OmniSciDB  c07336695a
logger::LogOptions Class Reference

#include <Logger.h>

+ Collaboration diagram for logger::LogOptions:

Public Member Functions

 LogOptions (char const *argv0)
 
boost::filesystem::path full_log_dir () const
 
boost::program_options::options_description const & get_options () const
 
void parse_command_line (int, char const *const *)
 
void set_base_path (std::string const &base_path)
 

Public Attributes

boost::filesystem::path log_dir_ {"mapd_log"}
 
std::string file_name_pattern_ {".{SEVERITY}.%Y%m%d-%H%M%S.log"}
 
std::string symlink_ {".{SEVERITY}"}
 
Severity severity_ {Severity::INFO}
 
Severity severity_clog_ {Severity::ERROR}
 
Channels channels_
 
bool auto_flush_ {true}
 
size_t max_files_ {100}
 
size_t min_free_space_ {20 << 20}
 
bool rotate_daily_ {true}
 
size_t rotation_size_ {10 << 20}
 

Private Attributes

std::string base_path_ {"."}
 
boost::program_options::options_description options_
 

Detailed Description

Definition at line 103 of file Logger.h.

Constructor & Destructor Documentation

◆ LogOptions()

logger::LogOptions::LogOptions ( char const *  argv0)

Definition at line 54 of file Logger.cpp.

References logger::ChannelNames, join(), and logger::SeverityNames.

54  : options_("Logging") {
55  // Log file base_name matches name of program.
56  std::string const base_name = argv0 == nullptr
57  ? std::string("omnisci_server")
58  : boost::filesystem::path(argv0).filename().string();
60  symlink_ = base_name + symlink_;
61  std::string const channels = join(ChannelNames, " ");
62  // Filter out DEBUG[1-4] severities from --help options
63  std::string severities;
64  for (auto const& name : SeverityNames) {
65  if (!boost::algorithm::starts_with(name, "DEBUG")) {
66  (severities += (severities.empty() ? "" : " ")) += name;
67  }
68  }
69  options_.add_options()(
70  "log-directory",
71  po::value<boost::filesystem::path>(&log_dir_)->default_value(log_dir_),
72  "Logging directory. May be relative to data directory, or absolute.");
73  options_.add_options()(
74  "log-file-name",
75  po::value<std::string>(&file_name_pattern_)->default_value(file_name_pattern_),
76  "Log file name relative to log-directory.");
77  options_.add_options()("log-symlink",
78  po::value<std::string>(&symlink_)->default_value(symlink_),
79  "Symlink to active log.");
80  options_.add_options()("log-severity",
81  po::value<Severity>(&severity_)->default_value(severity_),
82  ("Log to file severity level: " + severities).c_str());
83  options_.add_options()(
84  "log-severity-clog",
85  po::value<Severity>(&severity_clog_)->default_value(severity_clog_),
86  ("Log to console severity level: " + severities).c_str());
87  options_.add_options()("log-channels",
88  po::value<Channels>(&channels_)->default_value(channels_),
89  ("Log channel debug info: " + channels).c_str());
90  options_.add_options()("log-auto-flush",
91  po::value<bool>(&auto_flush_)->default_value(auto_flush_),
92  "Flush logging buffer to file after each message.");
93  options_.add_options()("log-max-files",
94  po::value<size_t>(&max_files_)->default_value(max_files_),
95  "Maximum number of log files to keep.");
96  options_.add_options()(
97  "log-min-free-space",
98  po::value<size_t>(&min_free_space_)->default_value(20 << 20),
99  "Minimum number of bytes left on device before oldest log files are deleted.");
100  options_.add_options()("log-rotate-daily",
101  po::value<bool>(&rotate_daily_)->default_value(true),
102  "Start new log files at midnight.");
103  options_.add_options()("log-rotation-size",
104  po::value<size_t>(&rotation_size_)->default_value(10 << 20),
105  "Maximum file size in bytes before new log files are started.");
106 }
size_t min_free_space_
Definition: Logger.h:118
std::string join(T const &container, std::string const &delim)
Channels channels_
Definition: Logger.h:115
bool rotate_daily_
Definition: Logger.h:119
std::string symlink_
Definition: Logger.h:112
constexpr std::array< char const *, 8 > SeverityNames
Definition: Logger.h:82
Severity severity_
Definition: Logger.h:113
constexpr std::array< char const *, 2 > ChannelNames
Definition: Logger.h:60
boost::program_options::options_description options_
Definition: Logger.h:105
std::string file_name_pattern_
Definition: Logger.h:111
size_t rotation_size_
Definition: Logger.h:120
size_t max_files_
Definition: Logger.h:117
Severity severity_clog_
Definition: Logger.h:114
boost::filesystem::path log_dir_
Definition: Logger.h:109
+ Here is the call graph for this function:

Member Function Documentation

◆ full_log_dir()

boost::filesystem::path logger::LogOptions::full_log_dir ( ) const

Definition at line 108 of file Logger.cpp.

References base_path_, and log_dir_.

Referenced by logger::init().

108  {
109  return log_dir_.has_root_directory() ? log_dir_ : base_path_ / log_dir_;
110 }
std::string base_path_
Definition: Logger.h:104
boost::filesystem::path log_dir_
Definition: Logger.h:109
+ Here is the caller graph for this function:

◆ get_options()

po::options_description const & logger::LogOptions::get_options ( ) const

Definition at line 112 of file Logger.cpp.

References options_.

Referenced by MapDProgramOptions::fillOptions(), and main().

112  {
113  return options_;
114 }
boost::program_options::options_description options_
Definition: Logger.h:105
+ Here is the caller graph for this function:

◆ parse_command_line()

void logger::LogOptions::parse_command_line ( int  argc,
char const *const *  argv 
)

Definition at line 117 of file Logger.cpp.

References options_, and run.

Referenced by TestHelpers::init_logger_stderr_only().

117  {
118  po::variables_map vm;
119  po::store(
120  po::command_line_parser(argc, argv).options(options_).allow_unregistered().run(),
121  vm);
122  po::notify(vm); // Sets LogOptions member variables.
123 }
boost::program_options::options_description options_
Definition: Logger.h:105
static bool run
+ Here is the caller graph for this function:

◆ set_base_path()

void logger::LogOptions::set_base_path ( std::string const &  base_path)

Definition at line 126 of file Logger.cpp.

References base_path_.

Referenced by main(), and MapDProgramOptions::parse_command_line().

126  {
127  base_path_ = base_path;
128 }
std::string base_path_
Definition: Logger.h:104
+ Here is the caller graph for this function:

Member Data Documentation

◆ auto_flush_

bool logger::LogOptions::auto_flush_ {true}

◆ base_path_

std::string logger::LogOptions::base_path_ {"."}
private

Definition at line 104 of file Logger.h.

Referenced by full_log_dir(), and set_base_path().

◆ channels_

Channels logger::LogOptions::channels_

Definition at line 115 of file Logger.h.

Referenced by logger::init().

◆ file_name_pattern_

std::string logger::LogOptions::file_name_pattern_ {".{SEVERITY}.%Y%m%d-%H%M%S.log"}

Definition at line 111 of file Logger.h.

Referenced by logger::make_sink().

◆ log_dir_

boost::filesystem::path logger::LogOptions::log_dir_ {"mapd_log"}

Definition at line 109 of file Logger.h.

Referenced by full_log_dir().

◆ max_files_

size_t logger::LogOptions::max_files_ {100}

◆ min_free_space_

size_t logger::LogOptions::min_free_space_ {20 << 20}

Definition at line 118 of file Logger.h.

Referenced by logger::make_sink().

◆ options_

boost::program_options::options_description logger::LogOptions::options_
private

Definition at line 105 of file Logger.h.

Referenced by get_options(), and parse_command_line().

◆ rotate_daily_

bool logger::LogOptions::rotate_daily_ {true}

Definition at line 119 of file Logger.h.

Referenced by logger::make_sink().

◆ rotation_size_

size_t logger::LogOptions::rotation_size_ {10 << 20}

Definition at line 120 of file Logger.h.

Referenced by logger::make_sink().

◆ severity_

Severity logger::LogOptions::severity_ {Severity::INFO}

◆ severity_clog_

Severity logger::LogOptions::severity_clog_ {Severity::ERROR}

Definition at line 114 of file Logger.h.

Referenced by logger::init(), and logger::make_sink().

◆ symlink_

std::string logger::LogOptions::symlink_ {".{SEVERITY}"}

Definition at line 112 of file Logger.h.

Referenced by logger::make_sink().


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