GENIE
genie::utility::Logger Class Reference

A utility class to record logs into disk files. More...

#include <Logger.h>

Public Member Functions

virtual ~Logger ()
 Destructor. More...
 

Static Public Member Functions

static void exit (void)
 Safely exit the logger. More...
 
static int log (int level, const char *fmt,...)
 Record and print a message into log file. More...
 
static void logQueries (int level, std::vector< genie::query::Query > &queries, size_t max_print_len=128)
 
static void logResults (int level, std::vector< genie::query::Query > &queries, std::vector< int > &result, std::vector< int > &result_count, size_t max_print_len=128)
 
static void logTable (int level, genie::table::inv_table *table, size_t max_print_len=32)
 
static void logInvLists (int level, const std::vector< std::vector< uint32_t > > &rawInvertedLists, size_t max_print_len=128)
 
static void set_level (int level)
 Set the screen print level for the logger. More...
 
static int get_level ()
 Get the current screen print level. More...
 
static void set_logfile_name (const char *name)
 Set the log file name. More...
 
static const char * get_logfile_name ()
 Get the current log file name. More...
 

Static Public Attributes

static const int NONE = 0
 
static const int ALERT = 1
 
static const int INFO = 2
 
static const int VERBOSE = 3
 
static const int DEBUG = 4
 
static const char *const LEVEL_NAMES []
 

Detailed Description

A utility class to record logs into disk files.

The Logger class is implemented using Singleton model and all logging calls should go through static method Logger::log .

Please set your screen print level of log information by calling Logger::set_level .

Please remember to call the Logger::exit method to safely instruct the Logger to flush and close all opened files and free occupied memory.

Definition at line 41 of file Logger.h.

Constructor & Destructor Documentation

◆ ~Logger()

genie::utility::Logger::~Logger ( )
virtual

Destructor.

Definition at line 47 of file Logger.cc.

Member Function Documentation

◆ exit()

static void genie::utility::Logger::exit ( void  )
static

Safely exit the logger.

This function should be called if the Logger class is used.

Definition at line 52 of file Logger.cc.

◆ get_level()

static int genie::utility::Logger::get_level ( )
static

Get the current screen print level.

Returns
The current screen print level set in the Logger.

Definition at line 78 of file Logger.cc.

◆ get_logfile_name()

static const char * genie::utility::Logger::get_logfile_name ( )
static

Get the current log file name.

Returns
The current log file name set in the Logger.

Definition at line 94 of file Logger.cc.

◆ log()

static int genie::utility::Logger::log ( int  level,
const char *  fmt,
  ... 
)
static

Record and print a message into log file.

The log call will direct the parameters except the level to std::sprintf .

If the current screen print level is higher than the provided logging level in the parameter, the message will be logged and printed. Otherwise the message will only be logged.

Parameters
levelThe logging level of the message.
fmtThe printing format of the message. See std::printf .
...The rest of parameters according to your format.
Returns
1 if the message is to be printed on screen or 0 otherwise.

Definition at line 99 of file Logger.cc.

◆ logInvLists()

void Logger::logInvLists ( int  level,
const std::vector< std::vector< uint32_t > > &  rawInvertedLists,
size_t  max_print_len = 128 
)
static

Definition at line 255 of file Logger.cc.

◆ logQueries()

void Logger::logQueries ( int  level,
std::vector< genie::query::Query > &  queries,
size_t  max_print_len = 128 
)
static

Definition at line 135 of file Logger.cc.

◆ logResults()

void Logger::logResults ( int  level,
std::vector< genie::query::Query > &  queries,
std::vector< int > &  result,
std::vector< int > &  result_count,
size_t  max_print_len = 128 
)
static

Definition at line 153 of file Logger.cc.

◆ logTable()

void Logger::logTable ( int  level,
genie::table::inv_table table,
size_t  max_print_len = 32 
)
static

Definition at line 171 of file Logger.cc.

◆ set_level()

static void genie::utility::Logger::set_level ( int  level)
static

Set the screen print level for the logger.

Once set, the Logger will only print messages whose logging levels are higher than the set value to screen.

It is recommended to set the screen print level at the beginning of the program.

Parameters
levelThe desired screen print level.

Definition at line 74 of file Logger.cc.

◆ set_logfile_name()

static void genie::utility::Logger::set_logfile_name ( const char *  name)
static

Set the log file name.

Once set, the Logger will write all log all messages in the current session to the file with the provided name.

The file will be created if it does not exist.

If not called, the default file name is set using the system current date and time.

Parameters
nameThe desired log file name.

Definition at line 83 of file Logger.cc.

Member Data Documentation

◆ ALERT

const int genie::utility::Logger::ALERT = 1
static

Screen print level - only error alters

Definition at line 47 of file Logger.h.

◆ DEBUG

const int genie::utility::Logger::DEBUG = 4
static

Screen print level - debugging information

Definition at line 53 of file Logger.h.

◆ INFO

const int genie::utility::Logger::INFO = 2
static

Screen print level - progress information

Definition at line 49 of file Logger.h.

◆ LEVEL_NAMES

const char *const Logger::LEVEL_NAMES
static
Initial value:
=
{ "NONE ", "ALERT ", "INFO ", "VERBOSE", "DEBUG " }

Definition at line 55 of file Logger.h.

◆ NONE

const int genie::utility::Logger::NONE = 0
static

Screen print level - no message

Definition at line 45 of file Logger.h.

◆ VERBOSE

const int genie::utility::Logger::VERBOSE = 3
static

Screen print level - detailed information

Definition at line 51 of file Logger.h.


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