OmniSciDB  1dac507f6e
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 106 of file Logger.h.

Constructor & Destructor Documentation

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

Definition at line 62 of file Logger.cpp.

References auto_flush_, logger::ChannelNames, channels_, file_name_pattern_, logger::filename(), join(), log_dir_, max_files_, min_free_space_, options_, rotate_daily_, rotation_size_, severity_, severity_clog_, logger::SeverityNames, and symlink_.

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

+ Here is the call graph for this function:

Member Function Documentation

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

Definition at line 115 of file Logger.cpp.

References base_path_, and log_dir_.

Referenced by logger::init().

115  {
116  return log_dir_.has_root_directory() ? log_dir_ : base_path_ / log_dir_;
117 }
std::string base_path_
Definition: Logger.h:107
boost::filesystem::path log_dir_
Definition: Logger.h:112

+ Here is the caller graph for this function:

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

Definition at line 119 of file Logger.cpp.

References options_.

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

119  {
120  return options_;
121 }
boost::program_options::options_description options_
Definition: Logger.h:108

+ Here is the caller graph for this function:

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

Definition at line 124 of file Logger.cpp.

References options_, and run.

124  {
125  po::variables_map vm;
126  po::store(
127  po::command_line_parser(argc, argv).options(options_).allow_unregistered().run(),
128  vm);
129  po::notify(vm); // Sets LogOptions member variables.
130 }
boost::program_options::options_description options_
Definition: Logger.h:108
static bool run
void logger::LogOptions::set_base_path ( std::string const &  base_path)

Definition at line 133 of file Logger.cpp.

References base_path_.

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

133  {
134  base_path_ = base_path;
135 }
std::string base_path_
Definition: Logger.h:107

+ Here is the caller graph for this function:

Member Data Documentation

bool logger::LogOptions::auto_flush_ {true}

Definition at line 119 of file Logger.h.

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

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

Definition at line 107 of file Logger.h.

Referenced by full_log_dir(), and set_base_path().

Channels logger::LogOptions::channels_

Definition at line 118 of file Logger.h.

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

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

Definition at line 114 of file Logger.h.

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

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

Definition at line 112 of file Logger.h.

Referenced by full_log_dir(), and LogOptions().

size_t logger::LogOptions::max_files_ {100}

Definition at line 120 of file Logger.h.

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

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

Definition at line 121 of file Logger.h.

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

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

Definition at line 108 of file Logger.h.

Referenced by get_options(), LogOptions(), and parse_command_line().

bool logger::LogOptions::rotate_daily_ {true}

Definition at line 122 of file Logger.h.

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

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

Definition at line 123 of file Logger.h.

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

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

Definition at line 117 of file Logger.h.

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

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

Definition at line 115 of file Logger.h.

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


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