Format
This commit is contained in:
		@@ -7,10 +7,10 @@
 | 
				
			|||||||
// bench.cpp : spdlog benchmarks
 | 
					// bench.cpp : spdlog benchmarks
 | 
				
			||||||
//
 | 
					//
 | 
				
			||||||
#include "spdlog/async.h"
 | 
					#include "spdlog/async.h"
 | 
				
			||||||
#include "spdlog/sinks/simple_file_sink.h"
 | 
					 | 
				
			||||||
#include "spdlog/sinks/daily_file_sink.h"
 | 
					#include "spdlog/sinks/daily_file_sink.h"
 | 
				
			||||||
#include "spdlog/sinks/rotating_file_sink.h"
 | 
					 | 
				
			||||||
#include "spdlog/sinks/null_sink.h"
 | 
					#include "spdlog/sinks/null_sink.h"
 | 
				
			||||||
 | 
					#include "spdlog/sinks/rotating_file_sink.h"
 | 
				
			||||||
 | 
					#include "spdlog/sinks/simple_file_sink.h"
 | 
				
			||||||
#include "spdlog/spdlog.h"
 | 
					#include "spdlog/spdlog.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "utils.h"
 | 
					#include "utils.h"
 | 
				
			||||||
@@ -48,7 +48,7 @@ int main(int argc, char *argv[])
 | 
				
			|||||||
            threads = atoi(argv[2]);
 | 
					            threads = atoi(argv[2]);
 | 
				
			||||||
        if (argc > 3)
 | 
					        if (argc > 3)
 | 
				
			||||||
            queue_size = atoi(argv[3]);
 | 
					            queue_size = atoi(argv[3]);
 | 
				
			||||||
	
 | 
					
 | 
				
			||||||
        cout << "*******************************************************************************\n";
 | 
					        cout << "*******************************************************************************\n";
 | 
				
			||||||
        cout << "Single thread, " << format(howmany) << " iterations" << endl;
 | 
					        cout << "Single thread, " << format(howmany) << " iterations" << endl;
 | 
				
			||||||
        cout << "*******************************************************************************\n";
 | 
					        cout << "*******************************************************************************\n";
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -10,9 +10,9 @@
 | 
				
			|||||||
#define SPDLOG_TRACE_ON
 | 
					#define SPDLOG_TRACE_ON
 | 
				
			||||||
#define SPDLOG_DEBUG_ON
 | 
					#define SPDLOG_DEBUG_ON
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "spdlog/sinks/simple_file_sink.h"
 | 
					 | 
				
			||||||
#include "spdlog/sinks/daily_file_sink.h"
 | 
					#include "spdlog/sinks/daily_file_sink.h"
 | 
				
			||||||
#include "spdlog/sinks/rotating_file_sink.h"
 | 
					#include "spdlog/sinks/rotating_file_sink.h"
 | 
				
			||||||
 | 
					#include "spdlog/sinks/simple_file_sink.h"
 | 
				
			||||||
#include "spdlog/sinks/stdout_color_sinks.h"
 | 
					#include "spdlog/sinks/stdout_color_sinks.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <iostream>
 | 
					#include <iostream>
 | 
				
			||||||
@@ -61,13 +61,13 @@ int main(int, char *[])
 | 
				
			|||||||
        daily_logger->info(123.44);
 | 
					        daily_logger->info(123.44);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Customize msg format for all messages
 | 
					        // Customize msg format for all messages
 | 
				
			||||||
        spd::set_pattern("[%^+++%$] [%H:%M:%S %z] [thread %t] %v"); 
 | 
					        spd::set_pattern("[%^+++%$] [%H:%M:%S %z] [thread %t] %v");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        console->info("This an info message with custom format");
 | 
					        console->info("This an info message with custom format");
 | 
				
			||||||
        console->error("This an error message with custom format");
 | 
					        console->error("This an error message with custom format");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// Change format back to to default
 | 
					        // Change format back to to default
 | 
				
			||||||
		spd::set_pattern ("%+");
 | 
					        spd::set_pattern("%+");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Runtime log levels
 | 
					        // Runtime log levels
 | 
				
			||||||
        spd::set_level(spd::level::info); // Set global log level to info
 | 
					        spd::set_level(spd::level::info); // Set global log level to info
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,6 +1,6 @@
 | 
				
			|||||||
#include "spdlog/spdlog.h"
 | 
					 | 
				
			||||||
#include "spdlog/sinks/file_sinks.h"
 | 
					#include "spdlog/sinks/file_sinks.h"
 | 
				
			||||||
#include "spdlog/sinks/stdout_sinks.h"
 | 
					#include "spdlog/sinks/stdout_sinks.h"
 | 
				
			||||||
 | 
					#include "spdlog/spdlog.h"
 | 
				
			||||||
#include <iostream>
 | 
					#include <iostream>
 | 
				
			||||||
#include <memory>
 | 
					#include <memory>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -11,7 +11,7 @@
 | 
				
			|||||||
// All loggers created here share same global thread pool.
 | 
					// All loggers created here share same global thread pool.
 | 
				
			||||||
// Each log message is pushed to a queue along withe a shared pointer to the logger.
 | 
					// Each log message is pushed to a queue along withe a shared pointer to the logger.
 | 
				
			||||||
// If a logger deleted while having pending messages in the queue, it's actual destruction will defer
 | 
					// If a logger deleted while having pending messages in the queue, it's actual destruction will defer
 | 
				
			||||||
// until all its messages are processed by the thread pool. 
 | 
					// until all its messages are processed by the thread pool.
 | 
				
			||||||
// This is because each message in the queue holds a shared_ptr to the originating logger.
 | 
					// This is because each message in the queue holds a shared_ptr to the originating logger.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "spdlog/async_logger.h"
 | 
					#include "spdlog/async_logger.h"
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -72,7 +72,7 @@ inline void spdlog::logger::log(level::level_enum lvl, const char *fmt, const Ar
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
    catch (...)
 | 
					    catch (...)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        _err_handler("Unknown exception in logger " + _name);        
 | 
					        _err_handler("Unknown exception in logger " + _name);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -95,7 +95,7 @@ inline void spdlog::logger::log(level::level_enum lvl, const char *msg)
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
    catch (...)
 | 
					    catch (...)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        _err_handler("Unknown exception in logger " + _name);        
 | 
					        _err_handler("Unknown exception in logger " + _name);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -118,7 +118,7 @@ inline void spdlog::logger::log(level::level_enum lvl, const T &msg)
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
    catch (...)
 | 
					    catch (...)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        _err_handler("Unknown exception in logger " + _name);        
 | 
					        _err_handler("Unknown exception in logger " + _name);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -151,8 +151,6 @@ public:
 | 
				
			|||||||
        return _msg_counter.load(std::memory_order_relaxed);
 | 
					        return _msg_counter.load(std::memory_order_relaxed);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
private:
 | 
					private:
 | 
				
			||||||
    std::atomic<size_t> _msg_counter; // total # of messages processed in this pool
 | 
					    std::atomic<size_t> _msg_counter; // total # of messages processed in this pool
 | 
				
			||||||
    q_type _q;
 | 
					    q_type _q;
 | 
				
			||||||
@@ -222,12 +220,12 @@ private:
 | 
				
			|||||||
        using std::chrono::milliseconds;
 | 
					        using std::chrono::milliseconds;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        auto time_since_op = now - last_op_time;
 | 
					        auto time_since_op = now - last_op_time;
 | 
				
			||||||
               
 | 
					
 | 
				
			||||||
        // yield upto 150 micros
 | 
					        // yield upto 150 micros
 | 
				
			||||||
        if (time_since_op <= microseconds(150))
 | 
					        if (time_since_op <= microseconds(150))
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            return std::this_thread::yield();
 | 
					            return std::this_thread::yield();
 | 
				
			||||||
        }		
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // sleep for 20 ms upto 200 ms
 | 
					        // sleep for 20 ms upto 200 ms
 | 
				
			||||||
        if (time_since_op <= milliseconds(200))
 | 
					        if (time_since_op <= milliseconds(200))
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -4,11 +4,11 @@
 | 
				
			|||||||
//
 | 
					//
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#pragma once
 | 
					#pragma once
 | 
				
			||||||
#include "spdlog/spdlog.h"
 | 
					 | 
				
			||||||
#include "spdlog/details/file_helper.h"
 | 
					#include "spdlog/details/file_helper.h"
 | 
				
			||||||
#include "spdlog/details/null_mutex.h"
 | 
					#include "spdlog/details/null_mutex.h"
 | 
				
			||||||
#include "spdlog/fmt/fmt.h"
 | 
					#include "spdlog/fmt/fmt.h"
 | 
				
			||||||
#include "spdlog/sinks/base_sink.h"
 | 
					#include "spdlog/sinks/base_sink.h"
 | 
				
			||||||
 | 
					#include "spdlog/spdlog.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <algorithm>
 | 
					#include <algorithm>
 | 
				
			||||||
#include <cerrno>
 | 
					#include <cerrno>
 | 
				
			||||||
@@ -123,7 +123,7 @@ using daily_file_sink_st = daily_file_sink<details::null_mutex>;
 | 
				
			|||||||
} // namespace sinks
 | 
					} // namespace sinks
 | 
				
			||||||
 | 
					
 | 
				
			||||||
//
 | 
					//
 | 
				
			||||||
// factory functions 
 | 
					// factory functions
 | 
				
			||||||
//
 | 
					//
 | 
				
			||||||
template<typename Factory = default_factory>
 | 
					template<typename Factory = default_factory>
 | 
				
			||||||
inline std::shared_ptr<logger> daily_logger_mt(const std::string &logger_name, const filename_t &filename, int hour = 0, int minute = 0)
 | 
					inline std::shared_ptr<logger> daily_logger_mt(const std::string &logger_name, const filename_t &filename, int hour = 0, int minute = 0)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -4,18 +4,18 @@
 | 
				
			|||||||
//
 | 
					//
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#pragma once
 | 
					#pragma once
 | 
				
			||||||
#include "spdlog/spdlog.h"
 | 
					 | 
				
			||||||
#include "spdlog/details/file_helper.h"
 | 
					#include "spdlog/details/file_helper.h"
 | 
				
			||||||
#include "spdlog/details/null_mutex.h"
 | 
					#include "spdlog/details/null_mutex.h"
 | 
				
			||||||
#include "spdlog/fmt/fmt.h"
 | 
					#include "spdlog/fmt/fmt.h"
 | 
				
			||||||
#include "spdlog/sinks/base_sink.h"
 | 
					#include "spdlog/sinks/base_sink.h"
 | 
				
			||||||
 | 
					#include "spdlog/spdlog.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <cerrno>
 | 
					#include <cerrno>
 | 
				
			||||||
#include <chrono>
 | 
					#include <chrono>
 | 
				
			||||||
#include <tuple>
 | 
					 | 
				
			||||||
#include <ctime>
 | 
					#include <ctime>
 | 
				
			||||||
#include <mutex>
 | 
					#include <mutex>
 | 
				
			||||||
#include <string>
 | 
					#include <string>
 | 
				
			||||||
 | 
					#include <tuple>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace spdlog {
 | 
					namespace spdlog {
 | 
				
			||||||
namespace sinks {
 | 
					namespace sinks {
 | 
				
			||||||
@@ -117,7 +117,6 @@ using rotating_file_sink_st = rotating_file_sink<details::null_mutex>;
 | 
				
			|||||||
// factory functions
 | 
					// factory functions
 | 
				
			||||||
//
 | 
					//
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
template<typename Factory = default_factory>
 | 
					template<typename Factory = default_factory>
 | 
				
			||||||
inline std::shared_ptr<logger> rotating_logger_mt(
 | 
					inline std::shared_ptr<logger> rotating_logger_mt(
 | 
				
			||||||
    const std::string &logger_name, const filename_t &filename, size_t max_file_size, size_t max_files)
 | 
					    const std::string &logger_name, const filename_t &filename, size_t max_file_size, size_t max_files)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -4,10 +4,10 @@
 | 
				
			|||||||
//
 | 
					//
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#pragma once
 | 
					#pragma once
 | 
				
			||||||
#include "spdlog/spdlog.h"
 | 
					 | 
				
			||||||
#include "spdlog/details/file_helper.h"
 | 
					#include "spdlog/details/file_helper.h"
 | 
				
			||||||
#include "spdlog/details/null_mutex.h"
 | 
					#include "spdlog/details/null_mutex.h"
 | 
				
			||||||
#include "spdlog/sinks/base_sink.h"
 | 
					#include "spdlog/sinks/base_sink.h"
 | 
				
			||||||
 | 
					#include "spdlog/spdlog.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <mutex>
 | 
					#include <mutex>
 | 
				
			||||||
#include <string>
 | 
					#include <string>
 | 
				
			||||||
@@ -55,7 +55,6 @@ private:
 | 
				
			|||||||
using simple_file_sink_mt = simple_file_sink<std::mutex>;
 | 
					using simple_file_sink_mt = simple_file_sink<std::mutex>;
 | 
				
			||||||
using simple_file_sink_st = simple_file_sink<details::null_mutex>;
 | 
					using simple_file_sink_st = simple_file_sink<details::null_mutex>;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
} // namespace sinks
 | 
					} // namespace sinks
 | 
				
			||||||
 | 
					
 | 
				
			||||||
//
 | 
					//
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -49,6 +49,6 @@ inline std::shared_ptr<logger> stderr_color_mt(const std::string &logger_name)
 | 
				
			|||||||
template<typename Factory = default_factory>
 | 
					template<typename Factory = default_factory>
 | 
				
			||||||
inline std::shared_ptr<logger> stderr_color_st(const std::string &logger_name)
 | 
					inline std::shared_ptr<logger> stderr_color_st(const std::string &logger_name)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    return Factory::template create<stderr_color_sink_mt > (logger_name);
 | 
					    return Factory::template create<stderr_color_sink_mt>(logger_name);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
} // namespace spdlog
 | 
					} // namespace spdlog
 | 
				
			||||||
@@ -12,12 +12,11 @@
 | 
				
			|||||||
#define SPDLOG_TRACE_ON
 | 
					#define SPDLOG_TRACE_ON
 | 
				
			||||||
#define SPDLOG_DEBUG_ON
 | 
					#define SPDLOG_DEBUG_ON
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
#include "spdlog/async.h"
 | 
					#include "spdlog/async.h"
 | 
				
			||||||
#include "spdlog/sinks/simple_file_sink.h"
 | 
					 | 
				
			||||||
#include "spdlog/sinks/stdout_color_sinks.h"
 | 
					 | 
				
			||||||
#include "spdlog/sinks/daily_file_sink.h"
 | 
					#include "spdlog/sinks/daily_file_sink.h"
 | 
				
			||||||
#include "spdlog/sinks/rotating_file_sink.h"
 | 
					 | 
				
			||||||
#include "spdlog/sinks/null_sink.h"
 | 
					#include "spdlog/sinks/null_sink.h"
 | 
				
			||||||
#include "spdlog/sinks/ostream_sink.h"
 | 
					#include "spdlog/sinks/ostream_sink.h"
 | 
				
			||||||
 | 
					#include "spdlog/sinks/rotating_file_sink.h"
 | 
				
			||||||
 | 
					#include "spdlog/sinks/simple_file_sink.h"
 | 
				
			||||||
 | 
					#include "spdlog/sinks/stdout_color_sinks.h"
 | 
				
			||||||
#include "spdlog/spdlog.h"
 | 
					#include "spdlog/spdlog.h"
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user