LogCabin
|
Functions | |
const char * | logLevelToString (LogLevel level) |
Convert a log level to a (static) string. | |
LogLevel | logLevelFromString (const std::string &level) |
Convert a string to a log level. | |
LogLevel | getLogLevel (const char *fileName) |
From the policy, calculate the most verbose log level that should be displayed for this file. | |
size_t | calculateLengthFilePrefix () |
Return the number of characters of __FILE__ that make up the path prefix. | |
const char * | relativeFileName (const char *fileName) |
Strip out the common prefix of a filename to get a path from the project's root directory. | |
Variables | |
std::mutex | mutex |
Protects logPolicy, isLoggingCache, and logFilename. | |
std::vector< std::pair < std::string, std::string > > | logPolicy |
Specifies the log messages that should be displayed for each filename. | |
std::unordered_map< const char *, LogLevel > | isLoggingCache |
A cache of the results of getLogLevel(), since that function is slow. | |
std::string | logFilename |
Filename of currently open stream, if known. | |
FILE * | stream |
Where log messages go (unless logHandler is set). | |
std::function< void(DebugMessage)> | logHandler |
If set, a callback that takes log messages instead of the normal log file (stream). | |
const size_t | lengthFilePrefix |
Stores result of calculateLengthFilePrefix(). |
const char* LogCabin::Core::Debug::Internal::logLevelToString | ( | LogLevel | level | ) |
LogLevel LogCabin::Core::Debug::Internal::logLevelFromString | ( | const std::string & | level | ) |
LogLevel LogCabin::Core::Debug::Internal::getLogLevel | ( | const char * | fileName | ) |
From the policy, calculate the most verbose log level that should be displayed for this file.
This is slow, so isLogging() caches the results in isLoggingCache.
Must be called with mutex held.
fileName | Relative filename. |
const char* LogCabin::Core::Debug::Internal::relativeFileName | ( | const char * | fileName | ) |
Strip out the common prefix of a filename to get a path from the project's root directory.
fileName | An absolute or relative filename, usually the value of __FILE__. |
std::mutex LogCabin::Core::Debug::Internal::mutex |
Protects logPolicy, isLoggingCache, and logFilename.
std::vector<std::pair<std::string, std::string> > LogCabin::Core::Debug::Internal::logPolicy |
Specifies the log messages that should be displayed for each filename.
This first component is a pattern; the second is a log level. A filename is matched against each pattern in order: if the filename starts with or ends with the pattern, the corresponding log level defines the most verbose messages that are to be displayed for the file. If a filename matches no pattern, its log level will default to NOTICE.
Protected by mutex.
std::unordered_map<const char*, LogLevel> LogCabin::Core::Debug::Internal::isLoggingCache |
A cache of the results of getLogLevel(), since that function is slow.
This needs to be cleared when the logPolicy changes. The key to the map is a pointer to the absolute filename, which should be a string literal.
Protected by mutex.
std::string LogCabin::Core::Debug::Internal::logFilename |
std::function<void(DebugMessage)> LogCabin::Core::Debug::Internal::logHandler |
const size_t LogCabin::Core::Debug::Internal::lengthFilePrefix |
Stores result of calculateLengthFilePrefix().