-
Notifications
You must be signed in to change notification settings - Fork 2
/
subsystem_registrator.h
61 lines (52 loc) · 1.66 KB
/
subsystem_registrator.h
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
52
53
54
55
56
57
58
59
60
61
/* SPDX-License-Identifier: MIT */
#pragma once
#include "logger.h"
#include "logfile_export.h"
#include <string>
namespace SuS {
namespace logfile {
//! Helper class to automatically register subsystems on application startup.
/*!
* Initialize an instance of this class to have your subsystems registered
* when the applications starts, so that it is immediately seen by the
* logging system.
*
* Typically this is used to initialize a variable in file-global scope,
* or a static variable of a class:
* @code
* namespace {
* subsystem_registrator log_id("my_subsystem");
* }
* @endcode
* and then
* @code
* SuS_LOG(finest, log_id(), "Hello world");
* @endcode
*
* Internally, \ref `logger::register_subsystem()` is called, and the returned
* id is available through \ref `subsystem_registrator::operator()()`.
*
* When the same subsystem name is registered several times, it is
* guaranteed that all registrations are merged and the same id is returned
* for all registrations.
*/
class LOGFILE_EXPORT subsystem_registrator {
public:
//! Initialize the class, thereby registering the subsystem.
/*!
* @param _name The name of the subsystem to register.
*/
subsystem_registrator(const std::string &_name);
//! Return the logger id of the subsystem registered by this class.
/*!
* @return The logger id for the subsystem.
*/
SuS::logfile::logger::subsystem_t operator()() {
return m_subsystem;
} // operator()
void set_min_log_level(logger::log_level _level);
private:
SuS::logfile::logger::subsystem_t m_subsystem;
}; // class subsystem_registrator
} // namespace logfile
} // namespace SuS