API
MagAOX::logger::logManager< _parentT, _logFileT > Struct Template Reference

The standard MagAOX log manager, used for both process logs and telemetry streams. More...

#include <logManager.hpp>

Inheritance diagram for MagAOX::logger::logManager< _parentT, _logFileT >:
Inheritance graph
Collaboration diagram for MagAOX::logger::logManager< _parentT, _logFileT >:
Collaboration graph

Public Types

typedef _parentT parentT
 
typedef _logFileT logFileT
 

Public Member Functions

 logManager ()
 Default c'tor. More...
 
 ~logManager ()
 Destructor. More...
 
void parent (parentT *p)
 Set the logger parent. More...
 
parentTparent ()
 Get the logger parent. More...
 
int writePause (const unsigned long &wp)
 Set a new value of writePause. More...
 
unsigned long writePause ()
 Get the current value of writePause. More...
 
int logLevel (logPrioT newLev)
 Set a new value of logLevel. More...
 
logPrioT logLevel ()
 Get the current value of logLevel. More...
 
int logThreadPrio (int newPrio)
 Set a new value of logThreadPrio. More...
 
int logThreadPrio ()
 Get the current value of logThreadPrio. More...
 
bool logThreadRunning ()
 Get status of the log thread running flag. More...
 
int setupConfig (mx::app::appConfigurator &config)
 Setup an application configurator for the logger section. More...
 
int loadConfig (mx::app::appConfigurator &config)
 Load the logger section from an application configurator. More...
 
int logThreadStart ()
 Start the logger thread. More...
 
void logThreadExec ()
 Execute the logger thread. More...
 
template<typename logT >
void log (const typename logT::messageT &msg, logPrioT level=logPrio::LOG_DEFAULT)
 Make a log entry, including a message. More...
 
template<typename logT >
void log (timespecX &ts, const typename logT::messageT &msg, logPrioT level=logPrio::LOG_DEFAULT)
 Make a log entry, including a message. More...
 
template<typename logT >
void log (logPrioT level=logPrio::LOG_DEFAULT)
 Make a log entry with no message. More...
 
template<typename logT >
void log (timespecX &ts, logPrioT level=logPrio::LOG_DEFAULT)
 Make a log entry with no message. More...
 

Static Public Member Functions

static void _logThreadStart (logManager *l)
 Thread starter, called by logThreadStart on thread construction. Calls logThreadExec. More...
 
template<typename logT >
static int createLog (bufferPtrT &logBuffer, const typename logT::messageT &msg, const logPrioT &level)
 Create a log formatted log entry, filling in a buffer. More...
 
template<typename logT >
static int createLog (bufferPtrT &logBuffer, const timespecX &ts, const typename logT::messageT &msg, const logPrioT &level)
 Create a log formatted log entry, filling in a buffer. More...
 

Public Attributes

std::string m_configSection {"logger"}
 The configuration files section name. Default is logger. More...
 
logPrioT m_logLevel {logPrio::LOG_INFO}
 The minimum log level to actually record. Logs with level below this are rejected. Default is INFO. Configure with logger.logLevel. More...
 

Protected Attributes

parentTm_parent {nullptr}
 
std::list< bufferPtrTm_logQueue
 Log entries are stored here, and writen to the file by the log thread. More...
 
std::thread m_logThread
 A separate thread for actually writing to the file. More...
 
std::mutex m_qMutex
 Mutex for accessing the m_logQueue. More...
 
bool m_logShutdown {false}
 Flag to signal the log thread to shutdown. More...
 
unsigned long m_writePause {MAGAOX_default_writePause}
 Time, in nanoseconds, to pause between successive batch writes to the file. Default is 1e9. Configure with logger.writePause. More...
 
int m_logThreadPrio {0}
 
bool m_logThreadRunning {false}
 

Detailed Description

template<class _parentT, class _logFileT>
struct MagAOX::logger::logManager< _parentT, _logFileT >

The standard MagAOX log manager, used for both process logs and telemetry streams.

Manages the formatting and queueing of the log entries.

A log entry is made using one of the standard log types. These are formatted into a binary stream and stored in a std::list. This occurs in the calling thread. The insertion into the list is mutex-ed, so it is safe to make logs from different threads concurrently.

Write-to-disk occurs in a separate thread, which is normally set to the lowest priority so as not to interfere with higher-priority tasks. The log thread cycles through pending log entries in the list, dispatching them to the logFile.

The template parameter logFileT is one of the logFile types, which is used to actually write to disk.

Example:

logManager<logFileRaw> log;
log.m_logThreadStart();
//do stuff
log<loop_closed>(); //An empty log, which is used to log discrete events.
//more stuff happens
log<text_log>("a log entry with a std::string message type");
void log(const typename logT::messageT &msg, logPrioT level=logPrio::LOG_DEFAULT)
Make a log entry, including a message.
Definition: logManager.hpp:527
Todo:
document all the requirements of logFileT
Template Parameters
logFileTa logFile type with a writeLog method.

Definition at line 73 of file logManager.hpp.

Member Typedef Documentation

◆ logFileT

template<class _parentT , class _logFileT >
typedef _logFileT MagAOX::logger::logManager< _parentT, _logFileT >::logFileT

Definition at line 76 of file logManager.hpp.

◆ parentT

template<class _parentT , class _logFileT >
typedef _parentT MagAOX::logger::logManager< _parentT, _logFileT >::parentT

Definition at line 75 of file logManager.hpp.

Constructor & Destructor Documentation

◆ logManager()

template<class parentT , class logFileT >
MagAOX::logger::logManager< parentT, logFileT >::logManager

Default c'tor.

Definition at line 254 of file logManager.hpp.

◆ ~logManager()

template<class parentT , class logFileT >
MagAOX::logger::logManager< parentT, logFileT >::~logManager

Destructor.

Definition at line 259 of file logManager.hpp.

Member Function Documentation

◆ _logThreadStart()

template<class parentT , class logFileT >
void MagAOX::logger::logManager< parentT, logFileT >::_logThreadStart ( logManager< _parentT, _logFileT > *  l)
static

Thread starter, called by logThreadStart on thread construction. Calls logThreadExec.

Parameters
[in]la pointer to a logger instance (normally this)

Definition at line 392 of file logManager.hpp.

◆ createLog() [1/2]

template<class parentT , class logFileT >
template<typename logT >
int MagAOX::logger::logManager< parentT, logFileT >::createLog ( bufferPtrT logBuffer,
const timespecX ts,
const typename logT::messageT &  msg,
const logPrioT level 
)
static

Create a log formatted log entry, filling in a buffer.

This version has the timestamp provided.

Template Parameters
logTis a log entry type
Returns
0 on success, -1 on error.
Parameters
[out]logBuffera shared_ptr<logBuffer>, which will be allocated and populated with the log entry
[in]tsthe timestamp of this log entry.
[in]msgthe message to log (could be of type emptyMessage)
[in]levelthe level (verbosity) of this log

Definition at line 516 of file logManager.hpp.

◆ createLog() [2/2]

template<class parentT , class logFileT >
template<typename logT >
int MagAOX::logger::logManager< parentT, logFileT >::createLog ( bufferPtrT logBuffer,
const typename logT::messageT &  msg,
const logPrioT level 
)
static

Create a log formatted log entry, filling in a buffer.

This is where the timestamp of the log entry is set.

Template Parameters
logTis a log entry type
Returns
0 on success, -1 on error.
Parameters
[out]logBuffera shared_ptr<logBuffer>, which will be allocated and populated with the log entry
[in]msgthe message to log (could be of type emptyMessage)
[in]levelthe level (verbosity) of this log

Definition at line 502 of file logManager.hpp.

◆ loadConfig()

template<class parentT , class logFileT >
int MagAOX::logger::logManager< parentT, logFileT >::loadConfig ( mx::app::appConfigurator &  config)

Load the logger section from an application configurator.

Parameters
[in]configan application configuration from which to load values

Definition at line 350 of file logManager.hpp.

◆ log() [1/4]

◆ log() [2/4]

◆ log() [3/4]

◆ log() [4/4]

◆ logLevel() [1/2]

template<class parentT , class logFileT >
logPrioT MagAOX::logger::logManager< parentT, logFileT >::logLevel

Get the current value of logLevel.

Returns
the value m_logLevel

Definition at line 309 of file logManager.hpp.

◆ logLevel() [2/2]

template<class parentT , class logFileT >
int MagAOX::logger::logManager< parentT, logFileT >::logLevel ( logPrioT  newLev)

Set a new value of logLevel.

Updates m_logLevel with new value. Will return an error and take no actions if the argument is outside the range of the logLevels enum.

Returns
0 on success
-1 on error.
Parameters
[in]newLevthe new value of logLevel

Definition at line 299 of file logManager.hpp.

Referenced by MagAOX::app::sshDigger::execTunnel(), and MagAOX::app::xindiserver::forkIndiserver().

◆ logThreadExec()

template<class parentT , class logFileT >
void MagAOX::logger::logManager< parentT, logFileT >::logThreadExec

Execute the logger thread.

Todo:
must check this for errors, and investigate how fsyncgate impacts us

Definition at line 438 of file logManager.hpp.

Referenced by MagAOX::logger::logManager< _parentT, _logFileT >::_logThreadStart().

◆ logThreadPrio() [1/2]

template<class parentT , class logFileT >
int MagAOX::logger::logManager< parentT, logFileT >::logThreadPrio

Get the current value of logThreadPrio.

Returns
the value m_logThreadPrio

Definition at line 325 of file logManager.hpp.

◆ logThreadPrio() [2/2]

template<class parentT , class logFileT >
int MagAOX::logger::logManager< parentT, logFileT >::logThreadPrio ( int  newPrio)

Set a new value of logThreadPrio.

Updates m_logThreadPrio with new value. If the argument is < 0, this sets m_logThreadPrio to 0. Will not set > 98, and returns -1 with no changes in this case.

Returns
0 on success
-1 on error (> 98).
Parameters
[in]newPriothe new value of logThreadPrio

Definition at line 315 of file logManager.hpp.

◆ logThreadRunning()

template<class parentT , class logFileT >
bool MagAOX::logger::logManager< parentT, logFileT >::logThreadRunning

Get status of the log thread running flag.

Returns
the current value of m_logThreadRunning

Definition at line 331 of file logManager.hpp.

◆ logThreadStart()

template<class parentT , class logFileT >
int MagAOX::logger::logManager< parentT, logFileT >::logThreadStart

Start the logger thread.

Definition at line 398 of file logManager.hpp.

◆ parent() [1/2]

template<class parentT , class logFileT >
parentT * MagAOX::logger::logManager< parentT, logFileT >::parent

Get the logger parent.

Returns a point to the parent object.

Definition at line 277 of file logManager.hpp.

◆ parent() [2/2]

template<class parentT , class logFileT >
void MagAOX::logger::logManager< parentT, logFileT >::parent ( parentT p)

Set the logger parent.

The parent is used for interactive presentation of log messages

Parameters
[in]ppointer to the parent object

Definition at line 271 of file logManager.hpp.

◆ setupConfig()

template<class parentT , class logFileT >
int MagAOX::logger::logManager< parentT, logFileT >::setupConfig ( mx::app::appConfigurator &  config)

Setup an application configurator for the logger section.

Parameters
[in]configan application configuration to setup

Definition at line 337 of file logManager.hpp.

◆ writePause() [1/2]

template<class parentT , class logFileT >
unsigned long MagAOX::logger::logManager< parentT, logFileT >::writePause

Get the current value of writePause.

Returns
the value m_writePause.

Definition at line 293 of file logManager.hpp.

◆ writePause() [2/2]

template<class parentT , class logFileT >
int MagAOX::logger::logManager< parentT, logFileT >::writePause ( const unsigned long &  wp)

Set a new value of writePause.

Updates m_writePause with new value.

Returns
0 on success
-1 on error (if wp == 0).
Parameters
[in]wpthe new value of writePause

Definition at line 283 of file logManager.hpp.

Member Data Documentation

◆ m_configSection

template<class _parentT , class _logFileT >
std::string MagAOX::logger::logManager< _parentT, _logFileT >::m_configSection {"logger"}

The configuration files section name. Default is logger.

Todo:
Make these protected members, with appropriate access methods

Definition at line 84 of file logManager.hpp.

◆ m_logLevel

template<class _parentT , class _logFileT >
logPrioT MagAOX::logger::logManager< _parentT, _logFileT >::m_logLevel {logPrio::LOG_INFO}

The minimum log level to actually record. Logs with level below this are rejected. Default is INFO. Configure with logger.logLevel.

Definition at line 97 of file logManager.hpp.

◆ m_logQueue

template<class _parentT , class _logFileT >
std::list<bufferPtrT> MagAOX::logger::logManager< _parentT, _logFileT >::m_logQueue
protected

Log entries are stored here, and writen to the file by the log thread.

Definition at line 87 of file logManager.hpp.

◆ m_logShutdown

template<class _parentT , class _logFileT >
bool MagAOX::logger::logManager< _parentT, _logFileT >::m_logShutdown {false}
protected

Flag to signal the log thread to shutdown.

Definition at line 92 of file logManager.hpp.

◆ m_logThread

template<class _parentT , class _logFileT >
std::thread MagAOX::logger::logManager< _parentT, _logFileT >::m_logThread
protected

A separate thread for actually writing to the file.

Definition at line 89 of file logManager.hpp.

◆ m_logThreadPrio

template<class _parentT , class _logFileT >
int MagAOX::logger::logManager< _parentT, _logFileT >::m_logThreadPrio {0}
protected

Definition at line 100 of file logManager.hpp.

◆ m_logThreadRunning

template<class _parentT , class _logFileT >
bool MagAOX::logger::logManager< _parentT, _logFileT >::m_logThreadRunning {false}
protected

Definition at line 102 of file logManager.hpp.

◆ m_parent

template<class _parentT , class _logFileT >
parentT* MagAOX::logger::logManager< _parentT, _logFileT >::m_parent {nullptr}
protected

Definition at line 79 of file logManager.hpp.

◆ m_qMutex

template<class _parentT , class _logFileT >
std::mutex MagAOX::logger::logManager< _parentT, _logFileT >::m_qMutex
protected

Mutex for accessing the m_logQueue.

Definition at line 90 of file logManager.hpp.

◆ m_writePause

template<class _parentT , class _logFileT >
unsigned long MagAOX::logger::logManager< _parentT, _logFileT >::m_writePause {MAGAOX_default_writePause}
protected

Time, in nanoseconds, to pause between successive batch writes to the file. Default is 1e9. Configure with logger.writePause.

Definition at line 94 of file logManager.hpp.


The documentation for this struct was generated from the following file: