77 std::map<std::string, std::tuple<std::shared_ptr<Sink>,
Filter, std::shared_ptr<Formatter>>>
mData;
87 bool has(
const std::string&
id)
const noexcept {
96 void configure(
const std::string&
id, std::shared_ptr<Sink> sink) {
97 std::lock_guard<std::mutex> lock(
mMutex);
98 mData[id] = std::make_tuple(std::move(sink),
Filter(), std::make_shared<Formatter>());
105 void configure(
const std::string&
id,
const std::string& filename) {
106 configure(
id, std::make_shared<FileSink>(filename));
113 void configure(
const std::string&
id, std::ostream& os) {
114 configure(
id, std::make_shared<StreamSink>(os));
122 auto it =
mData.find(
id);
123 assert(it !=
mData.end());
124 return std::get<1>(it->second);
131 const std::shared_ptr<Formatter>&
formatter(
const std::string&
id) noexcept {
132 auto it =
mData.find(
id);
133 assert(it !=
mData.end());
134 return std::get<2>(it->second);
141 void formatter(
const std::string&
id, std::shared_ptr<Formatter> fmt) noexcept {
142 auto it =
mData.find(
id);
143 assert(it !=
mData.end());
144 std::get<2>(it->second) = std::move(fmt);
145 std::get<2>(it->second)->configure(std::get<1>(it->second));
152 for (
auto& t:
mData) {
153 std::get<2>(t.second)->configure(std::get<1>(t.second));
163 for (
const auto& t:
mData) {
164 if (std::get<1>(t.second).check(channel, level)) {
178 std::lock_guard<std::mutex> lock(
mMutex);
179 for (
auto& t:
mData) {
180 if (!std::get<1>(t.second).check(channel, level))
continue;
181 std::get<2>(t.second)->prefix(std::get<0>(t.second)->log(), channel, level, info);
182 std::get<0>(t.second)->log() << ss.str();
183 std::get<2>(t.second)->suffix(std::get<0>(t.second)->log());
carl is the main namespace for the library.
Logger & logger()
Returns the single global instance of a Logger.
LogLevel
Indicated which log messages should be forwarded to some sink.
Base class that implements a singleton.
static Logger & getInstance()
Returns the single instance of this class by reference.
This class checks if some log message shall be forwarded to some sink.
const std::shared_ptr< Formatter > & formatter(const std::string &id) noexcept
Retrieves the Formatter for some Sink.
void log(LogLevel level, const std::string &channel, const std::stringstream &ss, const RecordInfo &info)
Logs a message.
void configure(const std::string &id, std::shared_ptr< Sink > sink)
Installs the given sink.
bool visible(LogLevel level, const std::string &channel) const noexcept
Checks whether a log message would be visible for some sink.
std::mutex mMutex
Logging mutex to ensure thread-safe logging.
bool has(const std::string &id) const noexcept
Check if a Sink with the given id has been installed.
void configure(const std::string &id, const std::string &filename)
Installs a FileSink.
Filter & filter(const std::string &id) noexcept
Retrieves the Filter for some Sink.
void configure(const std::string &id, std::ostream &os)
Installs a StreamSink.
void formatter(const std::string &id, std::shared_ptr< Formatter > fmt) noexcept
Overwrites the Formatter for some Sink.
std::map< std::string, std::tuple< std::shared_ptr< Sink >, Filter, std::shared_ptr< Formatter > > > mData
Mapping from channels to associated logging classes.
void resetFormatter() noexcept
Reconfigures all Formatter objects.
Additional information about a log message.