Logger.hpp
Go to the documentation of this file.
1 // @formatter:off
2 //
3 // Balau core C++ library
4 //
5 // Copyright (C) 2008 Bora Software (contact@borasoftware.com)
6 //
7 // Licensed under the Boost Software License - Version 1.0 - August 17th, 2003.
8 // See the LICENSE file for the full license text.
9 //
10 
19 
20 #ifndef COM_BORA_SOFTWARE__BALAU_LOGGING__LOGGER
21 #define COM_BORA_SOFTWARE__BALAU_LOGGING__LOGGER
22 
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>
28 
29 #include <atomic>
30 #include <functional>
31 
32 namespace Balau {
33 
34 class EnvironmentProperties;
35 
36 namespace LoggingSystem {
37 
38 class LoggerConfigurationVisitor;
39 class LoggerPropertyVisitor;
40 
41 } // namespace LoggingSystem
42 
44 
63  public: virtual void write(const LoggingSystem::LoggerString & str) = 0;
64 
70  public: virtual void flush() = 0;
71 
72  public: virtual ~LoggingStream() = default;
73 };
74 
81 using LoggingStreamFactory = LoggingStream * (*)(std::string_view uri);
82 
84 
92 class Logger {
94 
105  public: static Logger & getLogger(std::string_view loggingNamespace) noexcept;
106 
112  public: static void flushAll();
113 
117  public: static Logger & globalLogger();
118 
130  public: static void configure(const std::string & configurationText,
131  const std::map<std::string, std::string> & placeholders = std::map<std::string, std::string>());
132 
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>());
146 
158  public: static void resetConfiguration();
159 
169  public: static void lockConfiguration(bool throwOnReconfigure = false);
170 
176  public: static void registerLoggingStreamFactory(const std::string & scheme, LoggingStreamFactory factory);
177 
179 
183  public: LoggingLevel getLevel() const noexcept {
184  return level.load(std::memory_order_relaxed);
185  }
186 
190  public: bool flushes() const noexcept {
191  return shouldFlush.load(std::memory_order_relaxed);
192  }
193 
202  public: void flush() const;
203 
207  public: std::string getNamespace() const {
208  return nameSpace;
209  }
210 
216  public: std::string getConfiguration() const;
217 
221  public: bool operator == (const Logger & logger) const {
222  return nameSpace == logger.nameSpace;
223  }
224 
226 
230  public: bool traceEnabled() const {
231  return getLevel() >= LoggingLevel::TRACE;
232  }
233 
237  public: bool debugEnabled() const {
238  return getLevel() >= LoggingLevel::DEBUG;
239  }
240 
244  public: bool infoEnabled() const {
245  return getLevel() >= LoggingLevel::INFO;
246  }
247 
251  public: bool warnEnabled() const {
252  return getLevel() >= LoggingLevel::WARN;
253  }
254 
258  public: bool errorEnabled() const {
259  return getLevel() >= LoggingLevel::ERROR;
260  }
261 
265  public: bool enabled(LoggingLevel level) const {
266  return getLevel() >= level;
267  }
268 
270 
274  public: void trace(const char * message) const {
275  if (getLevel() >= LoggingLevel::TRACE) {
276  LoggingSystem::startLogAllocation();
277  logMessage(SourceCodeLocation(), LoggingLevel::TRACE, *this, message);
278  }
279  }
280 
284  public: void trace(std::string_view message) const {
285  if (getLevel() >= LoggingLevel::TRACE) {
286  LoggingSystem::startLogAllocation();
287  logMessage(SourceCodeLocation(), LoggingLevel::TRACE, *this, message);
288  }
289  }
290 
294  public: template <typename ... ObjectT>
295  void trace(const char * message, const ObjectT & ... object) const {
296  if (getLevel() >= LoggingLevel::TRACE) {
297  LoggingSystem::startLogAllocation();
298  logMessage(SourceCodeLocation(), LoggingLevel::TRACE, *this, message, LoggingSystem::makeStringVector(object ... ));
299  }
300  }
301 
305  public: template <typename ... ObjectT>
306  void trace(std::string_view message, const ObjectT & ... object) const {
307  if (getLevel() >= LoggingLevel::TRACE) {
308  LoggingSystem::startLogAllocation();
309  logMessage(SourceCodeLocation(), LoggingLevel::TRACE, *this, message, LoggingSystem::makeStringVector(object ... ));
310  }
311  }
312 
316  public: void trace(const std::function<std::string ()> & function) const {
317  if (getLevel() >= LoggingLevel::TRACE) {
318  LoggingSystem::startLogAllocation();
319  const std::string message = function();
320  logMessage(SourceCodeLocation(), LoggingLevel::TRACE, *this, message);
321  }
322  }
323 
327  public: void trace(const SourceCodeLocation & location, const char * message) const {
328  if (getLevel() >= LoggingLevel::TRACE) {
329  LoggingSystem::startLogAllocation();
330  logMessage(location, LoggingLevel::TRACE, *this, message);
331  }
332  }
333 
337  public: void trace(const SourceCodeLocation & location, std::string_view message) const {
338  if (getLevel() >= LoggingLevel::TRACE) {
339  LoggingSystem::startLogAllocation();
340  logMessage(location, LoggingLevel::TRACE, *this, message);
341  }
342  }
343 
347  public: template <typename ... ObjectT>
348  void trace(const SourceCodeLocation & location, const char * message, const ObjectT & ... object) const {
349  if (getLevel() >= LoggingLevel::TRACE) {
350  LoggingSystem::startLogAllocation();
351  logMessage(location, LoggingLevel::TRACE, *this, message, LoggingSystem::makeStringVector(object ... ));
352  }
353  }
354 
358  public: template <typename ... ObjectT>
359  void trace(const SourceCodeLocation & location, std::string_view message, const ObjectT & ... object) const {
360  if (getLevel() >= LoggingLevel::TRACE) {
361  LoggingSystem::startLogAllocation();
362  logMessage(location, LoggingLevel::TRACE, *this, message, LoggingSystem::makeStringVector(object ... ));
363  }
364  }
365 
369  public: void trace(const SourceCodeLocation & location, const std::function<std::string ()> & function) const {
370  if (getLevel() >= LoggingLevel::TRACE) {
371  LoggingSystem::startLogAllocation();
372  const std::string message = function();
373  logMessage(location, LoggingLevel::TRACE, *this, message);
374  }
375  }
376 
378 
382  public: void debug(const char * message) const {
383  if (getLevel() >= LoggingLevel::DEBUG) {
384  LoggingSystem::startLogAllocation();
385  logMessage(SourceCodeLocation(), LoggingLevel::DEBUG, *this, message);
386  }
387  }
388 
392  public: void debug(std::string_view message) const {
393  if (getLevel() >= LoggingLevel::DEBUG) {
394  LoggingSystem::startLogAllocation();
395  logMessage(SourceCodeLocation(), LoggingLevel::DEBUG, *this, message);
396  }
397  }
398 
402  public: template <typename ... ObjectT>
403  void debug(const char * message, const ObjectT & ... object) const {
404  if (getLevel() >= LoggingLevel::DEBUG) {
405  LoggingSystem::startLogAllocation();
406  logMessage(SourceCodeLocation(), LoggingLevel::DEBUG, *this, message, LoggingSystem::makeStringVector(object ... ));
407  }
408  }
409 
413  public: template <typename ... ObjectT>
414  void debug(std::string_view message, const ObjectT & ... object) const {
415  if (getLevel() >= LoggingLevel::DEBUG) {
416  LoggingSystem::startLogAllocation();
417  logMessage(SourceCodeLocation(), LoggingLevel::DEBUG, *this, message, LoggingSystem::makeStringVector(object ... ));
418  }
419  }
420 
424  public: void debug(const std::function<std::string ()> & function) const {
425  if (getLevel() >= LoggingLevel::DEBUG) {
426  LoggingSystem::startLogAllocation();
427  const std::string message = function();
428  logMessage(SourceCodeLocation(), LoggingLevel::DEBUG, *this, message);
429  }
430  }
431 
435  public: void debug(const SourceCodeLocation & location, const char * message) const {
436  if (getLevel() >= LoggingLevel::DEBUG) {
437  LoggingSystem::startLogAllocation();
438  logMessage(location, LoggingLevel::DEBUG, *this, message);
439  }
440  }
441 
445  public: void debug(const SourceCodeLocation & location, std::string_view message) const {
446  if (getLevel() >= LoggingLevel::DEBUG) {
447  LoggingSystem::startLogAllocation();
448  logMessage(location, LoggingLevel::DEBUG, *this, message);
449  }
450  }
451 
455  public: template <typename ... ObjectT>
456  void debug(const SourceCodeLocation & location, const char * message, const ObjectT & ... object) const {
457  if (getLevel() >= LoggingLevel::DEBUG) {
458  LoggingSystem::startLogAllocation();
459  logMessage(location, LoggingLevel::DEBUG, *this, message, LoggingSystem::makeStringVector(object ... ));
460  }
461  }
462 
466  public: template <typename ... ObjectT>
467  void debug(const SourceCodeLocation & location, std::string_view message, const ObjectT & ... object) const {
468  if (getLevel() >= LoggingLevel::DEBUG) {
469  LoggingSystem::startLogAllocation();
470  logMessage(location, LoggingLevel::DEBUG, *this, message, LoggingSystem::makeStringVector(object ... ));
471  }
472  }
473 
477  public: void debug(const SourceCodeLocation & location, const std::function<std::string ()> & function) const {
478  if (getLevel() >= LoggingLevel::DEBUG) {
479  LoggingSystem::startLogAllocation();
480  const std::string message = function();
481  logMessage(location, LoggingLevel::DEBUG, *this, message);
482  }
483  }
484 
486 
490  public: void info(const char * message) const {
491  if (getLevel() >= LoggingLevel::INFO) {
492  LoggingSystem::startLogAllocation();
493  logMessage(SourceCodeLocation(), LoggingLevel::INFO, *this, message);
494  }
495  }
496 
500  public: void info(std::string_view message) const {
501  if (getLevel() >= LoggingLevel::INFO) {
502  LoggingSystem::startLogAllocation();
503  logMessage(SourceCodeLocation(), LoggingLevel::INFO, *this, message);
504  }
505  }
506 
510  public: template <typename ... ObjectT>
511  void info(const char * message, const ObjectT & ... object) const {
512  if (getLevel() >= LoggingLevel::INFO) {
513  LoggingSystem::startLogAllocation();
514  logMessage(SourceCodeLocation(), LoggingLevel::INFO, *this, message, LoggingSystem::makeStringVector(object ... ));
515  }
516  }
517 
521  public: template <typename ... ObjectT>
522  void info(std::string_view message, const ObjectT & ... object) const {
523  if (getLevel() >= LoggingLevel::INFO) {
524  LoggingSystem::startLogAllocation();
525  logMessage(SourceCodeLocation(), LoggingLevel::INFO, *this, message, LoggingSystem::makeStringVector(object ... ));
526  }
527  }
528 
532  public: void info(const std::function<std::string ()> & function) const {
533  if (getLevel() >= LoggingLevel::INFO) {
534  LoggingSystem::startLogAllocation();
535  const std::string message = function();
536  logMessage(SourceCodeLocation(), LoggingLevel::INFO, *this, message);
537  }
538  }
539 
543  public: void info(const SourceCodeLocation & location, const char * message) const {
544  if (getLevel() >= LoggingLevel::INFO) {
545  LoggingSystem::startLogAllocation();
546  logMessage(location, LoggingLevel::INFO, *this, message);
547  }
548  }
549 
553  public: void info(const SourceCodeLocation & location, std::string_view message) const {
554  if (getLevel() >= LoggingLevel::INFO) {
555  LoggingSystem::startLogAllocation();
556  logMessage(location, LoggingLevel::INFO, *this, message);
557  }
558  }
559 
563  public: template <typename ... ObjectT>
564  void info(const SourceCodeLocation & location, const char * message, const ObjectT & ... object) const {
565  if (getLevel() >= LoggingLevel::INFO) {
566  LoggingSystem::startLogAllocation();
567  logMessage(location, LoggingLevel::INFO, *this, message, LoggingSystem::makeStringVector(object ... ));
568  }
569  }
570 
574  public: template <typename ... ObjectT>
575  void info(const SourceCodeLocation & location, std::string_view message, const ObjectT & ... object) const {
576  if (getLevel() >= LoggingLevel::INFO) {
577  LoggingSystem::startLogAllocation();
578  logMessage(location, LoggingLevel::INFO, *this, message, LoggingSystem::makeStringVector(object ... ));
579  }
580  }
581 
585  public: void info(const SourceCodeLocation & location, const std::function<std::string ()> & function) const {
586  if (getLevel() >= LoggingLevel::INFO) {
587  LoggingSystem::startLogAllocation();
588  const std::string message = function();
589  logMessage(location, LoggingLevel::INFO, *this, message);
590  }
591  }
592 
594 
598  public: void warn(const char * message) const {
599  if (getLevel() >= LoggingLevel::WARN) {
600  LoggingSystem::startLogAllocation();
601  logMessage(SourceCodeLocation(), LoggingLevel::WARN, *this, message);
602  }
603  }
604 
608  public: void warn(std::string_view message) const {
609  if (getLevel() >= LoggingLevel::WARN) {
610  LoggingSystem::startLogAllocation();
611  logMessage(SourceCodeLocation(), LoggingLevel::WARN, *this, message);
612  }
613  }
614 
618  public: template <typename ... ObjectT>
619  void warn(const char * message, const ObjectT & ... object) const {
620  if (getLevel() >= LoggingLevel::WARN) {
621  LoggingSystem::startLogAllocation();
622  logMessage(SourceCodeLocation(), LoggingLevel::WARN, *this, message, LoggingSystem::makeStringVector(object ... ));
623  }
624  }
625 
629  public: template <typename ... ObjectT>
630  void warn(std::string_view message, const ObjectT & ... object) const {
631  if (getLevel() >= LoggingLevel::WARN) {
632  LoggingSystem::startLogAllocation();
633  logMessage(SourceCodeLocation(), LoggingLevel::WARN, *this, message, LoggingSystem::makeStringVector(object ... ));
634  }
635  }
636 
640  public: void warn(const std::function<std::string ()> & function) const {
641  if (getLevel() >= LoggingLevel::WARN) {
642  LoggingSystem::startLogAllocation();
643  const std::string message = function();
644  logMessage(SourceCodeLocation(), LoggingLevel::WARN, *this, message);
645  }
646  }
647 
651  public: void warn(const SourceCodeLocation & location, const char * message) const {
652  if (getLevel() >= LoggingLevel::WARN) {
653  LoggingSystem::startLogAllocation();
654  logMessage(location, LoggingLevel::WARN, *this, message);
655  }
656  }
657 
661  public: void warn(const SourceCodeLocation & location, std::string_view message) const {
662  if (getLevel() >= LoggingLevel::WARN) {
663  LoggingSystem::startLogAllocation();
664  logMessage(location, LoggingLevel::WARN, *this, message);
665  }
666  }
667 
671  public: template <typename ... ObjectT>
672  void warn(const SourceCodeLocation & location, const char * message, const ObjectT & ... object) const {
673  if (getLevel() >= LoggingLevel::WARN) {
674  LoggingSystem::startLogAllocation();
675  logMessage(location, LoggingLevel::WARN, *this, message, LoggingSystem::makeStringVector(object ... ));
676  }
677  }
678 
682  public: template <typename ... ObjectT>
683  void warn(const SourceCodeLocation & location, std::string_view message, const ObjectT & ... object) const {
684  if (getLevel() >= LoggingLevel::WARN) {
685  LoggingSystem::startLogAllocation();
686  logMessage(location, LoggingLevel::WARN, *this, message, LoggingSystem::makeStringVector(object ... ));
687  }
688  }
689 
693  public: void warn(const SourceCodeLocation & location, const std::function<std::string ()> & function) const {
694  if (getLevel() >= LoggingLevel::WARN) {
695  LoggingSystem::startLogAllocation();
696  const std::string message = function();
697  logMessage(location, LoggingLevel::WARN, *this, message);
698  }
699  }
700 
702 
706  public: void error(const char * message) const {
707  if (getLevel() >= LoggingLevel::ERROR) {
708  LoggingSystem::startLogAllocation();
709  logMessage(SourceCodeLocation(), LoggingLevel::ERROR, *this, message);
710  }
711  }
712 
716  public: void error(std::string_view message) const {
717  if (getLevel() >= LoggingLevel::ERROR) {
718  LoggingSystem::startLogAllocation();
719  logMessage(SourceCodeLocation(), LoggingLevel::ERROR, *this, message);
720  }
721  }
722 
726  public: template <typename ... ObjectT>
727  void error(const char * message, const ObjectT & ... object) const {
728  if (getLevel() >= LoggingLevel::ERROR) {
729  LoggingSystem::startLogAllocation();
730  logMessage(SourceCodeLocation(), LoggingLevel::ERROR, *this, message, LoggingSystem::makeStringVector(object ... ));
731  }
732  }
733 
737  public: template <typename ... ObjectT>
738  void error(std::string_view message, const ObjectT & ... object) const {
739  if (getLevel() >= LoggingLevel::ERROR) {
740  LoggingSystem::startLogAllocation();
741  logMessage(SourceCodeLocation(), LoggingLevel::ERROR, *this, message, LoggingSystem::makeStringVector(object ... ));
742  }
743  }
744 
748  public: void error(const std::function<std::string ()> & function) const {
749  if (getLevel() >= LoggingLevel::ERROR) {
750  LoggingSystem::startLogAllocation();
751  const std::string message = function();
752  logMessage(SourceCodeLocation(), LoggingLevel::ERROR, *this, message);
753  }
754  }
755 
759  public: void error(const SourceCodeLocation & location, const char * message) const {
760  if (getLevel() >= LoggingLevel::ERROR) {
761  LoggingSystem::startLogAllocation();
762  logMessage(location, LoggingLevel::ERROR, *this, message);
763  }
764  }
765 
769  public: void error(const SourceCodeLocation & location, std::string_view message) const {
770  if (getLevel() >= LoggingLevel::ERROR) {
771  LoggingSystem::startLogAllocation();
772  logMessage(location, LoggingLevel::ERROR, *this, message);
773  }
774  }
775 
779  public: template <typename ... ObjectT>
780  void error(const SourceCodeLocation & location, const char * message, const ObjectT & ... object) const {
781  if (getLevel() >= LoggingLevel::ERROR) {
782  LoggingSystem::startLogAllocation();
783  logMessage(location, LoggingLevel::ERROR, *this, message, LoggingSystem::makeStringVector(object ... ));
784  }
785  }
786 
790  public: template <typename ... ObjectT>
791  void error(const SourceCodeLocation & location, std::string_view message, const ObjectT & ... object) const {
792  if (getLevel() >= LoggingLevel::ERROR) {
793  LoggingSystem::startLogAllocation();
794  logMessage(location, LoggingLevel::ERROR, *this, message, LoggingSystem::makeStringVector(object ... ));
795  }
796  }
797 
801  public: void error(const SourceCodeLocation & location, const std::function<std::string ()> & function) const {
802  if (getLevel() >= LoggingLevel::ERROR) {
803  LoggingSystem::startLogAllocation();
804  const std::string message = function();
805  logMessage(location, LoggingLevel::ERROR, *this, message);
806  }
807  }
808 
810 
816  public: void log(LoggingLevel specifiedLevel, const char * message) const {
817  if (getLevel() >= specifiedLevel) {
818  LoggingSystem::startLogAllocation();
819  logMessage(SourceCodeLocation(), specifiedLevel, *this, message);
820  }
821  }
822 
828  public: void log(LoggingLevel specifiedLevel, std::string_view message) const {
829  if (getLevel() >= specifiedLevel) {
830  LoggingSystem::startLogAllocation();
831  logMessage(SourceCodeLocation(), specifiedLevel, *this, message);
832  }
833  }
834 
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 ... ));
845  }
846  }
847 
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 ... ));
858  }
859  }
860 
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();
870  logMessage(SourceCodeLocation(), specifiedLevel, *this, message);
871  }
872  }
873 
879  public: void log(LoggingLevel specifiedLevel, const SourceCodeLocation & location, const char * message) const {
880  if (getLevel() >= specifiedLevel) {
881  LoggingSystem::startLogAllocation();
882  logMessage(location, specifiedLevel, *this, message);
883  }
884  }
885 
891  public: void log(LoggingLevel specifiedLevel, const SourceCodeLocation & location, std::string_view message) const {
892  if (getLevel() >= specifiedLevel) {
893  LoggingSystem::startLogAllocation();
894  logMessage(location, specifiedLevel, *this, message);
895  }
896  }
897 
903  public: template <typename ... ObjectT>
904  void log(LoggingLevel specifiedLevel, const SourceCodeLocation & location, const char * message, const ObjectT & ... object) const {
905  if (getLevel() >= specifiedLevel) {
906  LoggingSystem::startLogAllocation();
907  logMessage(location, specifiedLevel, *this, message, LoggingSystem::makeStringVector(object ... ));
908  }
909  }
910 
916  public: template <typename ... ObjectT>
917  void log(LoggingLevel specifiedLevel, const SourceCodeLocation & location, std::string_view message, const ObjectT & ... object) const {
918  if (getLevel() >= specifiedLevel) {
919  LoggingSystem::startLogAllocation();
920  logMessage(location, specifiedLevel, *this, message, LoggingSystem::makeStringVector(object ... ));
921  }
922  }
923 
929  public: void log(LoggingLevel specifiedLevel, const SourceCodeLocation & location, const std::function<std::string ()> & function) const {
930  if (getLevel() >= specifiedLevel) {
931  LoggingSystem::startLogAllocation();
932  const std::string message = function();
933  logMessage(location, specifiedLevel, *this, message);
934  }
935  }
936 
938 
939  // Local identifier of this logger.
940  // Not const in order to support move semantics only.
941  private: std::string identifier;
942 
943  // Full namespace of this logger.
944  // Not const in order to support move semantics only.
945  private: std::string nameSpace;
946 
947  // Abbreviated namespace of this logger.
948  // Not const in order to support move semantics only.
949  private: std::string ns;
950 
951  //
952  // The logging level of this logger.
953  //
954  // Reads on this atomic are free on x86/x64.
955  //
956  private: std::atomic<LoggingLevel> level = { LoggingLevel::NONE };
957 
958  //
959  // Indicates whether messages from this logger should flush the stream after each message.
960  //
961  // Reads on this atomic are free on x86/x64.
962  //
963  private: std::atomic_bool shouldFlush { true };
964 
965  //
966  // The log items for which this logger is configured.
967  //
968  // The log item vector is a pointer in order to allow reconfiguration to occur
969  // during logging, without the need for synchronisation.
970  //
971  // Log item vector instances are kept in the global logging system state and
972  // are not deleted until exit.
973  //
974  // Apart from compiler ordering restrictions, reads on these atomics are
975  // free on x86/x64.
976  //
977  private: std::atomic<std::vector<std::shared_ptr<LoggingSystem::LogItem>> *> logItems {};
978 
979  //
980  // The streams to which this logger writes.
981  // The array contains one stream pointer for each logging level (0 = error, 4 = trace).
982  //
983  // The streams are pointer in order to allow reconfiguration to occur during logging,
984  // without the need for synchronisation.
985  //
986  // Stream instances are kept in the global logging system state and are not
987  // deleted until exit.
988  //
989  // Apart from compiler ordering restrictions, reads on these atomics are
990  // free on x86/x64.
991  //
992  private: std::array<std::atomic<LoggingStream *>, _BalauLoggingLevelCount> streams {};
993 
994  friend class LoggingSystem::LoggerConfigurationVisitor;
995  friend class LoggingSystem::LoggerPropertyVisitor;
996 
997  //
998  // This logger's configuration properties.
999  //
1000  // This is the complete set of configuration properties for this logger,
1001  // including the ones inherited from the parent logger.
1002  //
1003  // This field is not used during logging. It is only used at configuration
1004  // time, protected by the global logging mutex.
1005  //
1006  private: std::map<std::string, std::string> properties;
1007 
1008  private: Logger(std::string identifier_,
1009  std::string nameSpace_,
1010  std::string ns_,
1011  const std::initializer_list<std::string> & propertyPairs);
1012 
1013  private: Logger() = default;
1014  private: Logger(Logger && rhs) noexcept;
1015  private: Logger(std::string && identifier_, std::string && nameSpace_, std::string && ns_) noexcept;
1016 
1017  public: Logger(const Logger &) = delete;
1018  public: Logger & operator = (const Logger &) = delete;
1019 
1020  private: void inheritConfiguration(const Logger & copy);
1021 
1022  // Non-parameter version.
1023  private: static void logMessage(const SourceCodeLocation & location,
1024  LoggingLevel level,
1025  const Logger & logger,
1026  std::string_view message);
1027 
1028  // Parameter version.
1029  private: static void logMessage(const SourceCodeLocation & location,
1030  LoggingLevel level,
1031  const Logger & logger,
1032  std::string_view message,
1033  const LoggingSystem::LoggerStringVector & parameters);
1034 
1035  friend class LoggingSystem::LoggerHolder;
1036  friend class LoggingSystem::LoggingState;
1037  friend class BalauLogger;
1038 };
1039 
1040 } // namespace Balau
1041 
1043 
1047 #define BalauLogTrace(LOGGER, ...) LOGGER.trace(SourceCodeLocation(__FILE__, __LINE__), __VA_ARGS__)
1048 
1052 #define BalauLogDebug(LOGGER, ...) LOGGER.debug(SourceCodeLocation(__FILE__, __LINE__), __VA_ARGS__)
1053 
1057 #define BalauLogInfo(LOGGER, ...) LOGGER.info(SourceCodeLocation(__FILE__, __LINE__), __VA_ARGS__)
1058 
1062 #define BalauLogWarn(LOGGER, ...) LOGGER.warn(SourceCodeLocation(__FILE__, __LINE__), __VA_ARGS__)
1063 
1067 #define BalauLogError(LOGGER, ...) LOGGER.error(SourceCodeLocation(__FILE__, __LINE__), __VA_ARGS__)
1068 
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&#39;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&#39;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&#39;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&#39;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&#39;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&#39;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