The Sleuth Kit Framework  4.1
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
Log Class Reference

Logging class to enable the framework, apps that use it, and modules to log error and warning messages. More...

#include <Log.h>

Public Types

enum  Channel { Error, Warn, Info }
 Defined logging levels. More...
 

Public Member Functions

int close ()
 Close the opened log file. More...
 
const char * getLogPath ()
 
const wchar_t * getLogPathW ()
 Return the path to the log file. More...
 
virtual void log (Channel a_channel, const std::wstring &a_msg)
 Generate a log message with a given level (wide string). More...
 
virtual void log (Channel a_channel, const std::string &a_msg)
 Generate a log message with a given level (narrow string). More...
 
void logError (const std::wstring &msg)
 Log an error message. More...
 
virtual void logf (Channel a_channel, char const *format,...)
 Generate a log message with a given level (printf-style arguments). More...
 
void logInfo (const std::wstring &msg)
 Log an info message. More...
 
void logWarn (const std::wstring &msg)
 Log a warning message. More...
 
int open (const wchar_t *a_logFileFullPath)
 Open the single log file at the path specified. More...
 
int open (const char *a_outDir)
 
int open ()
 Opens a single log file with a default name, based on the time that the log was opened. More...
 

Protected Member Functions

void logMessage (const std::string &level, const std::string &msg)
 

Protected Attributes

std::string m_filePath
 
unsigned int m_messageRepeatCount
 
std::ofstream m_outStream
 
std::string m_previousMessage
 

Static Protected Attributes

static const int REPEAT_THRESHOLD = 500
 

Detailed Description

Logging class to enable the framework, apps that use it, and modules to log error and warning messages.

The default implementation writes the log messages to a file if open() was called or prints the messages to stderr if open() was never called. The class can be extended if you want logs to be saved in another way. Can be registered with and retrieved from TskServices.

Developers can either directly call the log() method with the logging level, can call the logError(), etc. methods on the class or use the LOGERROR() etc. macros, which will also get the Log service from TskServices.

Member Enumeration Documentation

Defined logging levels.

Enumerator
Error 

Critical error that stops processing.

Warn 

Unexpected results that could be recovered from.

Info 

General debugging information.

Member Function Documentation

int Log::close ( )

Close the opened log file.

Returns
0 on success
const wchar_t * Log::getLogPathW ( )

Return the path to the log file.

Returns
path to log or NULL if log is going to STDERR

References TskUtilities::toUTF16().

void Log::log ( Channel  a_channel,
const std::wstring &  a_msg 
)
virtual

Generate a log message with a given level (wide string).

Parameters
a_channelLevel of log to make
a_msgMessage to record.

References TskUtilities::toUTF8().

Referenced by logf().

void Log::log ( Channel  a_channel,
const std::string &  a_msg 
)
virtual

Generate a log message with a given level (narrow string).

Parameters
a_channelLevel of log to make
a_msgMessage to record.

References Error, Info, and Warn.

void Log::logError ( const std::wstring &  msg)
inline

Log an error message.

Parameters
msgMessage to log

References Error.

Referenced by SectorRuns::addRun().

void Log::logf ( Channel  a_channel,
char const *  format,
  ... 
)
virtual

Generate a log message with a given level (printf-style arguments).

Parameters
a_channelLevel of log to make
formatMessage to record.

References log().

void Log::logInfo ( const std::wstring &  msg)
inline

Log an info message.

Parameters
msgMessage to log

References Info.

Referenced by TskServices::getLog().

void Log::logWarn ( const std::wstring &  msg)
inline

Log a warning message.

Parameters
msgMessage to log

References Warn.

int Log::open ( const wchar_t *  a_logFileFullPath)

Open the single log file at the path specified.

All messages will be printed to the log.

Parameters
a_logFileFullPathPath to logfile to open.
Returns
1 on error and 0 on success.

References open(), and TskUtilities::toUTF8().

int Log::open ( )

Opens a single log file with a default name, based on the time that the log was opened.

Returns
1 on error and 0 on success.

Referenced by open().


The documentation for this class was generated from the following files:

Copyright © 2011-2013 Brian Carrier. (carrier -at- sleuthkit -dot- org)
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.