CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
cond::persistency::Logger Class Reference

#include <Logger.h>

Public Member Functions

void end (int retCode)
 
std::iostream & log (const std::string &tag)
 
EchoedLogStream< edm::LogDebug_logDebug ()
 
EchoedLogStream< edm::LogErrorlogError ()
 
 Logger ()=delete
 
 Logger (const std::string &jobName)
 
EchoedLogStream< edm::LogInfologInfo ()
 
EchoedLogStream< edm::LogWarninglogWarning ()
 
void save ()
 
void saveOnDb ()
 
void saveOnFile ()
 
void setDbDestination (const std::string &connectionString)
 
void start ()
 
void subscribeCoralMessages (const std::weak_ptr< MsgDispatcher > &dispatcher)
 
virtual ~Logger ()
 

Private Member Functions

void clearBuffer ()
 

Private Attributes

std::string m_connectionString
 
std::weak_ptr< MsgDispatcherm_dispatcher
 
boost::posix_time::ptime m_endTime
 
std::string m_jobName
 
std::stringstream m_log
 
int m_retCode
 
bool m_started
 
boost::posix_time::ptime m_startTime
 

Detailed Description

Definition at line 85 of file Logger.h.

Constructor & Destructor Documentation

◆ Logger() [1/2]

cond::persistency::Logger::Logger ( )
delete

◆ Logger() [2/2]

Logger::Logger ( const std::string &  jobName)
explicit

Definition at line 48 of file Logger.cc.

49  : m_jobName(jobName),
51  m_started(false),
52  m_startTime(),
53  m_endTime(),
54  m_retCode(0),
55  m_log() {}
std::string m_connectionString
Definition: Logger.h:130
list jobName
Initialize all the variables.
boost::posix_time::ptime m_endTime
Definition: Logger.h:133
std::stringstream m_log
Definition: Logger.h:135
boost::posix_time::ptime m_startTime
Definition: Logger.h:132
std::string m_jobName
Definition: Logger.h:129

◆ ~Logger()

Logger::~Logger ( )
virtual

Definition at line 58 of file Logger.cc.

References m_dispatcher.

58  {
59  auto dispatcher = m_dispatcher.lock();
60  if (dispatcher.get())
61  dispatcher->unsubscribe();
62  }
std::weak_ptr< MsgDispatcher > m_dispatcher
Definition: Logger.h:136

Member Function Documentation

◆ clearBuffer()

void Logger::clearBuffer ( )
private

Definition at line 43 of file Logger.cc.

References m_log.

Referenced by end(), and start().

43  {
44  m_log.str("");
45  m_log.clear();
46  }
std::stringstream m_log
Definition: Logger.h:135

◆ end()

void Logger::end ( int  retCode)

Definition at line 80 of file Logger.cc.

References clearBuffer(), log(), m_endTime, m_retCode, m_started, and save().

Referenced by Types.LuminosityBlockRange::cppID(), Types.EventRange::cppID(), FakeBeamMonitor::endLuminosityBlock(), and BeamMonitor::endLuminosityBlock().

80  {
81  if (m_started) {
82  m_endTime = boost::posix_time::microsec_clock::universal_time();
83  m_started = false;
84  m_retCode = retCode;
85  log("END_JOB") << ": return code:" << retCode;
86  save();
87  clearBuffer();
88  }
89  }
boost::posix_time::ptime m_endTime
Definition: Logger.h:133
std::iostream & log(const std::string &tag)
Definition: Logger.cc:150

◆ log()

std::iostream & Logger::log ( const std::string &  tag)

◆ logDebug()

EchoedLogStream< edm::LogDebug_ > Logger::logDebug ( )

Definition at line 161 of file Logger.cc.

References log(), m_jobName, and m_log.

Referenced by reportToRecipient().

161  {
162  log("DEBUG");
163  return EchoedLogStream<edm::LogDebug_>(m_jobName, m_log);
164  }
std::stringstream m_log
Definition: Logger.h:135
std::iostream & log(const std::string &tag)
Definition: Logger.cc:150
std::string m_jobName
Definition: Logger.h:129

◆ logError()

EchoedLogStream< edm::LogError > Logger::logError ( )

Definition at line 165 of file Logger.cc.

References log(), m_jobName, and m_log.

Referenced by FakeBeamMonitor::FitAndFill(), BeamMonitor::FitAndFill(), reportToRecipient(), and saveOnDb().

165  {
166  log("ERROR");
167  return EchoedLogStream<edm::LogError>(m_jobName, m_log);
168  }
std::stringstream m_log
Definition: Logger.h:135
std::iostream & log(const std::string &tag)
Definition: Logger.cc:150
std::string m_jobName
Definition: Logger.h:129

◆ logInfo()

EchoedLogStream< edm::LogInfo > Logger::logInfo ( )

◆ logWarning()

EchoedLogStream< edm::LogWarning > Logger::logWarning ( )

Definition at line 169 of file Logger.cc.

References log(), m_jobName, and m_log.

Referenced by reportToRecipient(), and cond::service::OnlineDBOutputService::writeIOVForNextLumisection().

169  {
170  log("WARNING");
171  return EchoedLogStream<edm::LogWarning>(m_jobName, m_log);
172  }
std::stringstream m_log
Definition: Logger.h:135
std::iostream & log(const std::string &tag)
Definition: Logger.cc:150
std::string m_jobName
Definition: Logger.h:129

◆ save()

void Logger::save ( )

Definition at line 143 of file Logger.cc.

References m_connectionString, saveOnDb(), and saveOnFile().

Referenced by end(), and SpecificationBuilder_cfi.Specification::saveAll().

143  {
144  if (!m_connectionString.empty())
145  saveOnDb();
146  else
147  saveOnFile();
148  }
std::string m_connectionString
Definition: Logger.h:130

◆ saveOnDb()

void Logger::saveOnDb ( )

Definition at line 120 of file Logger.cc.

References cond::auth::COND_WRITER_ROLE, MillePedeFileConverter_cfg::e, cppFunctionSkipper::exception, cond::persistency::O2O_RUN::Table::insert(), logError(), m_connectionString, m_endTime, m_jobName, m_log, m_retCode, m_startTime, saveOnFile(), AlCaHLTBitMon_QueryRunRegistry::string, and cond::persistency::throwException().

Referenced by save().

120  {
121  if (!m_log.str().empty()) {
122  if (m_connectionString.empty()) {
123  throwException("Connection string for destination database has not been provided.", "Logger::saveOnDb");
124  }
125  coral::ConnectionService connServ;
126  std::unique_ptr<coral::ISessionProxy> coralSession(
127  connServ.connect(m_connectionString, auth::COND_WRITER_ROLE, coral::Update));
128  coralSession->transaction().start(false);
129  try {
130  O2O_RUN::Table destinationTable(coralSession->nominalSchema());
131  destinationTable.insert(m_jobName, m_startTime, m_endTime, m_retCode, m_log.str());
132  coralSession->transaction().commit();
133  } catch (const std::exception& e) {
134  coralSession->transaction().rollback();
135  // dump on file on this circumstance...
136  logError() << e.what();
137  saveOnFile();
138  throwException(std::string("Failure while saving log on database:") + e.what(), "Logger::saveOnDb");
139  }
140  }
141  }
std::string m_connectionString
Definition: Logger.h:130
EchoedLogStream< edm::LogError > logError()
Definition: Logger.cc:165
boost::posix_time::ptime m_endTime
Definition: Logger.h:133
std::stringstream m_log
Definition: Logger.h:135
boost::posix_time::ptime m_startTime
Definition: Logger.h:132
std::string m_jobName
Definition: Logger.h:129
static constexpr const char *const COND_WRITER_ROLE
Definition: Auth.h:17
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:12

◆ saveOnFile()

void Logger::saveOnFile ( )

Definition at line 110 of file Logger.cc.

References MillePedeFileConverter_cfg::fileName, groupFilesInBlocks::fout, cond::persistency::get_timestamp_for_filename(), m_log, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by save(), and saveOnDb().

110  {
111  if (!m_log.str().empty()) {
113  std::ofstream fout(fileName, std::ofstream::app);
114  fout << m_log.str() << std::endl;
115  fout.close();
116  }
117  }
std::stringstream m_log
Definition: Logger.h:135
std::string get_timestamp_for_filename()
Definition: Logger.cc:104

◆ setDbDestination()

void Logger::setDbDestination ( const std::string &  connectionString)

◆ start()

void Logger::start ( )

Definition at line 69 of file Logger.cc.

References clearBuffer(), log(), m_jobName, m_log, m_started, and m_startTime.

Referenced by progressbar.ProgressBar::__next__(), FakeBeamMonitor::beginLuminosityBlock(), BeamMonitor::beginLuminosityBlock(), Types.LuminosityBlockRange::cppID(), and Types.EventRange::cppID().

69  {
70  if (!m_started) {
71  if (!m_log.str().empty())
72  clearBuffer();
73  m_startTime = boost::posix_time::microsec_clock::universal_time();
74  m_started = true;
75  log("START_JOB") << " " << m_jobName;
76  }
77  }
std::stringstream m_log
Definition: Logger.h:135
boost::posix_time::ptime m_startTime
Definition: Logger.h:132
std::iostream & log(const std::string &tag)
Definition: Logger.cc:150
std::string m_jobName
Definition: Logger.h:129

◆ subscribeCoralMessages()

void Logger::subscribeCoralMessages ( const std::weak_ptr< MsgDispatcher > &  dispatcher)

Definition at line 64 of file Logger.cc.

References m_dispatcher.

64 { m_dispatcher = dispatcher; }
std::weak_ptr< MsgDispatcher > m_dispatcher
Definition: Logger.h:136

Member Data Documentation

◆ m_connectionString

std::string cond::persistency::Logger::m_connectionString
private

Definition at line 130 of file Logger.h.

Referenced by save(), saveOnDb(), and setDbDestination().

◆ m_dispatcher

std::weak_ptr<MsgDispatcher> cond::persistency::Logger::m_dispatcher
private

Definition at line 136 of file Logger.h.

Referenced by subscribeCoralMessages(), and ~Logger().

◆ m_endTime

boost::posix_time::ptime cond::persistency::Logger::m_endTime
private

Definition at line 133 of file Logger.h.

Referenced by end(), and saveOnDb().

◆ m_jobName

std::string cond::persistency::Logger::m_jobName
private

Definition at line 129 of file Logger.h.

Referenced by logDebug(), logError(), logInfo(), logWarning(), saveOnDb(), and start().

◆ m_log

std::stringstream cond::persistency::Logger::m_log
private

Definition at line 135 of file Logger.h.

Referenced by clearBuffer(), log(), logDebug(), logError(), logInfo(), logWarning(), saveOnDb(), saveOnFile(), and start().

◆ m_retCode

int cond::persistency::Logger::m_retCode
private

Definition at line 134 of file Logger.h.

Referenced by end(), and saveOnDb().

◆ m_started

bool cond::persistency::Logger::m_started
private

Definition at line 131 of file Logger.h.

Referenced by end(), and start().

◆ m_startTime

boost::posix_time::ptime cond::persistency::Logger::m_startTime
private

Definition at line 132 of file Logger.h.

Referenced by saveOnDb(), and start().