The logging class. More...
#include <cbicaLogging.h>
Public Member Functions | |
void | EnableConsoleLogging () |
Switches from text to console file logging. More... | |
void | EnableGMTLogging () |
This enables logging the date and time in GMT rather than in local (which is the default behavior) | |
void | EnableMultiUserLogging () |
This is useful in scenarios where the application has been installed in a multi-user machine. More... | |
void | EnableTextLogging (const std::string &newLogFile) |
Switches from console to text file logging. More... | |
std::string | getLoggingFileName () |
Get the file name with full path where log has happened. More... | |
Logging (const std::string file_name, const std::string FreeText_input) | |
Actual Constructor. More... | |
Logging () | |
Default constructor. More... | |
Logging (const Logging &origin) | |
Default constructor. More... | |
void | UseNewFile (const std::string &newLogFile) |
Change Logging file after initializing class. More... | |
void | Write (const std::string FreeText_input) |
Function to call to write to log file. More... | |
void | WriteError (const std::string FreeText_input) |
Function to call to write error messages to log file without any free text. More... | |
virtual | ~Logging () |
The Destructor. | |
Protected Member Functions | |
void | initialize_class (std::string &file_name_with_path_wrap, std::ofstream &log_file_wrap, std::string &exe_name_wrap, std::string &user_name_wrap) |
The function used to initialize the class. More... | |
void | writing_function (const std::string &FreeText_wrap, std::ofstream &log_file_wrap, const std::string &exe_name_wrap, const std::string &user_name_wrap, bool isError=false) |
The function used to do the actual writing onto the file. More... | |
The logging class.
This automatically generates a machine-parseable log specified by the file name. The user also has the option of submitting free text to be put along with the log. The generated log is in the format show below:
<4 digit year>:<2 digit month>:<2 digit date>,<2 digit 24 hour>:<2 digit minute>:<2 digit second>;<exe name>="">;<user name>="">;<free text>="">
Usage:
// writing to a file cbica::Logging logger( "file_name.txt", "randomness is highly underrated" ); // the file has already been written at this point and can be viewed // to write to console, either initialize the class as 'cbica::Logging logger;' or call EnableConsoleLogging() after the initialization. ... // more code ... logger.Write( "'I accept chaos, I'm not sure whether it accepts me' - Bob Dylan" ); // writes to file_name.txt
The class defaults to console logging. Use Logging::EnableTextLogging() or UseNewFile() to switch; by default, it writes to a text file 'EXE_NAME-log.txt' in directory specified by cbica::createTemporaryDirectory()
|
explicit |
Actual Constructor.
file_name_with_path | The file onto which the log file is to be written |
FreeText_input | Free text which the user wants to be present in the log, defaults to an empty string |
|
explicit |
Default constructor.
Just used to keep a track of the user name and executable run at a particular time.
Default constructor.
Just used to keep a track of the user name and executable run at a particular time.
void EnableConsoleLogging | ( | ) |
Switches from text to console file logging.
This is helpful if the user wants to visualize the console output. If it is done for saving, the recommended way is to call EnableTextLogging().
The output stamps are of the form:
<4 digit year>:<2 digit month>:<2 digit date>,<2 digit 24 hour>:<2 digit minute>:<2 digit second>;<free text>="">
|
inline |
This is useful in scenarios where the application has been installed in a multi-user machine.
This also disables writing of the date in the log since the assumption is that on a single user machine, the filename should be in the following format: ${userHomeDir}/.${appName}/${currentDate} (see CaPTk logging as example). This also disables the writing of the executable name.
void EnableTextLogging | ( | const std::string & | newLogFile | ) |
Switches from console to text file logging.
The output stamps are of the form:
<4 digit year>:<2 digit month>:<2 digit date>,<2 digit 24 hour>:<2 digit minute>:<2 digit second>;<free text>="">
std::string getLoggingFileName | ( | ) |
Get the file name with full path where log has happened.
|
inlineprotected |
The function used to initialize the class.
Kept private to avoid cluttering global namespace.
file_name_with_path_wrap | Wrap for file_name_with_path |
log_file_wrap | Wrap for log_file |
exe_name_wrap | Wrap for exe_name |
user_name_wrap | Wrap for user_name |
void UseNewFile | ( | const std::string & | newLogFile | ) |
Change Logging file after initializing class.
newLogFile | Path of new log file. If empty, it becomes 'cbica::createTmpDir() + cbica::getExecutableName() + "-log.txt"' |
void Write | ( | const std::string | FreeText_input | ) |
Function to call to write to log file.
FreeText_input | Free text which the user wants to be present in the log, defaults to an empty string |
void WriteError | ( | const std::string | FreeText_input | ) |
Function to call to write error messages to log file without any free text.
FreeText_input | Free text which the user wants to be present in the log |
|
inlineprotected |
The function used to do the actual writing onto the file.
Kept private to avoid cluttering global namespace.
FreeText_wrap | Wrap for FreeText |
log_file_wrap | Wrap for log_file |
timer_wrap | Wrap for timer |
exe_name_wrap | Wrap for exe_name |
user_name_wrap | Wrap for user_name |