Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-05 08:52:41

0001 // Created by Dmitry Romanov
0002 // Subject to the terms in the LICENSE file found in the top-level directory.
0003 //
0004 
0005 #pragma once
0006 
0007 #include <memory>
0008 #include <spdlog/spdlog.h>
0009 #include <JANA/JApplicationFwd.h>
0010 #include "services/log/Log_service.h"
0011 #include "SpdlogExtensions.h"
0012 
0013 namespace eicrecon {
0014 class SpdlogMixin {
0015   /** Logger mixin
0016          *
0017          * @example:
0018          *      class MyFactory : JFactory, SpdlogMixin {
0019          *
0020          *          void Init() {
0021          *              InitLogger(GetApplication(), "MyPlugin:MyFactory");
0022          *
0023          *              // Logger is ready and can be used:
0024          *              m_log->info("MyFactory logger initialized");
0025          *          }
0026          *
0027          *          void Process(...) {
0028          *              m_log->trace("Using logger!");
0029          *          }
0030          *      };
0031          */
0032 public:
0033   using level = Log_service::level;
0034 
0035   /**
0036          * Initializes logger through current LogService
0037          * @param app - JApplication pointer, as obtained from GetApplication()
0038          * @param param_prefix - name of both logger and user parameter
0039          * @param default_level - optional - default log level, overrides default logging level
0040          *                          : trace, debug, info, warn, err, critical, off
0041          *
0042          * @remark: Each logger is cloned from spdlog::default_logger(). This allows to set the default level
0043          *          and output formatting on a global system level. But sometimes it is useful to provide
0044          *          default log level independently on what is set by the system. Again we are about DEFAULT value
0045          *          if no user flag is provided
0046          *
0047          * @example:
0048          *      InitLogger(GetApplication(), "BTRK:TrackerHits")           // Default log level is set the same as in system
0049          *      InitLogger(GetApplication(), "BTRK:TrackerHits", "info")   // By default log level is info
0050          *
0051          *  will create "BTRK:TrackerHits" logger and check -PBTRK:TrackerHits:LogLevel user parameter
0052          */
0053   void InitLogger(JApplication* app, const std::string& param_prefix,
0054                   const level default_level = level::info) {
0055 
0056     // Logger. Get plugin level sub-log
0057     m_log = app->GetService<Log_service>()->logger(param_prefix, default_level);
0058   }
0059 
0060 public:
0061   std::shared_ptr<spdlog::logger>& logger() { return m_log; }
0062 
0063 protected: // FIXME change to private
0064   /// current logger
0065   std::shared_ptr<spdlog::logger> m_log;
0066 };
0067 } // namespace eicrecon