LogCabin
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Functions | Variables
LogCabin::Core::Debug::Internal Namespace Reference

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().

Function Documentation

const char* LogCabin::Core::Debug::Internal::logLevelToString ( LogLevel  level)

Convert a log level to a (static) string.

PANICs if the string is not a valid log level (case insensitive).

Definition at line 160 of file Debug.cc.

Convert a string to a log level.

PANICs if the string is not a valid log level (case insensitive).

Definition at line 180 of file Debug.cc.

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.

Parameters:
fileNameRelative filename.

Definition at line 204 of file Debug.cc.

Return the number of characters of __FILE__ that make up the path prefix.

That is, __FILE__ plus this value will be the relative path from the top directory of the code tree.

Definition at line 223 of file Debug.cc.

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.

Parameters:
fileNameAn absolute or relative filename, usually the value of __FILE__.
Returns:
A nicer way to show display 'fileName' to the user. For example, this file would yield "Core/Debug.cc".

Definition at line 244 of file Debug.cc.


Variable Documentation

Protects logPolicy, isLoggingCache, and logFilename.

Definition at line 113 of file Debug.cc.

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.

Definition at line 125 of file Debug.cc.

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.

Definition at line 135 of file Debug.cc.

Filename of currently open stream, if known.

Protected by mutex.

Definition at line 141 of file Debug.cc.

Where log messages go (unless logHandler is set).

Definition at line 146 of file Debug.cc.

If set, a callback that takes log messages instead of the normal log file (stream).

This is exposed to client applications so they can integrate with their own logging mechanism.

Definition at line 153 of file Debug.cc.

Stores result of calculateLengthFilePrefix().

Definition at line 232 of file Debug.cc.

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines