153 const char *log_format = getenv(
"ELECTRONEUM_LOG_FORMAT");
167 std::string rname = generate_log_filename(filename_base.c_str());
168 int ret = rename(
name, rname.c_str());
174 if (max_log_files != 0)
176 std::vector<boost::filesystem::path> found_files;
177 const boost::filesystem::directory_iterator end_itr;
178 const boost::filesystem::path filename_base_path(filename_base);
179 const boost::filesystem::path parent_path = filename_base_path.has_parent_path() ? filename_base_path.parent_path() :
".";
180 for (boost::filesystem::directory_iterator iter(parent_path); iter != end_itr; ++iter)
182 const std::string filename = iter->path().string();
183 if (filename.size() >= filename_base.size() && std::memcmp(filename.data(), filename_base.data(), filename_base.size()) == 0)
185 found_files.push_back(iter->path());
188 if (found_files.size() >= max_log_files)
190 std::sort(found_files.begin(), found_files.end(), [](
const boost::filesystem::path &
a,
const boost::filesystem::path &b) {
191 boost::system::error_code ec;
192 std::time_t ta = boost::filesystem::last_write_time(boost::filesystem::path(
a), ec);
195 MERROR(
"Failed to get timestamp from " <<
a <<
": " << ec);
198 std::time_t tb = boost::filesystem::last_write_time(boost::filesystem::path(b), ec);
201 MERROR(
"Failed to get timestamp from " << b <<
": " << ec);
204 static_assert(std::is_integral<time_t>(),
"bad time_t");
207 for (
size_t i = 0; i <= found_files.size() - max_log_files; ++i)
211 boost::system::error_code ec;
212 boost::filesystem::remove(found_files[i], ec);
215 MERROR(
"Failed to remove " << found_files[i] <<
": " << ec);
218 catch (
const std::exception &e)
220 MERROR(
"Failed to remove " << found_files[i] <<
": " << e.what());
226 mlog_set_common_prefix();
227 const char *electroneum_log = getenv(
"ELECTRONEUM_LOGS");
228 if (!electroneum_log)
230 electroneum_log = get_default_categories(0);
static void setDefaultConfigurations(const Configurations &configurations, bool reconfigureExistingLoggers=false)
Sets default configurations. This configuration is used for future (and conditionally for existing) l...
Creates logger automatically when not available.
void mlog_set_log(const char *log)
static void addFlag(LoggingFlag flag)
Adds logging flag used internally.
Thread-safe Configuration repository.
Determines log file (full path) to write logs to for correponding level and logger.
Determines format of logging corresponding level and logger.
void setGlobally(ConfigurationType configurationType, const std::string &value)
Sets configuration for all levels.
static void installPreRollOutCallback(const PreRollOutCallback &callback)
Installs pre rollout callback, this callback is triggered when log file is about to be rolled out (ca...
Make terminal output colorful for supported terminals.
Enables strict file rolling.
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Whether or not to write corresponding log to log file.
std::string to_string(t_connection_type type)
Whether or not to write corresponding level and logger log to standard output. By standard output mea...
Enables hierarchical logging.
Specifies log file max size.
Allows to disable application abortion when logged using FATAL level.