20 #ifndef COM_BORA_SOFTWARE__BALAU_LOGGING__LOGGER 21 #define COM_BORA_SOFTWARE__BALAU_LOGGING__LOGGER 23 #include <Balau/Application/Impl/BindingKey.hpp> 25 #include <Balau/Logging/Impl/LoggerAllocator.hpp> 26 #include <Balau/Logging/Impl/LoggerForwardDeclarations.hpp> 27 #include <Balau/Type/SourceCodeLocation.hpp> 34 class EnvironmentProperties;
36 namespace LoggingSystem {
38 class LoggerConfigurationVisitor;
39 class LoggerPropertyVisitor;
63 public:
virtual void write(
const LoggingSystem::LoggerString & str) = 0;
70 public:
virtual void flush() = 0;
105 public:
static Logger & getLogger(std::string_view loggingNamespace) noexcept;
112 public:
static void flushAll();
117 public:
static Logger & globalLogger();
130 public:
static void configure(
const std::string & configurationText,
131 const std::map<std::string, std::string> & placeholders = std::map<std::string, std::string>());
144 public:
static void configure(
const std::shared_ptr<EnvironmentProperties> & configuration,
145 const std::map<std::string, std::string> & placeholders = std::map<std::string, std::string>());
158 public:
static void resetConfiguration();
169 public:
static void lockConfiguration(
bool throwOnReconfigure =
false);
176 public:
static void registerLoggingStreamFactory(
const std::string & scheme,
LoggingStreamFactory factory);
184 return level.load(std::memory_order_relaxed);
191 return shouldFlush.load(std::memory_order_relaxed);
202 public:
void flush()
const;
216 public: std::string getConfiguration()
const;
222 return nameSpace == logger.nameSpace;
266 return getLevel() >= level;
274 public:
void trace(
const char * message)
const {
276 LoggingSystem::startLogAllocation();
284 public:
void trace(std::string_view message)
const {
286 LoggingSystem::startLogAllocation();
294 public:
template <
typename ... ObjectT>
295 void trace(
const char * message,
const ObjectT & ...
object)
const {
297 LoggingSystem::startLogAllocation();
305 public:
template <
typename ... ObjectT>
306 void trace(std::string_view message,
const ObjectT & ...
object)
const {
308 LoggingSystem::startLogAllocation();
316 public:
void trace(
const std::function<std::string ()> &
function)
const {
318 LoggingSystem::startLogAllocation();
319 const std::string message =
function();
329 LoggingSystem::startLogAllocation();
339 LoggingSystem::startLogAllocation();
347 public:
template <
typename ... ObjectT>
350 LoggingSystem::startLogAllocation();
351 logMessage(location,
LoggingLevel::TRACE, *
this, message, LoggingSystem::makeStringVector(
object ... ));
358 public:
template <
typename ... ObjectT>
361 LoggingSystem::startLogAllocation();
362 logMessage(location,
LoggingLevel::TRACE, *
this, message, LoggingSystem::makeStringVector(
object ... ));
371 LoggingSystem::startLogAllocation();
372 const std::string message =
function();
382 public:
void debug(
const char * message)
const {
384 LoggingSystem::startLogAllocation();
392 public:
void debug(std::string_view message)
const {
394 LoggingSystem::startLogAllocation();
402 public:
template <
typename ... ObjectT>
403 void debug(
const char * message,
const ObjectT & ...
object)
const {
405 LoggingSystem::startLogAllocation();
413 public:
template <
typename ... ObjectT>
414 void debug(std::string_view message,
const ObjectT & ...
object)
const {
416 LoggingSystem::startLogAllocation();
424 public:
void debug(
const std::function<std::string ()> &
function)
const {
426 LoggingSystem::startLogAllocation();
427 const std::string message =
function();
437 LoggingSystem::startLogAllocation();
447 LoggingSystem::startLogAllocation();
455 public:
template <
typename ... ObjectT>
458 LoggingSystem::startLogAllocation();
459 logMessage(location,
LoggingLevel::DEBUG, *
this, message, LoggingSystem::makeStringVector(
object ... ));
466 public:
template <
typename ... ObjectT>
469 LoggingSystem::startLogAllocation();
470 logMessage(location,
LoggingLevel::DEBUG, *
this, message, LoggingSystem::makeStringVector(
object ... ));
479 LoggingSystem::startLogAllocation();
480 const std::string message =
function();
490 public:
void info(
const char * message)
const {
492 LoggingSystem::startLogAllocation();
500 public:
void info(std::string_view message)
const {
502 LoggingSystem::startLogAllocation();
510 public:
template <
typename ... ObjectT>
511 void info(
const char * message,
const ObjectT & ...
object)
const {
513 LoggingSystem::startLogAllocation();
521 public:
template <
typename ... ObjectT>
522 void info(std::string_view message,
const ObjectT & ...
object)
const {
524 LoggingSystem::startLogAllocation();
532 public:
void info(
const std::function<std::string ()> &
function)
const {
534 LoggingSystem::startLogAllocation();
535 const std::string message =
function();
545 LoggingSystem::startLogAllocation();
555 LoggingSystem::startLogAllocation();
563 public:
template <
typename ... ObjectT>
566 LoggingSystem::startLogAllocation();
567 logMessage(location,
LoggingLevel::INFO, *
this, message, LoggingSystem::makeStringVector(
object ... ));
574 public:
template <
typename ... ObjectT>
577 LoggingSystem::startLogAllocation();
578 logMessage(location,
LoggingLevel::INFO, *
this, message, LoggingSystem::makeStringVector(
object ... ));
587 LoggingSystem::startLogAllocation();
588 const std::string message =
function();
598 public:
void warn(
const char * message)
const {
600 LoggingSystem::startLogAllocation();
608 public:
void warn(std::string_view message)
const {
610 LoggingSystem::startLogAllocation();
618 public:
template <
typename ... ObjectT>
619 void warn(
const char * message,
const ObjectT & ...
object)
const {
621 LoggingSystem::startLogAllocation();
629 public:
template <
typename ... ObjectT>
630 void warn(std::string_view message,
const ObjectT & ...
object)
const {
632 LoggingSystem::startLogAllocation();
640 public:
void warn(
const std::function<std::string ()> &
function)
const {
642 LoggingSystem::startLogAllocation();
643 const std::string message =
function();
653 LoggingSystem::startLogAllocation();
663 LoggingSystem::startLogAllocation();
671 public:
template <
typename ... ObjectT>
674 LoggingSystem::startLogAllocation();
675 logMessage(location,
LoggingLevel::WARN, *
this, message, LoggingSystem::makeStringVector(
object ... ));
682 public:
template <
typename ... ObjectT>
685 LoggingSystem::startLogAllocation();
686 logMessage(location,
LoggingLevel::WARN, *
this, message, LoggingSystem::makeStringVector(
object ... ));
695 LoggingSystem::startLogAllocation();
696 const std::string message =
function();
706 public:
void error(
const char * message)
const {
708 LoggingSystem::startLogAllocation();
716 public:
void error(std::string_view message)
const {
718 LoggingSystem::startLogAllocation();
726 public:
template <
typename ... ObjectT>
727 void error(
const char * message,
const ObjectT & ...
object)
const {
729 LoggingSystem::startLogAllocation();
737 public:
template <
typename ... ObjectT>
738 void error(std::string_view message,
const ObjectT & ...
object)
const {
740 LoggingSystem::startLogAllocation();
748 public:
void error(
const std::function<std::string ()> &
function)
const {
750 LoggingSystem::startLogAllocation();
751 const std::string message =
function();
761 LoggingSystem::startLogAllocation();
771 LoggingSystem::startLogAllocation();
779 public:
template <
typename ... ObjectT>
782 LoggingSystem::startLogAllocation();
783 logMessage(location,
LoggingLevel::ERROR, *
this, message, LoggingSystem::makeStringVector(
object ... ));
790 public:
template <
typename ... ObjectT>
793 LoggingSystem::startLogAllocation();
794 logMessage(location,
LoggingLevel::ERROR, *
this, message, LoggingSystem::makeStringVector(
object ... ));
803 LoggingSystem::startLogAllocation();
804 const std::string message =
function();
817 if (getLevel() >= specifiedLevel) {
818 LoggingSystem::startLogAllocation();
829 if (getLevel() >= specifiedLevel) {
830 LoggingSystem::startLogAllocation();
840 public:
template <
typename ... ObjectT>
841 void log(
LoggingLevel specifiedLevel,
const char * message,
const ObjectT & ...
object)
const {
842 if (getLevel() >= specifiedLevel) {
843 LoggingSystem::startLogAllocation();
844 logMessage(
SourceCodeLocation(), specifiedLevel, *
this, message, LoggingSystem::makeStringVector(
object ... ));
853 public:
template <
typename ... ObjectT>
854 void log(
LoggingLevel specifiedLevel, std::string_view message,
const ObjectT & ...
object)
const {
855 if (getLevel() >= specifiedLevel) {
856 LoggingSystem::startLogAllocation();
857 logMessage(
SourceCodeLocation(), specifiedLevel, *
this, message, LoggingSystem::makeStringVector(
object ... ));
866 public:
void log(
LoggingLevel specifiedLevel,
const std::function<std::string ()> &
function)
const {
867 if (getLevel() >= specifiedLevel) {
868 LoggingSystem::startLogAllocation();
869 const std::string message =
function();
880 if (getLevel() >= specifiedLevel) {
881 LoggingSystem::startLogAllocation();
882 logMessage(location, specifiedLevel, *
this, message);
892 if (getLevel() >= specifiedLevel) {
893 LoggingSystem::startLogAllocation();
894 logMessage(location, specifiedLevel, *
this, message);
903 public:
template <
typename ... ObjectT>
905 if (getLevel() >= specifiedLevel) {
906 LoggingSystem::startLogAllocation();
907 logMessage(location, specifiedLevel, *
this, message, LoggingSystem::makeStringVector(
object ... ));
916 public:
template <
typename ... ObjectT>
918 if (getLevel() >= specifiedLevel) {
919 LoggingSystem::startLogAllocation();
920 logMessage(location, specifiedLevel, *
this, message, LoggingSystem::makeStringVector(
object ... ));
930 if (getLevel() >= specifiedLevel) {
931 LoggingSystem::startLogAllocation();
932 const std::string message =
function();
933 logMessage(location, specifiedLevel, *
this, message);
941 private: std::string identifier;
945 private: std::string nameSpace;
949 private: std::string ns;
963 private: std::atomic_bool shouldFlush {
true };
977 private: std::atomic<std::vector<std::shared_ptr<LoggingSystem::LogItem>> *> logItems {};
992 private: std::array<std::atomic<LoggingStream *>, _BalauLoggingLevelCount> streams {};
994 friend class LoggingSystem::LoggerConfigurationVisitor;
995 friend class LoggingSystem::LoggerPropertyVisitor;
1006 private: std::map<std::string, std::string> properties;
1008 private:
Logger(std::string identifier_,
1009 std::string nameSpace_,
1011 const std::initializer_list<std::string> & propertyPairs);
1013 private:
Logger() =
default;
1015 private:
Logger(std::string && identifier_, std::string && nameSpace_, std::string && ns_) noexcept;
1020 private:
void inheritConfiguration(
const Logger & copy);
1026 std::string_view message);
1032 std::string_view message,
1033 const LoggingSystem::LoggerStringVector & parameters);
1035 friend class LoggingSystem::LoggerHolder;
1036 friend class LoggingSystem::LoggingState;
1037 friend class BalauLogger;
1047 #define BalauLogTrace(LOGGER, ...) LOGGER.trace(SourceCodeLocation(__FILE__, __LINE__), __VA_ARGS__) 1052 #define BalauLogDebug(LOGGER, ...) LOGGER.debug(SourceCodeLocation(__FILE__, __LINE__), __VA_ARGS__) 1057 #define BalauLogInfo(LOGGER, ...) LOGGER.info(SourceCodeLocation(__FILE__, __LINE__), __VA_ARGS__) 1062 #define BalauLogWarn(LOGGER, ...) LOGGER.warn(SourceCodeLocation(__FILE__, __LINE__), __VA_ARGS__) 1067 #define BalauLogError(LOGGER, ...) LOGGER.error(SourceCodeLocation(__FILE__, __LINE__), __VA_ARGS__) 1069 #endif // COM_BORA_SOFTWARE__BALAU_LOGGING__LOGGER void info(const SourceCodeLocation &location, const char *message, const ObjectT &... object) const
Log an info message with parameters and the source code location of the log message call site...
Definition: Logger.hpp:564
void log(LoggingLevel specifiedLevel, std::string_view message, const ObjectT &... object) const
Log a message with parameters.
Definition: Logger.hpp:854
void error(const char *message, const ObjectT &... object) const
Log an error message with parameters.
Definition: Logger.hpp:727
void log(LoggingLevel specifiedLevel, const char *message) const
Log a message.
Definition: Logger.hpp:816
bool operator==(const BalauException &lhs, const BalauException &rhs)
Base class comparison function for Balau exceptions.
Definition: BalauException.hpp:112
void log(LoggingLevel specifiedLevel, const SourceCodeLocation &location, const char *message, const ObjectT &... object) const
Log an error message with parameters and the source code location of the log message call site...
Definition: Logger.hpp:904
void trace(const SourceCodeLocation &location, const char *message) const
Log a trace message and the source code location of the log message call site.
Definition: Logger.hpp:327
void warn(const SourceCodeLocation &location, std::string_view message) const
Log a warn message and the source code location of the log message call site.
Definition: Logger.hpp:661
bool traceEnabled() const
Is trace level logging enabled for this logger.
Definition: Logger.hpp:230
bool errorEnabled() const
Is error level logging enabled for this logger.
Definition: Logger.hpp:258
bool flushes() const noexcept
Returns true if the logger is auto-flushing.
Definition: Logger.hpp:190
void trace(const char *message, const ObjectT &... object) const
Log a trace message with parameters.
Definition: Logger.hpp:295
Log to the logger's trace stream if the logger is trace enabled.
LoggingLevel
The logging level.
Definition: LoggingLevel.hpp:32
void info(const char *message) const
Log an info message.
Definition: Logger.hpp:490
void warn(const SourceCodeLocation &location, const std::function< std::string()> &function) const
Log a warn message via the supplied function and the source code location of the log message call sit...
Definition: Logger.hpp:693
void error(const SourceCodeLocation &location, const char *message) const
Log an error message and the source code location of the log message call site.
Definition: Logger.hpp:759
Log to the logger's error stream if the logger is error enabled.
void warn(const SourceCodeLocation &location, std::string_view message, const ObjectT &... object) const
Log a warn message with parameters and the source code location of the log message call site...
Definition: Logger.hpp:683
void log(LoggingLevel specifiedLevel, const SourceCodeLocation &location, const char *message) const
Log an error message and the source code location of the log message call site.
Definition: Logger.hpp:879
std::string getNamespace() const
Get the logging namespace of this logger.
Definition: Logger.hpp:207
void warn(const std::function< std::string()> &function) const
Log a warn message via the supplied function.
Definition: Logger.hpp:640
LoggingStream *(*)(std::string_view uri) LoggingStreamFactory
The logging stream factory function type.
Definition: Logger.hpp:81
void warn(const char *message, const ObjectT &... object) const
Log a warn message with parameters.
Definition: Logger.hpp:619
The root Balau namespace.
Definition: ApplicationConfiguration.hpp:23
Log to the logger's info stream if the logger is info enabled.
void log(LoggingLevel specifiedLevel, std::string_view message) const
Log a message.
Definition: Logger.hpp:828
bool debugEnabled() const
Is debug level logging enabled for this logger.
Definition: Logger.hpp:237
void info(const std::function< std::string()> &function) const
Log an info message via the supplied function.
Definition: Logger.hpp:532
void debug(std::string_view message, const ObjectT &... object) const
Log a debug message with parameters.
Definition: Logger.hpp:414
LoggingLevel getLevel() const noexcept
Get the logging level of this logger.
Definition: Logger.hpp:183
void info(std::string_view message) const
Log an info message.
Definition: Logger.hpp:500
void log(LoggingLevel specifiedLevel, const SourceCodeLocation &location, std::string_view message) const
Log an error message and the source code location of the log message call site.
Definition: Logger.hpp:891
void error(const char *message) const
Log an error message.
Definition: Logger.hpp:706
Used to indicate that a logger is not enabled.
void debug(const SourceCodeLocation &location, const std::function< std::string()> &function) const
Log a debug message via the supplied function and the source code location of the log message call si...
Definition: Logger.hpp:477
void warn(const char *message) const
Log a warn message.
Definition: Logger.hpp:598
void info(const char *message, const ObjectT &... object) const
Log an info message with parameters.
Definition: Logger.hpp:511
Base class of logging stream plugins.
Definition: Logger.hpp:57
Log to the logger's debug stream if the logger is debug enabled.
void log(LoggingLevel specifiedLevel, const SourceCodeLocation &location, std::string_view message, const ObjectT &... object) const
Log an error message with parameters and the source code location of the log message call site...
Definition: Logger.hpp:917
void warn(std::string_view message, const ObjectT &... object) const
Log a warn message with parameters.
Definition: Logger.hpp:630
void warn(std::string_view message) const
Log a warn message.
Definition: Logger.hpp:608
void trace(std::string_view message) const
Log a trace message.
Definition: Logger.hpp:284
The main logger class.
Definition: Logger.hpp:92
A type used to representing a source code file and line number pair, obtained via the FILE and LINE m...
Definition: SourceCodeLocation.hpp:27
void error(const SourceCodeLocation &location, std::string_view message) const
Log an error message and the source code location of the log message call site.
Definition: Logger.hpp:769
void trace(const SourceCodeLocation &location, const char *message, const ObjectT &... object) const
Log a trace message with parameters and the source code location of the log message call site...
Definition: Logger.hpp:348
The logging system's logging level.
bool enabled(LoggingLevel level) const
Is logging at the specified level enabled for this logger.
Definition: Logger.hpp:265
void log(LoggingLevel specifiedLevel, const SourceCodeLocation &location, const std::function< std::string()> &function) const
Log an error message via the supplied function and the source code location of the log message call s...
Definition: Logger.hpp:929
void trace(const char *message) const
Log a trace message.
Definition: Logger.hpp:274
void info(const SourceCodeLocation &location, const std::function< std::string()> &function) const
Log an info message via the supplied function and the source code location of the log message call si...
Definition: Logger.hpp:585
void warn(const SourceCodeLocation &location, const char *message) const
Log a warn message and the source code location of the log message call site.
Definition: Logger.hpp:651
void trace(const SourceCodeLocation &location, std::string_view message) const
Log a trace message and the source code location of the log message call site.
Definition: Logger.hpp:337
void trace(const SourceCodeLocation &location, std::string_view message, const ObjectT &... object) const
Log a trace message with parameters and the source code location of the log message call site...
Definition: Logger.hpp:359
void info(const SourceCodeLocation &location, std::string_view message, const ObjectT &... object) const
Log an info message with parameters and the source code location of the log message call site...
Definition: Logger.hpp:575
void error(const std::function< std::string()> &function) const
Log a error message via the supplied function.
Definition: Logger.hpp:748
void debug(const char *message) const
Log a debug message.
Definition: Logger.hpp:382
void debug(const char *message, const ObjectT &... object) const
Log a debug message with parameters.
Definition: Logger.hpp:403
void error(std::string_view message, const ObjectT &... object) const
Log an error message with parameters.
Definition: Logger.hpp:738
void error(std::string_view message) const
Log an error message.
Definition: Logger.hpp:716
bool infoEnabled() const
Is info level logging enabled for this logger.
Definition: Logger.hpp:244
void info(std::string_view message, const ObjectT &... object) const
Log an info message with parameters.
Definition: Logger.hpp:522
void error(const SourceCodeLocation &location, const char *message, const ObjectT &... object) const
Log an error message with parameters and the source code location of the log message call site...
Definition: Logger.hpp:780
void info(const SourceCodeLocation &location, const char *message) const
Log an info message and the source code location of the log message call site.
Definition: Logger.hpp:543
void trace(std::string_view message, const ObjectT &... object) const
Log a trace message with parameters.
Definition: Logger.hpp:306
void debug(const SourceCodeLocation &location, std::string_view message, const ObjectT &... object) const
Log a debug message with parameters and the source code location of the log message call site...
Definition: Logger.hpp:467
void debug(std::string_view message) const
Log a debug message.
Definition: Logger.hpp:392
void error(const SourceCodeLocation &location, std::string_view message, const ObjectT &... object) const
Log an error message with parameters and the source code location of the log message call site...
Definition: Logger.hpp:791
void trace(const SourceCodeLocation &location, const std::function< std::string()> &function) const
Log a trace message via the supplied function and the source code location of the log message call si...
Definition: Logger.hpp:369
void debug(const SourceCodeLocation &location, const char *message, const ObjectT &... object) const
Log a debug message with parameters and the source code location of the log message call site...
Definition: Logger.hpp:456
void info(const SourceCodeLocation &location, std::string_view message) const
Log an info message and the source code location of the log message call site.
Definition: Logger.hpp:553
void debug(const std::function< std::string()> &function) const
Log a debug message via the supplied function.
Definition: Logger.hpp:424
void log(LoggingLevel specifiedLevel, const char *message, const ObjectT &... object) const
Log a message with parameters.
Definition: Logger.hpp:841
void trace(const std::function< std::string()> &function) const
Log a trace message via the supplied function.
Definition: Logger.hpp:316
void error(const SourceCodeLocation &location, const std::function< std::string()> &function) const
Log an error message via the supplied function and the source code location of the log message call s...
Definition: Logger.hpp:801
void debug(const SourceCodeLocation &location, std::string_view message) const
Log a debug message and the source code location of the log message call site.
Definition: Logger.hpp:445
Log to the logger's warn stream if the logger is warn enabled.
void debug(const SourceCodeLocation &location, const char *message) const
Log a debug message and the source code location of the log message call site.
Definition: Logger.hpp:435
void warn(const SourceCodeLocation &location, const char *message, const ObjectT &... object) const
Log a warn message with parameters and the source code location of the log message call site...
Definition: Logger.hpp:672
void log(LoggingLevel specifiedLevel, const std::function< std::string()> &function) const
Log a error message via the supplied function.
Definition: Logger.hpp:866
bool warnEnabled() const
Is warn level logging enabled for this logger.
Definition: Logger.hpp:251