example update
This commit is contained in:
		@@ -28,6 +28,7 @@
 | 
				
			|||||||
#include <iostream>
 | 
					#include <iostream>
 | 
				
			||||||
#include "spdlog/spdlog.h"
 | 
					#include "spdlog/spdlog.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int main(int, char* [])
 | 
					int main(int, char* [])
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -35,29 +36,34 @@ int main(int, char* [])
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    try
 | 
					    try
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        std::string filename = "spdlog_example";
 | 
					        std::string filename = "logs/spdlog_example";
 | 
				
			||||||
        auto console = spd::stderr_logger_mt("console");
 | 
					        // Set log level to all loggers to DEBUG and above
 | 
				
			||||||
        console->info("Welcome to spdlog!") ;
 | 
					        spd::set_level(spd::level::DEBUG);
 | 
				
			||||||
        console->info() << "Creating file " << filename << "..";
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        //Create console, multithreaded logger
 | 
				
			||||||
 | 
					        auto console = spd::stdout_logger_mt("console");
 | 
				
			||||||
 | 
					        console->info("Welcome to spdlog!") ;
 | 
				
			||||||
 | 
					        console->info("Varriadic template call are supproted", "...", 1, 2, 3.5);
 | 
				
			||||||
 | 
					        console->info() << "streams are supported too  " << std::setw(5) << std::setfill('0') << 1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        //Create a file rotating logger with 5mb size max and 3 rotated files
 | 
				
			||||||
        auto file_logger = spd::rotating_logger_mt("file_logger", filename, 1024 * 1024 * 5, 3);
 | 
					        auto file_logger = spd::rotating_logger_mt("file_logger", filename, 1024 * 1024 * 5, 3);
 | 
				
			||||||
        file_logger->info("Log file message number", 1);
 | 
					        file_logger->info("Log file message number", 1);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        for (int i = 0; i < 100; ++i)
 | 
					        for (int i = 0; i < 100; ++i)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            auto square = i*i;
 | 
					            file_logger->info(i, "in hex is", "0x") << std::hex << std::uppercase << i;
 | 
				
			||||||
            file_logger->info() << i << '*' << i << '=' << square << " (" << "0x" << std::hex << square << ")";
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Change log level to all loggers to warning and above
 | 
					        spd::set_pattern("*** [%H:%M:%S %z] [thread %t] %v ***");
 | 
				
			||||||
        spd::set_level(spd::level::WARN);
 | 
					        file_logger->info("This is another message with custom format");
 | 
				
			||||||
        console->info("This should not be displayed");
 | 
					
 | 
				
			||||||
        console->warn("This should!");
 | 
					        spd::get("console")->info("loggers can be retrieved from a global registry using the spdlog::get(logger_name) function");
 | 
				
			||||||
        spd::set_level(spd::level::INFO);
 | 
					
 | 
				
			||||||
 | 
					        SPDLOG_TRACE(file_logger, "This is a trace message (only #ifdef _DEBUG)", 123);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Change format pattern to all loggers
 | 
					 | 
				
			||||||
        spd::set_pattern(" **** %Y-%m-%d %H:%M:%S.%e %l **** %v");
 | 
					 | 
				
			||||||
        spd::get("console")->info("This is another message with different format");
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    catch (const spd::spdlog_ex& ex)
 | 
					    catch (const spd::spdlog_ex& ex)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user