Commit b093b824 authored by gabime's avatar gabime

gcc support

parent 68504fa3
CC = g++
CCFLAGS = -std=c++11 -pthread -Iinclude -O3 -flto
all: lib testlog
testlog: test.o lib
$(CC) -o $testlog test.o libc11log.a $(CCFLAGS)
lib: factory.o formatters.o line_logger.o os.o
ar rvs libc11log.a $^;
test.o: src/test.cpp
$(CC) -c -o $@ $^ $(CCFLAGS)
factory.o: src/factory.cpp
$(CC) -c -o $@ $^ $(CCFLAGS)
formatters.o: src/formatters.cpp
$(CC) -c -o $@ $^ $(CCFLAGS)
line_logger.o: src/line_logger.cpp
$(CC) -c -o $@ $^ $(CCFLAGS)
os.o: src/os.cpp
$(CC) -c -o $@ $^ $(CCFLAGS)
.PHONY: clean
clean:
rm *.o
// stdafx.h : include file for standard system include files, // stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but // or project specific include files that are used frequently, but
// are changed infrequently // are changed infrequently
// //
#pragma once
#pragma once
#ifdef _MSC_VER
#include <thread> #include "targetver.h"
#include <iostream> #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#include <chrono> #endif
#include "utils.h" #include <string>
#include "../include/c11log/logger.h" #include <chrono>
#include "../include/c11log/sinks/async_sink.h" #include <ctime>
#include "../include/c11log/sinks/stdout_sinks.h" #include <memory>
#include "../include/c11log/sinks/file_sinks.h" #include <iostream>
#ifndef _MSC_VER
namespace std {
template<typename T, typename ...Args>
std::unique_ptr<T> make_unique( Args&& ...args )
{
return std::unique_ptr<T>( new T( std::forward<Args>(args)... ) );
}
}
#endif
...@@ -2,30 +2,38 @@ ...@@ -2,30 +2,38 @@
// //
#include "stdafx.h" #include "stdafx.h"
#include "c11log/logger.h"
#include "c11log/sinks/async_sink.h"
#include "c11log/sinks/file_sinks.h"
#include "c11log/sinks/stdout_sinks.h"
#include "utils.h"
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
int nthreads = argc > 1 ? atoi(argv[1]) : 1;
auto null_sink = std::make_shared<c11log::sinks::null_sink>(); auto null_sink = std::make_shared<c11log::sinks::null_sink>();
auto stdout_sink = std::make_shared<c11log::sinks::stdout_sink>();
auto async = std::make_shared<c11log::sinks::async_sink>(100); auto async = std::make_shared<c11log::sinks::async_sink>(100);
auto fsink = std::make_shared<c11log::sinks::rotating_file_sink>("newlog", "txt", 1024*1024*10 , 2); auto fsink = std::make_shared<c11log::sinks::rotating_file_sink>("newlog", "txt", 1024*1024*10 , 2);
async->add_sink(fsink); async->add_sink(null_sink);
c11log::logger logger("test"); c11log::logger logger("test");
logger.add_sink(async); logger.add_sink(async);
std::atomic<uint32_t> counter { 0 }; std::atomic<uint32_t> counter { 0 };
auto counter_ptr = &counter; auto counter_ptr = &counter;
for (int i = 0; i < 4; i++) std::cout << "Starting " << nthreads << " threads.." << std::endl;
for (int i = 0; i < nthreads; i++)
{ {
new std::thread([&logger, counter_ptr]() { new std::thread([&logger, counter_ptr]() {
while (true) while (true)
{ {
logger.info() << "Hello from thread" << std::this_thread::get_id(); logger.info() << "Hello from thread " << std::this_thread::get_id() << "\tcounter: " << counter_ptr->load();
(*counter_ptr)++; (*counter_ptr)++;
} }
......
// stdafx.cpp : source file that includes just the standard includes
// test.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information
#include "stdafx.h"
// TODO: reference any additional headers you need in STDAFX.H
// and not in this file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment