mirror of
https://github.com/gabime/spdlog.git
synced 2024-12-24 09:31:34 +08:00
gcc support
This commit is contained in:
parent
68504fa3e5
commit
b093b82473
30
Makefile
Normal file
30
Makefile
Normal file
@ -0,0 +1,30 @@
|
||||
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
|
27
include/stdafx.h
Normal file
27
include/stdafx.h
Normal file
@ -0,0 +1,27 @@
|
||||
// stdafx.h : include file for standard system include files,
|
||||
// or project specific include files that are used frequently, but
|
||||
// are changed infrequently
|
||||
//
|
||||
#pragma once
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#include "targetver.h"
|
||||
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
|
||||
#endif
|
||||
|
||||
#include <string>
|
||||
#include <chrono>
|
||||
#include <ctime>
|
||||
#include <memory>
|
||||
#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 @@
|
||||
//
|
||||
|
||||
#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 nthreads = argc > 1 ? atoi(argv[1]) : 1;
|
||||
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 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");
|
||||
logger.add_sink(async);
|
||||
|
||||
|
||||
std::atomic<uint32_t> counter { 0 };
|
||||
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]() {
|
||||
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)++;
|
||||
}
|
||||
|
@ -1,8 +0,0 @@
|
||||
// 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
|
@ -1,16 +0,0 @@
|
||||
// stdafx.h : include file for standard system include files,
|
||||
// or project specific include files that are used frequently, but
|
||||
// are changed infrequently
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <thread>
|
||||
#include <iostream>
|
||||
#include <chrono>
|
||||
|
||||
#include "utils.h"
|
||||
#include "../include/c11log/logger.h"
|
||||
#include "../include/c11log/sinks/async_sink.h"
|
||||
#include "../include/c11log/sinks/stdout_sinks.h"
|
||||
#include "../include/c11log/sinks/file_sinks.h"
|
Loading…
Reference in New Issue
Block a user