reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
resip::Log Class Reference

Singleton that handles logging calls. More...

#include <Log.hxx>

Classes

class  Guard
 Implementation for logging macros. More...
 
class  LocalLoggerMap
 Thread Local logger settings storage. More...
 
class  ThreadData
 
class  ThreadSetting
 

Public Types

enum  Type {
  Cout = 0 , Syslog , File , Cerr ,
  VSDebugWindow , OnlyExternal , OnlyExternalNoHeaders
}
 
enum  Level {
  None = -1 , Crit = LOG_CRIT , Err , Warning = LOG_WARNING ,
  Info = LOG_INFO , Debug = LOG_DEBUG , Stack = 8 , StdErr = 9 ,
  Bogus = 666
}
 
enum  MessageStructure { Unstructured = 0 , JSON_CEE }
 
typedef int LocalLoggerId
 Thread Local logger ID type.
 

Static Public Member Functions

static EncodeStream & tags (Log::Level level, const Subsystem &subsystem, const char *file, int line, const char *methodName, EncodeStream &strm, MessageStructure messageStructure)
 output the loglevel, hostname, appname, pid, tid, subsystem
 
static Data & timestamp (Data &result)
 
static Data timestamp ()
 
static ExternalLogger * getExternal ()
 
static Data getAppName ()
 
static int parseSyslogFacilityName (const Data &facilityName)
 
static void initialize (Type type, Level level, const Data &appName, const char *logFileName=0, ExternalLogger *externalLogger=0, const Data &syslogFacility="LOG_DAEMON", MessageStructure messageStructure=Unstructured, const Data &instanceName="")
 
static void initialize (const Data &type, const Data &level, const Data &appName, const char *logFileName=0, ExternalLogger *externalLogger=0, const Data &syslogFacility="LOG_DAEMON", const Data &messageStructure="Unstructured", const Data &instanceName="")
 
static void initialize (const char *type, const char *level, const char *appName, const char *logFileName=0, ExternalLogger *externalLogger=0, const char *syslogFacility="LOG_DAEMON", const char *messageStructure="Unstructured", const char *instanceName="")
 
static void initialize (Type type, Level level, const Data &appName, ExternalLogger &logger, const Data &syslogFacility="LOG_DAEMON", MessageStructure messageStructure=Unstructured, const Data &instanceName="")
 
static void initialize (const ConfigParse &configParse, const Data &appName, ExternalLogger *externalLogger=0)
 
static void setLevel (Level level)
 Set logging level for current thread.
 
static void setLevel (Level level, Subsystem &s)
 Set logging level for given subsystem.
 
static void setLevel (Level level, LocalLoggerId loggerId)
 Set logging level for given local logger.
 
static Level level ()
 Return logging level for current thread.
 
static Level level (LocalLoggerId loggerId)
 Return logging level for given local logger.
 
static LocalLoggerId id ()
 
static void setMaxLineCount (unsigned int maxLineCount)
 
static void setMaxLineCount (unsigned int maxLineCount, LocalLoggerId loggerId)
 
static void setMaxByteCount (unsigned int maxByteCount)
 
static void setMaxByteCount (unsigned int maxByteCount, LocalLoggerId loggerId)
 
static void setKeepAllLogFiles (bool keepAllLogFiles)
 
static void setKeepAllLogFiles (bool keepAllLogFiles, LocalLoggerId loggerId)
 
static Level toLevel (const Data &l)
 
static Type toType (const Data &t)
 
static Data toString (Level l)
 
static void setServiceLevel (int service, Level l)
 DEPRECATED! Left for backward compatibility - use localLoggers instead.
 
static Level getServiceLevel (int service)
 
static const ThreadSetting * getThreadSetting ()
 DEPRECATED! Left for backward compatibility - use localLoggers instead.
 
static void setThreadSetting (ThreadSetting info)
 
static void setThreadSetting (int serv, Level l)
 
static void setThreadSetting (int serv)
 
static LocalLoggerId localLoggerCreate (Type type, Level level, const char *logFileName=NULL, ExternalLogger *externalLogger=NULL, MessageStructure messageStructure=Unstructured)
 Create new logger instance and return its ID (zero on error)
 
static int localLoggerReinitialize (LocalLoggerId loggerId, Type type, Level level, const char *logFileName=NULL, ExternalLogger *externalLogger=NULL, MessageStructure messageStructure=Unstructured)
 Reinitialize all new setting for a local logger instance.
 
static int localLoggerRemove (LocalLoggerId loggerId)
 Destroy existing logger instance.
 
static int setThreadLocalLogger (LocalLoggerId loggerId)
 Set logger instance with given ID as a thread local logger.
 
static std::ostream & Instance (unsigned int bytesToWrite)
 
static bool isLogging (Log::Level level, const Subsystem &)
 
static void OutputToWin32DebugWindow (const Data &result)
 
static void reset ()
 Frees logger stream.
 
static void droppingPrivileges (uid_t uid, pid_t pid)
 

Protected Member Functions

friend void::freeLocalLogger (void *pThreadData)
 

Static Protected Member Functions

static ThreadData & getLoggerData ()
 

Static Protected Attributes

static Mutex _mutex
 
static std::atomic< unsigned int > touchCount {0}
 
static const Data delim
 
static unsigned int MaxLineCount = RESIP_LOG_MAX_LINE_COUNT_DEFAULT
 
static unsigned int MaxByteCount = RESIP_LOG_MAX_BYTE_COUNT_DEFAULT
 
static bool KeepAllLogFiles = false
 
static ThreadData mDefaultLoggerData
 Default logger settings.
 
static Data mAppName
 
static Data mHostname
 
static Data mFqdn
 
static int mSyslogFacility = LOG_DAEMON
 
static const char mDescriptions [][32] = {"NONE", "EMERG", "ALERT", "CRIT", "ERR", "WARNING", "NOTICE", "INFO", "DEBUG", "STACK", "CERR", ""}
 
static const char mCEEPri [][32] = { "", "CRIT", "CRIT", "CRIT", "ERROR", "WARN", "DEBUG", "DEBUG", "DEBUG", "DEBUG", "ERROR", ""}
 
static const int mSyslogPriority [] = { 0, LOG_CRIT, LOG_CRIT, LOG_CRIT, LOG_ERR, LOG_WARNING, LOG_NOTICE, LOG_INFO, LOG_DEBUG, LOG_DEBUG, LOG_ERR, 0 }
 
static Data mInstanceName
 
static LocalLoggerMap mLocalLoggerMap
 
static ThreadIf::TlsKey * mLocalLoggerKey
 
static HashMap< ThreadIf::Id, std::pair< ThreadSetting, bool > > mThreadToLevel
 DEPRECATED! Left for backward compatibility - use localLoggers instead.
 
static HashMap< int, std::set< ThreadIf::Id > > mServiceToThreads
 
static ThreadIf::TlsKey * mLevelKey
 
static HashMap< int, Level > mServiceToLevel
 DEPRECATED! Left for backward compatibility - use localLoggers instead.
 

Friends

class LogStaticInitializer
 

Detailed Description

Singleton that handles logging calls.

See also
Logger for usage details

Definition at line 50 of file Log.hxx.

Member Typedef Documentation

◆ LocalLoggerId

Thread Local logger ID type.

Definition at line 98 of file Log.hxx.

Member Enumeration Documentation

◆ Level

Enumerator
None 
Crit 
Err 
Warning 
Info 
Debug 
Stack 
StdErr 
Bogus 

Definition at line 65 of file Log.hxx.

◆ MessageStructure

Enumerator
Unstructured 
JSON_CEE 

Definition at line 91 of file Log.hxx.

◆ Type

Enumerator
Cout 
Syslog 
File 
Cerr 
VSDebugWindow 

Use only for Visual Studio Debug Window logging - WIN32 must be defined.

OnlyExternal 

log messages are only written to external logger

OnlyExternalNoHeaders 

same as OnlyExternal, only the messageWithHeaders param of the ExternalLogger will be empty.

This parameter usually contains a pre-formatted log entry.

Definition at line 53 of file Log.hxx.

Member Function Documentation

◆ droppingPrivileges()

void Log::droppingPrivileges ( uid_t  uid,
pid_t  pid 
)
static

Definition at line 964 of file Log.cxx.

◆ getAppName()

static Data resip::Log::getAppName ( )
inlinestatic

Definition at line 168 of file Log.hxx.

◆ getExternal()

static ExternalLogger * resip::Log::getExternal ( )
inlinestatic

Definition at line 164 of file Log.hxx.

◆ getLoggerData()

static ThreadData & resip::Log::getLoggerData ( )
inlinestaticprotected

Definition at line 374 of file Log.hxx.

◆ getServiceLevel()

Log::Level Log::getServiceLevel ( int  service)
static

dcm! – should perhaps throw an exception here, instead of setting a

Definition at line 808 of file Log.cxx.

◆ getThreadSetting()

const Log::ThreadSetting * Log::getThreadSetting ( )
static

DEPRECATED! Left for backward compatibility - use localLoggers instead.

Definition at line 823 of file Log.cxx.

◆ id()

static LocalLoggerId resip::Log::id ( )
inlinestatic

Definition at line 224 of file Log.hxx.

◆ initialize() [1/5]

void Log::initialize ( const char *  type,
const char *  level,
const char *  appName,
const char *  logFileName = 0,
ExternalLogger *  externalLogger = 0,
const char *  syslogFacility = "LOG_DAEMON",
const char *  messageStructure = "Unstructured",
const char *  instanceName = "" 
)
static

Definition at line 140 of file Log.cxx.

◆ initialize() [2/5]

void Log::initialize ( const ConfigParse &  configParse,
const Data &  appName,
ExternalLogger *  externalLogger = 0 
)
static

Definition at line 390 of file Log.cxx.

◆ initialize() [3/5]

void Log::initialize ( const Data &  type,
const Data &  level,
const Data &  appName,
const char *  logFileName = 0,
ExternalLogger *  externalLogger = 0,
const Data &  syslogFacility = "LOG_DAEMON",
const Data &  messageStructure = "Unstructured",
const Data &  instanceName = "" 
)
static

Definition at line 146 of file Log.cxx.

◆ initialize() [4/5]

void Log::initialize ( Type  type,
Level  level,
const Data &  appName,
const char *  logFileName = 0,
ExternalLogger *  externalLogger = 0,
const Data &  syslogFacility = "LOG_DAEMON",
MessageStructure  messageStructure = Unstructured,
const Data &  instanceName = "" 
)
static

Definition at line 268 of file Log.cxx.

◆ initialize() [5/5]

void Log::initialize ( Type  type,
Level  level,
const Data &  appName,
ExternalLogger &  logger,
const Data &  syslogFacility = "LOG_DAEMON",
MessageStructure  messageStructure = Unstructured,
const Data &  instanceName = "" 
)
static

Definition at line 378 of file Log.cxx.

◆ Instance()

std::ostream & Log::Instance ( unsigned int  bytesToWrite)
static

Definition at line 951 of file Log.cxx.

◆ isLogging()

bool Log::isLogging ( Log::Level  level,
const Subsystem &  sub 
)
static

Definition at line 971 of file Log.cxx.

◆ level() [1/2]

static Level resip::Log::level ( )
inlinestatic

Return logging level for current thread.

If thread has no local logger attached, then return global logging level.

Definition at line 221 of file Log.hxx.

◆ level() [2/2]

Log::Level Log::level ( Log::LocalLoggerId  loggerId)
static

Return logging level for given local logger.

Use 0 to set global logging level.

Definition at line 460 of file Log.cxx.

◆ localLoggerCreate()

Log::LocalLoggerId Log::localLoggerCreate ( Log::Type  type,
Log::Level  level,
const char *  logFileName = NULL,
ExternalLogger *  externalLogger = NULL,
MessageStructure  messageStructure = Unstructured 
)
static

Create new logger instance and return its ID (zero on error)

Definition at line 908 of file Log.cxx.

◆ localLoggerReinitialize()

int Log::localLoggerReinitialize ( Log::LocalLoggerId  loggerId,
Log::Type  type,
Log::Level  level,
const char *  logFileName = NULL,
ExternalLogger *  externalLogger = NULL,
MessageStructure  messageStructure = Unstructured 
)
static

Reinitialize all new setting for a local logger instance.

Return values
0on success
1if logger does not exist

Definition at line 917 of file Log.cxx.

◆ localLoggerRemove()

int Log::localLoggerRemove ( Log::LocalLoggerId  loggerId)
static

Destroy existing logger instance.

Return values
0on success
1if logger does not exist
2if logger is still in use
>2on other failures

Definition at line 927 of file Log.cxx.

◆ OutputToWin32DebugWindow()

void Log::OutputToWin32DebugWindow ( const Data &  result)
static

Definition at line 984 of file Log.cxx.

◆ parseSyslogFacilityName()

int Log::parseSyslogFacilityName ( const Data &  facilityName)
static

Definition at line 173 of file Log.cxx.

◆ reset()

void Log::reset ( )
static

Frees logger stream.

Definition at line 957 of file Log.cxx.

◆ setKeepAllLogFiles() [1/2]

void Log::setKeepAllLogFiles ( bool  keepAllLogFiles)
static

Definition at line 542 of file Log.cxx.

◆ setKeepAllLogFiles() [2/2]

void Log::setKeepAllLogFiles ( bool  keepAllLogFiles,
Log::LocalLoggerId  loggerId 
)
static

Definition at line 549 of file Log.cxx.

◆ setLevel() [1/3]

void Log::setLevel ( Level  level)
static

Set logging level for current thread.

If thread has no local logger attached, then set global logging level.

Definition at line 423 of file Log.cxx.

◆ setLevel() [2/3]

void Log::setLevel ( Level  level,
Log::LocalLoggerId  loggerId 
)
static

Set logging level for given local logger.

Use 0 to set global logging level.

Definition at line 437 of file Log.cxx.

◆ setLevel() [3/3]

void Log::setLevel ( Level  level,
Subsystem &  s 
)
static

Set logging level for given subsystem.

Definition at line 430 of file Log.cxx.

◆ setMaxByteCount() [1/2]

void Log::setMaxByteCount ( unsigned int  maxByteCount)
static

Definition at line 512 of file Log.cxx.

◆ setMaxByteCount() [2/2]

void Log::setMaxByteCount ( unsigned int  maxByteCount,
Log::LocalLoggerId  loggerId 
)
static

Definition at line 519 of file Log.cxx.

◆ setMaxLineCount() [1/2]

void Log::setMaxLineCount ( unsigned int  maxLineCount)
static

Definition at line 482 of file Log.cxx.

◆ setMaxLineCount() [2/2]

void Log::setMaxLineCount ( unsigned int  maxLineCount,
Log::LocalLoggerId  loggerId 
)
static

Definition at line 489 of file Log.cxx.

◆ setServiceLevel()

void Log::setServiceLevel ( int  service,
Level  l 
)
static

DEPRECATED! Left for backward compatibility - use localLoggers instead.

Definition at line 890 of file Log.cxx.

◆ setThreadLocalLogger()

int Log::setThreadLocalLogger ( Log::LocalLoggerId  loggerId)
static

Set logger instance with given ID as a thread local logger.

Pass zero loggerId to remove thread local logger.

Return values
0on success
1if logger does not exist
>1on other failures

Definition at line 932 of file Log.cxx.

◆ setThreadSetting() [1/3]

void Log::setThreadSetting ( int  serv)
static

Definition at line 854 of file Log.cxx.

◆ setThreadSetting() [2/3]

void Log::setThreadSetting ( int  serv,
Log::Level  l 
)
static

Definition at line 860 of file Log.cxx.

◆ setThreadSetting() [3/3]

void Log::setThreadSetting ( ThreadSetting  info)
static

Definition at line 866 of file Log.cxx.

◆ tags()

EncodeStream & Log::tags ( Log::Level  level,
const Subsystem &  subsystem,
const char *  file,
int  line,
const char *  methodName,
EncodeStream &  strm,
MessageStructure  messageStructure 
)
static

output the loglevel, hostname, appname, pid, tid, subsystem

Definition at line 620 of file Log.cxx.

◆ timestamp() [1/2]

Data Log::timestamp ( )
static

Definition at line 733 of file Log.cxx.

◆ timestamp() [2/2]

Data & Log::timestamp ( Data &  result)
static

Definition at line 741 of file Log.cxx.

◆ toLevel()

Log::Level Log::toLevel ( const Data &  l)
static

Definition at line 580 of file Log.cxx.

◆ toString()

Data Log::toString ( Level  l)
static

Definition at line 574 of file Log.cxx.

◆ toType()

Log::Type Log::toType ( const Data &  t)
static

Definition at line 599 of file Log.cxx.

◆ void::freeLocalLogger()

resip::Log::void::freeLocalLogger ( void *  pThreadData)
protected

Friends And Related Symbol Documentation

◆ LogStaticInitializer

friend class LogStaticInitializer
friend

Definition at line 431 of file Log.hxx.

Member Data Documentation

◆ _mutex

Mutex Log::_mutex
staticprotected

Definition at line 289 of file Log.hxx.

◆ delim

const Data Log::delim
staticprotected

Definition at line 291 of file Log.hxx.

◆ KeepAllLogFiles

bool Log::KeepAllLogFiles = false
staticprotected

Definition at line 295 of file Log.hxx.

◆ mAppName

Data Log::mAppName
staticprotected

Definition at line 365 of file Log.hxx.

◆ MaxByteCount

unsigned int Log::MaxByteCount = RESIP_LOG_MAX_BYTE_COUNT_DEFAULT
staticprotected

Definition at line 294 of file Log.hxx.

◆ MaxLineCount

unsigned int Log::MaxLineCount = RESIP_LOG_MAX_LINE_COUNT_DEFAULT
staticprotected

Definition at line 293 of file Log.hxx.

◆ mCEEPri

const char Log::mCEEPri = { "", "CRIT", "CRIT", "CRIT", "ERROR", "WARN", "DEBUG", "DEBUG", "DEBUG", "DEBUG", "ERROR", ""}
staticprotected

Definition at line 370 of file Log.hxx.

◆ mDefaultLoggerData

Log::ThreadData Log::mDefaultLoggerData
staticprotected

Default logger settings.

Definition at line 364 of file Log.hxx.

◆ mDescriptions

const char Log::mDescriptions = {"NONE", "EMERG", "ALERT", "CRIT", "ERR", "WARNING", "NOTICE", "INFO", "DEBUG", "STACK", "CERR", ""}
staticprotected

Definition at line 369 of file Log.hxx.

◆ mFqdn

Data Log::mFqdn
staticprotected

Definition at line 367 of file Log.hxx.

◆ mHostname

Data Log::mHostname
staticprotected

Definition at line 366 of file Log.hxx.

◆ mInstanceName

Data Log::mInstanceName
staticprotected

Definition at line 372 of file Log.hxx.

◆ mLevelKey

ThreadIf::TlsKey* resip::Log::mLevelKey
staticprotected

Definition at line 440 of file Log.hxx.

◆ mLocalLoggerKey

ThreadIf::TlsKey * Log::mLocalLoggerKey
staticprotected

Definition at line 433 of file Log.hxx.

◆ mLocalLoggerMap

Log::LocalLoggerMap Log::mLocalLoggerMap
staticprotected

Definition at line 432 of file Log.hxx.

◆ mServiceToLevel

HashMap< int, Log::Level > Log::mServiceToLevel
staticprotected

DEPRECATED! Left for backward compatibility - use localLoggers instead.

Definition at line 442 of file Log.hxx.

◆ mServiceToThreads

HashMap<int, std::set<ThreadIf::Id> > resip::Log::mServiceToThreads
staticprotected

Definition at line 439 of file Log.hxx.

◆ mSyslogFacility

int Log::mSyslogFacility = LOG_DAEMON
staticprotected

Definition at line 368 of file Log.hxx.

◆ mSyslogPriority

const int Log::mSyslogPriority = { 0, LOG_CRIT, LOG_CRIT, LOG_CRIT, LOG_ERR, LOG_WARNING, LOG_NOTICE, LOG_INFO, LOG_DEBUG, LOG_DEBUG, LOG_ERR, 0 }
staticprotected

Definition at line 371 of file Log.hxx.

◆ mThreadToLevel

HashMap<ThreadIf::Id, std::pair<ThreadSetting, bool> > resip::Log::mThreadToLevel
staticprotected

DEPRECATED! Left for backward compatibility - use localLoggers instead.

Definition at line 438 of file Log.hxx.

◆ touchCount

std::atomic< unsigned int > Log::touchCount {0}
staticprotected

Definition at line 290 of file Log.hxx.


The documentation for this class was generated from the following files: