atscppapi
1.0.9
C++ wrapper for Apache Traffic Server API
|
Create log files that are automatically rolled and cleaned up as space is required. More...
#include "Logger.h"
Inherits atscppapi::noncopyable.
Public Types | |
enum | LogLevel { LOG_LEVEL_NO_LOG = 128, LOG_LEVEL_DEBUG = 1, LOG_LEVEL_INFO = 2, LOG_LEVEL_ERROR = 4 } |
Public Member Functions | |
bool | init (const std::string &file, bool add_timestamp=true, bool rename_file=true, LogLevel level=LOG_LEVEL_INFO, bool rolling_enabled=true, int rolling_interval_seconds=3600) |
void | setRollingIntervalSeconds (int seconds) |
int | getRollingIntervalSeconds () const |
void | setRollingEnabled (bool enabled) |
bool | isRollingEnabled () const |
void | setLogLevel (Logger::LogLevel level) |
Logger::LogLevel | getLogLevel () const |
void | flush () |
void | logDebug (const char *fmt,...) ATSCPPAPI_PRINTFLIKE(2 |
void void | logInfo (const char *fmt,...) ATSCPPAPI_PRINTFLIKE(2 |
void void void | logError (const char *fmt,...) ATSCPPAPI_PRINTFLIKE(2 |
Create log files that are automatically rolled and cleaned up as space is required.
Log files created using the Logger class will be placed in the same directory as other log files, that directory is specified in records.config. All of the logging configuration such as max space available for all logs includes any logs created using the Logger class.
Loggers are very easy to use and a full example is available in examples/logger_example/, a simple example is:
The available log levels
void Logger::flush | ( | ) |
This method allows you to flush any log lines that might have been buffered.
Logger::LogLevel Logger::getLogLevel | ( | ) | const |
int Logger::getRollingIntervalSeconds | ( | ) | const |
bool Logger::init | ( | const std::string & | file, |
bool | add_timestamp = true , |
||
bool | rename_file = true , |
||
LogLevel | level = LOG_LEVEL_INFO , |
||
bool | rolling_enabled = true , |
||
int | rolling_interval_seconds = 3600 |
||
) |
You must always init() a Logger before you begin logging. If you do not call init() nothing will happen.
file | The name of the file to create in the logging directory, if you do not specify an extension .log will be used. |
add_timestamp | Prepend a timestamp to the log lines, the default value is true. |
rename_file | If a file already exists by the same name it will attempt to rename using a scheme that appends .1, .2, and so on, the default value for this argument is true. |
level | the default log level to use when creating the logger, this is set to LOG_LEVEL_INFO by default. |
rolling_enabled | if set to true this will enable log rolling on a periodic basis, this is enabled by default. |
rolling_interval_seconds | how frequently to roll the longs in seconds, this is set to 3600 by default (one hour). |
bool Logger::isRollingEnabled | ( | ) | const |
void Logger::logDebug | ( | const char * | fmt, |
... | |||
) |
This method writes a DEBUG level message to the log file, the LOG_DEBUG macro in Logger.h should be used in favor of these when possible because it will produce a much more rich debug message.
Sample usage:
void Logger::logError | ( | const char * | fmt, |
... | |||
) |
This method writes an ERROR level message to the log file, the LOG_ERROR macro in Logger.h should be used in favor of these when possible because it will produce a much more rich error message.
void Logger::logInfo | ( | const char * | fmt, |
... | |||
) |
This method writes an INFO level message to the log file, the LOG_INFO macro in Logger.h should be used in favor of these when possible because it will produce a much more rich info message.
void Logger::setLogLevel | ( | Logger::LogLevel | level | ) |
void Logger::setRollingEnabled | ( | bool | enabled | ) |
Enables or disables log rolling
enabled | true to enable log rolling, false to disable it. |
void Logger::setRollingIntervalSeconds | ( | int | seconds | ) |
Allows you to change the rolling interval in seconds
seconds | the number of seconds between rolls |