17 #include <boost/date_time/posix_time/posix_time.hpp>
18 #include <boost/date_time/posix_time/posix_time_types.hpp>
19 #include <boost/filesystem.hpp>
23 using boost::filesystem::create_directory;
24 using boost::filesystem::exists;
25 using boost::filesystem::is_directory;
26 using boost::posix_time::microsec_clock;
27 using boost::posix_time::ptime;
28 using boost::posix_time::time_from_string;
29 using namespace impala;
31 const ptime
EPOCH = time_from_string(
"1970-01-01 00:00:00.000");
34 if (!exists(log_dir)) {
35 LOG(INFO) <<
"Log directory does not exist, creating: " << log_dir;
37 create_directory(log_dir);
38 }
catch (
const std::exception& e) {
39 LOG(ERROR) <<
"Could not create log directory: "
40 << log_dir <<
", " << e.what();
41 return Status(
"Failed to create log directory");
45 if (!is_directory(log_dir)) {
46 LOG(ERROR) <<
"Log path is not a directory ("
48 return Status(
"Log path is not a directory");
55 int64_t ms_since_epoch =
56 (microsec_clock::universal_time() -
EPOCH).total_milliseconds();
64 log_file_name_prefix_(log_file_name_prefix),
65 num_log_file_entries_(0),
66 max_entries_per_file_(max_entries_per_file) {
std::ofstream log_file_
Log files are written to this stream.
boost::mutex log_file_lock_
Protects log_file_, num_log_file_entries_ and log_file_name_.
#define RETURN_IF_ERROR(stmt)
some generally useful macros
std::string log_file_name_
Current log file name.
void GenerateLogFileName()
uint64_t num_log_file_entries_
Status AppendEntry(const std::string &entry)
std::string log_dir_
Directory to log to.
Status InitLoggingDir(const string &log_dir)
SimpleLogger(const std::string &log_dir_, const std::string &log_file_name_prefix_, uint64_t max_entries_per_file)
std::string log_file_name_prefix_
Prefix for all log files.
uint64_t max_entries_per_file_