Commit b60aa784 authored by Andreas Tille's avatar Andreas Tille
Browse files

New upstream version 0.14.0

parent e67cb72a
Loading
Loading
Loading
Loading
+10 −3
Original line number Diff line number Diff line
@@ -5,14 +5,19 @@

cmake_minimum_required(VERSION 3.1)
project(spdlog VERSION 1.0.0)
include(CTest)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
    set(CMAKE_CXX_FLAGS "-Wall ${CMAKE_CXX_FLAGS}")
endif()

add_library(spdlog INTERFACE)

option(SPDLOG_BUILD_EXAMPLES "Build examples" OFF)
option(SPDLOG_BUILD_TESTS "Build tests" OFF)
option(SPDLOG_BUILD_TESTING "Build spdlog tests" ON)

target_include_directories(
    spdlog
@@ -23,12 +28,11 @@ target_include_directories(

set(HEADER_BASE "${CMAKE_CURRENT_SOURCE_DIR}/include")

include(CTest)
if(SPDLOG_BUILD_EXAMPLES)
    add_subdirectory(example)
endif()

if(SPDLOG_BUILD_TESTS)
if(SPDLOG_BUILD_TESTING)
    add_subdirectory(tests)
endif()

@@ -78,3 +82,6 @@ install(
    NAMESPACE "${namespace}"
    DESTINATION "${config_install_dir}"
)

file(GLOB_RECURSE spdlog_include_SRCS "${HEADER_BASE}/*.h")
add_custom_target(spdlog_headers_for_ide SOURCES ${spdlog_include_SRCS})
+55 −31
Original line number Diff line number Diff line
@@ -4,13 +4,25 @@ Very fast, header only, C++ logging library. [![Build Status](https://travis-ci.


## Install
Just copy the source [folder](https://github.com/gabime/spdlog/tree/master/include/spdlog) to your build tree and use a C++11 compiler
#### Just copy the headers:

* Copy the source [folder](https://github.com/gabime/spdlog/tree/master/include/spdlog) to your build tree and use a C++11 compiler.

#### Or use your favourite package manager:

* Ubuntu: `apt-get install libspdlog-dev`
* Homebrew: `brew install spdlog`
* FreeBSD:  `cd /usr/ports/devel/spdlog/ && make install clean`
* Fedora: `yum install spdlog`
* Gentoo: `emerge dev-libs/spdlog`
* Arch Linux: `pacman -S spdlog-git`
* vcpkg: `vcpkg install spdlog`
 

## Platforms
 * Linux (gcc 4.8.1+, clang 3.5+)
 * Windows (visual studio 2013+, cygwin/mingw with g++ 4.9.1+)
 * Linux, FreeBSD, Solaris
 * Windows (vc 2013+, cygwin/mingw)
 * Mac OSX (clang 3.5+)
 * Solaris (gcc 5.2.0+)
 * Android

## Features
@@ -19,12 +31,14 @@ Just copy the source [folder](https://github.com/gabime/spdlog/tree/master/inclu
* Feature rich [call style](#usage-example) using the excellent [fmt](https://github.com/fmtlib/fmt) library.
* Extremely fast asynchronous mode (optional) - using lockfree queues and other tricks to reach millions of calls/sec.
* [Custom](https://github.com/gabime/spdlog/wiki/3.-Custom-formatting) formatting.
* Conditional Logging
* Multi/Single threaded loggers.
* Various log targets:
    * Rotating log files.
    * Daily log files.
    * Console logging (colors supported).
    * syslog.
    * Windows debugger (```OutputDebugString(..)```)
    * Easily extendable with custom log targets  (just implement a single function in the [sink](include/spdlog/sinks/sink.h) interface).
* Severity based filtering - threshold levels can be modified in runtime as well as in compile time.

@@ -74,34 +88,29 @@ int main(int, char*[])
{
    try
    {
        // Multithreaded color console
        auto console = spd::stdout_logger_mt("console", true);
        // Console logger with color
        auto console = spd::stdout_color_mt("console");
        console->info("Welcome to spdlog!");
        console->info("An info message example {}..", 1);
        console->error("Some error message with arg{}..", 1);

	// Conditional logging example
        auto i = 2;
        console->warn_if(i != 0, "an important message");

        // Formatting examples
        console->warn("Easy padding in numbers like {:08d}", 12);
        console->critical("Support for int: {0:d};  hex: {0:x};  oct: {0:o}; bin: {0:b}", 42);
        console->info("Support for floats {:03.2f}", 1.23456);
        console->info("Positional args are {1} {0}..", "too", "supported");

        console->info("{:<30}", "left aligned");
        console->info("{:>30}", "right aligned");
        console->info("{:^30}", "centered");
        
        spd::get("console")->info("loggers can be retrieved from a global registry using the spdlog::get(logger_name) function");

        // Runtime log levels
        spd::set_level(spd::level::info); //Set global log level to info
        console->debug("This message shold not be displayed!");
        console->set_level(spd::level::debug); // Set specific logger's log level
        console->debug("This message shold be displayed..");
        spd::get("console")->info("loggers can be retrieved from a global registry using the spdlog::get(logger_name) function");
        
        // Create basic file logger (not rotated)
        auto my_logger = spd::basic_logger_mt("basic_logger", "logs/basic.txt");
        my_logger->info("Some log message");


        // Create a file rotating logger with 5mb size max and 3 rotated files
        auto rotating_logger = spd::rotating_logger_mt("some_logger_name", "logs/mylogfile", 1048576 * 5, 3);
        for (int i = 0; i < 10; ++i)
@@ -109,14 +118,23 @@ int main(int, char*[])

        // Create a daily logger - a new file is created every day on 2:30am
        auto daily_logger = spd::daily_logger_mt("daily_logger", "logs/daily", 2, 30);
        // trigger flush if the log severity is error or higher
        daily_logger->flush_on(spd::level::err);
        daily_logger->info(123.44);

        // Customize msg format for all messages
        spd::set_pattern("*** [%H:%M:%S %z] [thread %t] %v ***");
        rotating_logger->info("This is another message with custom format");

        // Compile time debug or trace macros.
        // Enabled #ifdef SPDLOG_DEBUG_ON or #ifdef SPDLOG_TRACE_ON

        // Runtime log levels
	spd::set_level(spd::level::info); //Set global log level to info
	console->debug("This message shold not be displayed!");
	console->set_level(spd::level::debug); // Set specific logger's log level
	console->debug("This message shold be displayed..");

        // Compile time log levels
        // define SPDLOG_DEBUG_ON or SPDLOG_TRACE_ON
        SPDLOG_TRACE(console, "Enabled only #ifdef SPDLOG_TRACE_ON..{} ,{}", 1, 3.23);
        SPDLOG_DEBUG(console, "Enabled only #ifdef SPDLOG_DEBUG_ON.. {} ,{}", 1, 3.23);

@@ -124,20 +142,26 @@ int main(int, char*[])
        // Just call spdlog::set_async_mode(q_size) and all created loggers from now on will be asynchronous..
        async_example();

        // syslog example. linux/osx only..
        // syslog example. linux/osx only
        syslog_example();

        // Log user-defined types example..
        // android example. compile with NDK
        android_example();

        // Log user-defined types example
        user_defined_example();

        // Change default log error handler
        err_handler_example();

        // Apply a function on all registered loggers
        spd::apply_all([&](std::shared_ptr<spdlog::logger> l) {l->info("End of example."); });
        spd::apply_all([&](std::shared_ptr<spd::logger> l)
        {
            l->info("End of example.");
        });

        // Release and close all loggers
        spdlog::drop_all();
        spd::drop_all();
    }
    // Exceptions will only be thrown upon failed logger or sink construction (not during logging)
    catch (const spd::spdlog_ex& ex)
@@ -150,7 +174,7 @@ int main(int, char*[])
void async_example()
{
    size_t q_size = 4096; //queue size must be power of 2
    spdlog::set_async_mode(q_size);
    spd::set_async_mode(q_size);
    auto async_file = spd::daily_logger_st("async_file_logger", "logs/async_log.txt");
    for (int i = 0; i < 100; ++i)
        async_file->info("Async message #{}", i);
@@ -188,7 +212,7 @@ void user_defined_example()
//
void err_handler_example()
{	
	spdlog::set_error_handler([](const std::string& msg) {
	spd::set_error_handler([](const std::string& msg) {
		std::cerr << "my err handler: " << msg << std::endl;
	}); 
	// (or logger->set_error_handler(..) to set for specific logger)
+0 −1
Original line number Diff line number Diff line
@@ -2,7 +2,6 @@
// Copyright(c) 2015 Gabi Melman.
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
//

#include <boost/log/core.hpp>
#include <boost/log/trivial.hpp>
#include <boost/log/expressions.hpp>

bench/latency/Makefile

0 → 100644
+32 −0
Original line number Diff line number Diff line
CXX	?= g++
CXXFLAGS	= -march=native -Wall -std=c++11 -pthread 
CXX_RELEASE_FLAGS = -O2 -DNDEBUG


binaries=spdlog-latency g3log-latency g3log-crush

all: $(binaries)

spdlog-latency: spdlog-latency.cpp
	$(CXX) spdlog-latency.cpp -o spdlog-latency $(CXXFLAGS) $(CXX_RELEASE_FLAGS) -I../../include



g3log-latency: g3log-latency.cpp
	$(CXX) g3log-latency.cpp -o g3log-latency $(CXXFLAGS) $(CXX_RELEASE_FLAGS) -I../../../g3log/src -L. -lg3logger 
		
		
g3log-crush: g3log-crush.cpp
	$(CXX) g3log-crush.cpp -o g3log-crush $(CXXFLAGS) $(CXX_RELEASE_FLAGS) -I../../../g3log/src -L. -lg3logger 
		
	
.PHONY: clean

clean:
	rm -f *.o  *.log $(binaries)


rebuild: clean all


+13 −0
Original line number Diff line number Diff line
#!/bin/bash
echo "running spdlog and g3log tests 10 time with ${1:-10} threads each (total 1,000,000 entries).."
rm -f *.log
for i in {1..10}

do
   echo
   sleep 0.5
   ./spdlog-latency ${1:-10} 2>/dev/null || exit
   sleep 0.5
   ./g3log-latency ${1:-10} 2>/dev/null || exit

done
Loading