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

+ Here is the call graph for this function:

+ 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: