OmniSciDB  340b00dbf6
 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)
 
void set_options ()
 

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_ {"."}
 
std::unique_ptr
< 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 66 of file Logger.cpp.

References file_name_pattern_, logger::filename(), set_options(), and symlink_.

66  {
67  // Log file base_name matches name of program.
68  std::string const base_name =
69  argv0 == nullptr ? std::string("omnisci_server") : filename(argv0);
71  symlink_ = base_name + symlink_;
72  set_options();
73 }
std::string filename(char const *path)
Definition: Logger.cpp:62
std::string symlink_
Definition: Logger.h:117
std::string file_name_pattern_
Definition: Logger.h:116
void set_options()
Definition: Logger.cpp:98

+ Here is the call graph for this function:

Member Function Documentation

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

Definition at line 75 of file Logger.cpp.

References base_path_, and log_dir_.

Referenced by logger::init().

75  {
76  return log_dir_.has_root_directory() ? log_dir_ : base_path_ / log_dir_;
77 }
std::string base_path_
Definition: Logger.h:107
boost::filesystem::path log_dir_
Definition: Logger.h:114

+ Here is the caller graph for this function:

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

Definition at line 79 of file Logger.cpp.

References options_.

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

79  {
80  return *options_;
81 }
std::unique_ptr< boost::program_options::options_description > options_
Definition: Logger.h:110

+ Here is the caller graph for this function:

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

Definition at line 84 of file Logger.cpp.

84  {
85  po::variables_map vm;
86  po::store(
87  po::command_line_parser(argc, argv).options(*options_).allow_unregistered().run(),
88  vm);
89  po::notify(vm); // Sets LogOptions member variables.
90 }
void logger::LogOptions::set_base_path ( std::string const &  base_path)

Definition at line 93 of file Logger.cpp.

References base_path_.

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

93  {
94  base_path_ = base_path;
95 }
std::string base_path_
Definition: Logger.h:107

+ Here is the caller graph for this function:

void logger::LogOptions::set_options ( )

Definition at line 98 of file Logger.cpp.

References auto_flush_, logger::ChannelNames, channels_, file_name_pattern_, log_dir_, max_files_, min_free_space_, setup::name, options_, rotate_daily_, rotation_size_, severity_, severity_clog_, logger::SeverityNames, and symlink_.

Referenced by LogOptions().

98  {
99  options_ = std::make_unique<boost::program_options::options_description>("Logging");
100  std::string const channels =
101  std::accumulate(ChannelNames.cbegin() + 1,
102  ChannelNames.cend(),
103  std::string(ChannelNames.front()),
104  [](auto a, auto channel) { return a + ' ' + channel; });
105  // Filter out DEBUG[1-4] severities from --help options
106  std::string severities;
107  for (auto const& name : SeverityNames) {
108  if (!boost::algorithm::starts_with(name, "DEBUG")) {
109  (severities += (severities.empty() ? "" : " ")) += name;
110  }
111  }
112  options_->add_options()(
113  "log-directory",
114  po::value<boost::filesystem::path>(&log_dir_)->default_value(log_dir_),
115  "Logging directory. May be relative to data directory, or absolute.");
116  options_->add_options()(
117  "log-file-name",
118  po::value<std::string>(&file_name_pattern_)->default_value(file_name_pattern_),
119  "Log file name relative to log-directory.");
120  options_->add_options()("log-symlink",
121  po::value<std::string>(&symlink_)->default_value(symlink_),
122  "Symlink to active log.");
123  options_->add_options()("log-severity",
124  po::value<Severity>(&severity_)->default_value(severity_),
125  ("Log to file severity level: " + severities).c_str());
126  options_->add_options()(
127  "log-severity-clog",
128  po::value<Severity>(&severity_clog_)->default_value(severity_clog_),
129  ("Log to console severity level: " + severities).c_str());
130  options_->add_options()("log-channels",
131  po::value<Channels>(&channels_)->default_value(channels_),
132  ("Log channel debug info: " + channels).c_str());
133  options_->add_options()("log-auto-flush",
134  po::value<bool>(&auto_flush_)->default_value(auto_flush_),
135  "Flush logging buffer to file after each message.");
136  options_->add_options()("log-max-files",
137  po::value<size_t>(&max_files_)->default_value(max_files_),
138  "Maximum number of log files to keep.");
139  options_->add_options()(
140  "log-min-free-space",
141  po::value<size_t>(&min_free_space_)->default_value(min_free_space_),
142  "Minimum number of bytes left on device before oldest log files are deleted.");
143  options_->add_options()("log-rotate-daily",
144  po::value<bool>(&rotate_daily_)->default_value(rotate_daily_),
145  "Start new log files at midnight.");
146  options_->add_options()(
147  "log-rotation-size",
148  po::value<size_t>(&rotation_size_)->default_value(rotation_size_),
149  "Maximum file size in bytes before new log files are started.");
150 }
std::unique_ptr< boost::program_options::options_description > options_
Definition: Logger.h:110
constexpr std::array< char const *, 3 > ChannelNames
Definition: Logger.h:63
size_t min_free_space_
Definition: Logger.h:123
Channels channels_
Definition: Logger.h:120
bool rotate_daily_
Definition: Logger.h:124
std::string symlink_
Definition: Logger.h:117
constexpr std::array< char const *, 8 > SeverityNames
Definition: Logger.h:85
Severity severity_
Definition: Logger.h:118
std::string file_name_pattern_
Definition: Logger.h:116
size_t rotation_size_
Definition: Logger.h:125
size_t max_files_
Definition: Logger.h:122
string name
Definition: setup.py:35
Severity severity_clog_
Definition: Logger.h:119
boost::filesystem::path log_dir_
Definition: Logger.h:114

+ Here is the caller graph for this function:

Member Data Documentation

bool logger::LogOptions::auto_flush_ {true}

Definition at line 121 of file Logger.h.

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

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 120 of file Logger.h.

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

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

Definition at line 116 of file Logger.h.

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

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

Definition at line 114 of file Logger.h.

Referenced by full_log_dir(), and set_options().

size_t logger::LogOptions::max_files_ {100}

Definition at line 122 of file Logger.h.

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

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

Definition at line 123 of file Logger.h.

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

std::unique_ptr<boost::program_options::options_description> logger::LogOptions::options_
private

Definition at line 110 of file Logger.h.

Referenced by get_options(), and set_options().

bool logger::LogOptions::rotate_daily_ {true}

Definition at line 124 of file Logger.h.

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

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

Definition at line 125 of file Logger.h.

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

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

Definition at line 119 of file Logger.h.

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

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

Definition at line 117 of file Logger.h.

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


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