-
Notifications
You must be signed in to change notification settings - Fork 0
Library Content Summary
All the code which is related to the SBLogger is located in the sblogger
namespace. The loggers are of 3 types:
-
sblogger::StreamLogger
(which writes to the standard streams) -
sblogger::FileLogger
(which writes to a file) - which also has a specialized derivate,-
sblogger::DailyLogger
(which writes to a file that changes daily at the specified time)
-
Each of the loggers mentioned above ensure thread-safety, sblogger::StreamLogger
making use of the std::ostream
mechanisms, while the other two having their own custom ones.
In addition to those two enums are defined, sblogger::StreamType
which is useful when logging with sblogger::StreamLogger
, in order to specify STDOUT, STDERR or STDLOG, and sblogger::LogLevel
, which is used to define the specific log levels that one can use. The library also contains its own custom errors, which help identify issues a user might run into.
Note: All those previously mentioned can also be written with lowercase letters (i.e.:
sblogger::stream_logger
,sblogger::stream_types
).
Note: All errors when thrown are thrown on the stack, not on the heap.
An abstract class which implements basic logger methods and members (ex.: auto flush, format, replace formatters etc.). More about those methods can be found in the Logging Messages section. All other loggers inherit it, making it useful if you wish to make use of polymorphism.
// Basic Logger
// Abstract class which implements basic logger methods and members (ex.: auto flush, format, replace formatters etc)
class Logger;
Derived from the sblogger::Logger
abstract class, provides functionality for writing logs to any of the standard streams, which can be selected using the sblogger::StreamTypes
enum (concretely, STDOUT, STDERR or STDLOG). The stream can be changed at run time, to any of the available ones.
// Stream Logger
// Used to log messages to a non-file stream (ex.: STDOUT, STDERR, STDLOG)
class StreamLogger;
Derived from the sblogger::Logger
abstract class, provides functionality for writing logs to a file stream, provided the file path in which it should write to. It can also clear any log file it writes to, during runtime.
// File Logger
// Used to log messages to a file stream
class FileLogger;
Derived from the sblogger::FileLogger
class, provides the same functionality for writing logs to a file stream, with the addition that once per day it changes said file to a new one, at a specified time point (by default 00:00:00 AM).
// Daily Logger
// Used to log messages to a file stream, recreated daily at a specified time point
class DailyLogger;
Is defined in order to specify all supported log levels that can be used. Its values are given as parameters when setting the log level at runtime.
// Log level enum. Contains all possible log levels, such as TRACE, ERROR, FATAL etc.
enum class LogLevel
{
TRACE /*= 0*/, DEBUG /*= 1*/, INFO /*= 2*/, WARN /*= 3*/, ERROR /*= 4*/, CRITICAL /*= 5*/, OFF /*= 6*/
};
Is defined in order to specify which of the standard streams can the sblogger::StreamLogger
use (concretely, STDOUT
, STDERR
and STDLOG
).
// Stream types to be used by a Logger instance
enum class StreamType
{
STDOUT /*= 0*/, STDERR /*= 1*/, STDLOG /*= 2*/
};
The default base error from SBLogger. Derived from the std::exception
class. Defined as an abstract class.
Methods:
-
const char* What()
- returns the message of the error
// Base exception
class SBLoggerException;
using sblogger_exception = SBLoggerException;
Derived from the SBLoggerException
class. Thrown when the given file path is null or empty.
// NullOrEmptyPathException
// Thrown when the given file path is null or empty
class NullOrEmptyPathException;
using null_or_empty_path_exception = NullOrEmptyPathException;
Derived from the SBLoggerException
class. Thrown when the given file name is null or whitespace.
// NullOrWhitespaceNameException
// Thrown when the given file name is null or whitespace
Derived from the ```SBLoggerException``` class.
class NullOrWhitespaceNameException;
using null_or_whitespace_name_exception = NullOrWhitespaceNameException;
Derived from the SBLoggerException
class. Thrown when the specified file could not be opened.
// InvalidFilePathException
// Thrown when the specified file could not be opened
class InvalidFilePathException;
using invalid_file_path_exception = InvalidFilePathException;
Derived from the SBLoggerException
class. Thrown when a time related value is out of bounds (e.g.: hours not in [0, 23]).
// TimeRangeException
// Thrown when a time related value is out of bounds (e.g.: hours not in [0, 23])
class TimeRangeException;
using time_range_exception = TimeRangeException;