Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timezone information with text file backend #210

Open
KennethBuijssen opened this issue Jun 7, 2023 · 2 comments
Open

Timezone information with text file backend #210

KennethBuijssen opened this issue Jun 7, 2023 · 2 comments

Comments

@KennethBuijssen
Copy link

KennethBuijssen commented Jun 7, 2023

We're currently working on adding logging to our application and trying to get a log file in the following format: test_20230607T165634+0200.log

With the following code however, the resulting log file is test_20230607T165634.log. After reading the documentation is seems that boost log does not support any of the time zone flags, since it uses ptime internally (https://www.boost.org/doc/libs/1_82_0/doc/html/date_time/date_time_io.html#date_time.format_flags). Could support for this be added?

#include <boost/log/trivial.hpp>
#include <boost/log/utility/setup/file.hpp>

void init_logger(const std::string& filename)
{
  auto sink = boost::log::add_file_log(boost::log::keywords::file_name = filename + "_%Y%m%dT%H%M%S%q.log");
}

int main(int, char**)
{
  init_logger("test");

  BOOST_LOG_TRIVIAL(info) << "Hello, World!";
}
@Lastique
Copy link
Member

Lastique commented Jul 2, 2023

This is not easy to do, since Boost.DateTime does not allow to create a time zone object that reflects the time zone set on the system. There doesn't seem to be a portable way to obtain this information either, at least I'm not aware of one. I reported this to Boost.DateTime, but the chances for this to be implemented soon are rather slim, unfortunately.

@otopetrik
Copy link

It could be useful to have configuration option to use UTC time for file names.

Instead of having log file names with times in unknown time zone, the timezone would be known.
Especially useful if already using attributes::utc_clock for TimeStamp

Looks like local_time_traits::get_clock() is hardcoded, with no way to use utc_time_traits

m_Facet.put(sbuf_it, m_Stream, m_Stream.fill(), boost::log::attributes::local_time_traits::get_clock());

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants