forked from osm2pgsql-dev/osm2pgsql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogging.cpp
More file actions
51 lines (39 loc) · 1.3 KB
/
logging.cpp
File metadata and controls
51 lines (39 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/**
* SPDX-License-Identifier: GPL-2.0-or-later
*
* This file is part of osm2pgsql (https://osm2pgsql.org/).
*
* Copyright (C) 2006-2025 by the osm2pgsql developer community.
* For a full list of authors see the git log.
*/
#include "logging.hpp"
#include <osmium/thread/util.hpp>
namespace {
thread_local unsigned int this_thread_num = 0;
/// Global logger singleton
logger the_logger{};
} // anonymous namespace
/// Access the global logger singleton
logger &get_logger() noexcept { return the_logger; }
void logger::generate_common_prefix(std::string *str, fmt::text_style const &ts,
char const *prefix) const
{
*str += fmt::format("{:%Y-%m-%d %H:%M:%S} ",
fmt::localtime(std::time(nullptr)));
if (m_current_level == log_level::debug) {
*str += fmt::format(ts, "[{:02d}] ", this_thread_num);
}
if (prefix) {
*str += fmt::format(ts, "{}: ", prefix);
}
}
void logger::init_thread(unsigned int num)
{
// Store thread number in thread local variable
this_thread_num = num;
// Set thread name in operating system.
// On Linux thread names have a maximum length of 16 characters.
std::string name{"_osm2pgsql_"};
name.append(std::to_string(num));
osmium::thread::set_thread_name(name.c_str());
}