This class implements log functions.
More...
#include <trantor/utils/Logger.h>
|
| enum | LogLevel {
kTrace = 0
, kDebug
, kInfo
, kWarn
,
kError
, kFatal
, kNumberOfLogLevels
} |
|
|
| Logger (SourceFile file, int line) |
|
| Logger (SourceFile file, int line, LogLevel level) |
|
| Logger (SourceFile file, int line, bool isSysErr) |
|
| Logger (SourceFile file, int line, LogLevel level, const char *func) |
|
| Logger (LogLevel level) |
|
| Logger (bool isSysErr) |
|
Logger & | setIndex (int index) |
|
LogStream & | stream () |
|
| static void | setOutputFunction (std::function< void(const char *msg, const uint64_t len)> outputFunc, std::function< void()> flushFunc, int index=-1) |
| | Set the output function.
|
| static void | setLogLevel (LogLevel level) |
| | Set the log level. Logs below the level are not printed.
|
| static LogLevel | logLevel () |
| | Get the current log level.
|
|
static bool | displayLocalTime () |
| | Check whether it shows local time or UTC time.
|
|
static void | setDisplayLocalTime (bool showLocalTime) |
| | Set whether it shows local time or UTC time. the default is UTC.
|
| static bool | hasSpdLogSupport () |
| | Check whether trantor was build with spdlog support.
|
| static void | enableSpdLog (int index, std::shared_ptr< spdlog::logger > logger={}) |
| | Enable logging with spdlog for the specified channel.
|
| static void | enableSpdLog (std::shared_ptr< spdlog::logger > logger={}) |
| | Enable logging with spdlog for the default channel.
|
| static void | disableSpdLog (int index) |
| | Disable logging with spdlog for the specified channel.
|
| static void | disableSpdLog () |
| | Disable logging with spdlog for the default channel.
|
| static std::shared_ptr< spdlog::logger > | getSpdLogger (int index=-1) |
| | Get the spdlog::logger set on the specified channel.
|
| static std::shared_ptr< spdlog::logger > | getDefaultSpdLogger (int index) |
| | Get a default spdlog::logger for the specified channel.
|
|
|
void | formatTime () |
|
| NonCopyable (const NonCopyable &)=delete |
|
NonCopyable & | operator= (const NonCopyable &)=delete |
|
| NonCopyable (NonCopyable &&) noexcept(true)=default |
|
NonCopyable & | operator= (NonCopyable &&) noexcept(true)=default |
|
|
static void | defaultOutputFunction (const char *msg, const uint64_t len) |
|
static void | defaultFlushFunction () |
|
static bool & | displayLocalTime_ () |
|
static LogLevel & | logLevel_ () |
|
static std::function< void(const char *msg, const uint64_t len)> & | outputFunc_ () |
|
static std::function< void()> & | flushFunc_ () |
|
static std::function< void(const char *msg, const uint64_t len)> & | outputFunc_ (size_t index) |
|
static std::function< void()> & | flushFunc_ (size_t index) |
|
|
LogStream | logStream_ |
|
Date | date_ {Date::now()} |
|
SourceFile | sourceFile_ |
|
int | fileLine_ |
|
LogLevel | level_ |
|
int | index_ {-1} |
|
const char * | func_ {nullptr} |
|
std::size_t | spdLogMessageOffset_ {0} |
This class implements log functions.
◆ disableSpdLog() [1/2]
| void trantor::Logger::disableSpdLog |
( |
| ) |
|
|
inlinestatic |
Disable logging with spdlog for the default channel.
◆ disableSpdLog() [2/2]
| void trantor::Logger::disableSpdLog |
( |
int | index | ) |
|
|
static |
Disable logging with spdlog for the specified channel.
- Parameters
-
| [in] | channel | index (-1 = default channel). |
◆ enableSpdLog() [1/2]
| void trantor::Logger::enableSpdLog |
( |
int | index, |
|
|
std::shared_ptr< spdlog::logger > | logger = {} ) |
|
static |
Enable logging with spdlog for the specified channel.
- Parameters
-
| index | channel index (-1 = default channel). |
| logger | spdlog::logger object to use. If none given, defaults to getDefaultSpdLogger(index). |
◆ enableSpdLog() [2/2]
| void trantor::Logger::enableSpdLog |
( |
std::shared_ptr< spdlog::logger > | logger = {} | ) |
|
|
inlinestatic |
Enable logging with spdlog for the default channel.
- Parameters
-
◆ getDefaultSpdLogger()
| std::shared_ptr< spdlog::logger > trantor::Logger::getDefaultSpdLogger |
( |
int | index | ) |
|
|
static |
Get a default spdlog::logger for the specified channel.
This helper function provides a default spdlog::logger with a similar output format as the existing non-spdlog trantor::Logger format.
If a default logger was already created for the channel, it is returned as-is.
Otherwise, a new spdlog::logger object named "trantor" (for index < 0) or "trantor<channel>" is created, registered with spdlog, and configured as follows:
- it has the same sinks as the lowest (index) enabled channel, or those of the spdlog::default_logger(), which by defaults outputs to stdout (spdlog::sinks::stdout_color_mt),
- its format pattern is set to resemble to the existing non-spdlog trantor::Logger format ("%Y%m%d %T.%f %6t %^%=8l%$ [%!] %v - %s:%#"),
- the logging level is set to unfiltered (spdlog::level::trace) since the internal trantor/drogon level filtering is still managed by trantor:::Logger,
- the flush level is set to spdlog::level::error.
- Note
- To add custom sinks to all the channels, you can do that this way:
(optional) add your sinks to spdlog::default_logger(),
- create the default logger for the default channel using getDefaultSpdLogger(-1),
- if not done at step 1., add your sinks to this logger,
- enable the logger with enableSpdLog(),
- for the other channels, invoke enableSpdLog(index).
- Parameters
-
| [in] | channel | index (-1 = default channel). |
- Returns
- the default spdlog logger for the channel.
◆ getSpdLogger()
| std::shared_ptr< spdlog::logger > trantor::Logger::getSpdLogger |
( |
int | index = -1 | ) |
|
|
static |
Get the spdlog::logger set on the specified channel.
- Parameters
-
| [in] | channel | index (-1 = default channel). |
- Returns
- the logger, if set, else a null pointer.
◆ hasSpdLogSupport()
| bool trantor::Logger::hasSpdLogSupport |
( |
| ) |
|
|
static |
Check whether trantor was build with spdlog support.
- Return values
-
| true | if yes |
| false | if not - in this case, all the spdlog functions are noop functions |
◆ logLevel()
| LogLevel trantor::Logger::logLevel |
( |
| ) |
|
|
inlinestatic |
Get the current log level.
- Returns
- LogLevel
◆ setLogLevel()
| void trantor::Logger::setLogLevel |
( |
LogLevel | level | ) |
|
|
inlinestatic |
Set the log level. Logs below the level are not printed.
- Parameters
-
◆ setOutputFunction()
| void trantor::Logger::setOutputFunction |
( |
std::function< void(const char *msg, const uint64_t len)> | outputFunc, |
|
|
std::function< void()> | flushFunc, |
|
|
int | index = -1 ) |
|
inlinestatic |
Set the output function.
- Parameters
-
| outputFunc | The function to output a log message. |
| flushFunc | The function to flush. |
| index | The channel index. |
- Note
- Logs are output to the standard output by default.
The documentation for this class was generated from the following file: