Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
|
#include <simple-logger.h>
Public Member Functions | |
SimpleLogger (const std::string &log_dir_, const std::string &log_file_name_prefix_, uint64_t max_entries_per_file) | |
Status | Init () |
Status | AppendEntry (const std::string &entry) |
Status | Flush () |
Private Member Functions | |
void | GenerateLogFileName () |
Status | FlushInternal () |
Private Attributes | |
boost::mutex | log_file_lock_ |
Protects log_file_, num_log_file_entries_ and log_file_name_. More... | |
std::string | log_dir_ |
Directory to log to. More... | |
std::string | log_file_name_prefix_ |
Prefix for all log files. More... | |
uint64_t | num_log_file_entries_ |
uint64_t | max_entries_per_file_ |
std::ofstream | log_file_ |
Log files are written to this stream. More... | |
std::string | log_file_name_ |
Current log file name. More... | |
A class that provides basic thread-safe support for logging to a file. Supports creation of the log file and log directories as well as rolling the log file when it has reached a specified number of entries.
Definition at line 28 of file simple-logger.h.
SimpleLogger::SimpleLogger | ( | const std::string & | log_dir_, |
const std::string & | log_file_name_prefix_, | ||
uint64_t | max_entries_per_file | ||
) |
Definition at line 61 of file simple-logger.cc.
Status SimpleLogger::AppendEntry | ( | const std::string & | entry | ) |
Appends the given string to the log file, including a newline. If the log file already contains the specified entry limit, a new log file will be created. This function is thread safe and blocks while a Flush() is in progress
Definition at line 80 of file simple-logger.cc.
References FlushInternal(), GenerateLogFileName(), log_file_, log_file_lock_, log_file_name_, max_entries_per_file_, num_log_file_entries_, impala::Status::OK, and RETURN_IF_ERROR.
Status SimpleLogger::Flush | ( | ) |
Flushes the log file to disk by closing and re-opening the file. This function is thread safe and blocks while a WriteEntry() is in progress
Definition at line 94 of file simple-logger.cc.
References FlushInternal(), and log_file_lock_.
|
private |
Flushes the log file to disk (closes and reopens the file). Must be called with the log_file_lock_ held.
Definition at line 99 of file simple-logger.cc.
References log_file_, log_file_name_, and impala::Status::OK.
Referenced by AppendEntry(), Flush(), and Init().
|
private |
Generates and sets a new log file name that is based off the log file name prefix and the current system time. The format will be: PREFIX-<UTC timestamp>="">
Definition at line 53 of file simple-logger.cc.
References EPOCH, log_dir_, log_file_name_, and log_file_name_prefix_.
Referenced by AppendEntry(), and Init().
Status SimpleLogger::Init | ( | ) |
Initializes the logging directory and creates the initial log file. If the log dir does not already exist, it will be created. This function is not thread safe and should only be called once.
Definition at line 69 of file simple-logger.cc.
References FlushInternal(), GenerateLogFileName(), InitLoggingDir(), log_dir_, log_file_name_, impala::Status::OK, and RETURN_IF_ERROR.
|
private |
Directory to log to.
Definition at line 52 of file simple-logger.h.
Referenced by GenerateLogFileName(), and Init().
|
private |
Log files are written to this stream.
Definition at line 66 of file simple-logger.h.
Referenced by AppendEntry(), and FlushInternal().
|
private |
Protects log_file_, num_log_file_entries_ and log_file_name_.
Definition at line 49 of file simple-logger.h.
Referenced by AppendEntry(), and Flush().
|
private |
Current log file name.
Definition at line 69 of file simple-logger.h.
Referenced by AppendEntry(), FlushInternal(), GenerateLogFileName(), and Init().
|
private |
Prefix for all log files.
Definition at line 55 of file simple-logger.h.
Referenced by GenerateLogFileName().
|
private |
The maximum number of entries for each log file. If this number is reached the log file will be rolled
Definition at line 63 of file simple-logger.h.
Referenced by AppendEntry().
|
private |
Counts the number of entries written to log_file_; used to decide when to roll the log file
Definition at line 59 of file simple-logger.h.
Referenced by AppendEntry().