logging.cpp File Reference

Go to the source code of this file.

Classes

struct  LogPropagateOpts
struct  VerboseDef
struct  LoglevelDef
class  LoggingItem

Typedefs

typedef QMap< QString,
VerboseDef * > 
VerboseMap
typedef QMap< int, LoglevelDef * > LoglevelMap

Enumerations

enum  LoggingType {
  kMessage = 0x01, kRegistering = 0x02, kDeregistering = 0x04, kFlush = 0x08,
  kStandardIO = 0x10
}

Functions

void verboseAdd (uint64_t mask, QString name, bool additive, QString helptext)
 Add a verbose level to the verboseMap.
void loglevelAdd (int value, QString name, char shortname)
 Add a log level to the logLevelMap.
void verboseInit (void)
 Initialize the logging levels and verbose levels.
void verboseHelp (void)
 Outputs the Verbose levels and their descriptions (for --verbose help).
void LogTimeStamp (struct tm *tm, uint32_t *usec)
 Fill in the time structure from the current time to make a timestamp for the log message.
char * getThreadName (LoggingItem *item)
 Get the name of the thread that produced the LoggingItem.
int64_t getThreadTid (LoggingItem *item)
 Get the thread ID of the thread that produced the LoggingItem.
void setThreadTid (LoggingItem *item)
 Set the thread ID of the thread that produced the LoggingItem.
static LoggingItemcreateItem (const char *_file, const char *_function, int _line, LogLevel_t _level, int _type)
 Create a new LoggingItem.
static void deleteItem (LoggingItem *item)
 Delete the LoggingItem once its reference count has run down.
void logSighup (int signum, siginfo_t *info, void *secret)
 SIGHUP handler - reopen all open logfiles for logrollers.
void LogPrintLine (uint64_t mask, LogLevel_t level, const char *file, int line, const char *function, int fromQString, const char *format,...)
 Format and send a log message into the queue.
void logPropagateCalc (void)
 Generate the logPropagateArgs global with the latest logging level, mask, etc to propagate to all of the mythtv programs spawned from this one.
bool logPropagateQuiet (void)
 Check if we are propagating a "--quiet".
void logStart (QString logfile, int progress, int quiet, int facility, LogLevel_t level, bool dblog, bool propagate)
 Entry point to start logging for the application.
void logStop (void)
 Entry point for stopping logging for an application.
void loggingRegisterThread (const QString &name)
 Register the current thread with the given name.
void loggingDeregisterThread (void)
 Deregister the current thread's name.
int syslogGetFacility (QString facility)
 Map a syslog facility name back to the enumerated value.
LogLevel_t logLevelGet (QString level)
 Map a log level name back to the enumerated value.
QString logLevelGetName (LogLevel_t level)
 Map a log level enumerated value back to the name.
int verboseArgParse (QString arg)
 Parse the --verbose commandline argument and set the verbose level.
QString logStrerror (int errnum)
 Verbose helper function for ENO macro.

Variables

QMutex loggerListMutex
QList< LoggerBase * > loggerList
QMutex logQueueMutex
QQueue< LoggingItem * > logQueue
QRegExp logRegExp = QRegExp("[%]{1,2}")
QMutex logThreadMutex
QHash< uint64_t, char * > logThreadHash
QMutex logThreadTidMutex
QHash< uint64_t, int64_tlogThreadTidHash
LoggerThreadlogThread = NULL
bool logThreadFinished = false
bool debugRegistration = false
LogPropagateOpts logPropagateOpts
QString logPropagateArgs
LogLevel_t logLevel = (LogLevel_t)LOG_INFO
bool verboseInitialized = false
VerboseMap verboseMap
QMutex verboseMapMutex
LoglevelMap loglevelMap
QMutex loglevelMapMutex
const uint64_t verboseDefaultInt = VB_GENERAL
const char * verboseDefaultStr = " general"
uint64_t verboseMask = verboseDefaultInt
QString verboseString = QString(verboseDefaultStr)
uint64_t userDefaultValueInt = verboseDefaultInt
QString userDefaultValueStr = QString(verboseDefaultStr)
bool haveUserDefaultValues = false
static QList< LoggingItem * > item_recycler
static QAtomicInt item_count
static QAtomicInt malloc_count
static int max_count = 0
static QTime memory_time

Typedef Documentation

typedef QMap<QString, VerboseDef *> VerboseMap

Definition at line 94 of file logging.cpp.

typedef QMap<int, LoglevelDef *> LoglevelMap

Definition at line 101 of file logging.cpp.


Enumeration Type Documentation

Enumerator:
kMessage 
kRegistering 
kDeregistering 
kFlush 
kStandardIO 

Definition at line 136 of file logging.cpp.


Function Documentation

void verboseAdd ( uint64_t  mask,
QString  name,
bool  additive,
QString  helptext 
)

Add a verbose level to the verboseMap.

Done at initialization.

Parameters:
mask verbose mask (VB_*)
name name of the verbosity level
additive true if this is to be ORed with other masks. false if is will clear the other bits.
helptext Descriptive text for --verbose help output

Definition at line 1360 of file logging.cpp.

void loglevelAdd ( int  value,
QString  name,
char  shortname 
)

Add a log level to the logLevelMap.

Done at initialization.

Parameters:
value log level enumerated value (LOG_*) - matches syslog levels
name name of the log level
shortname one-letter short name for output into logs

Definition at line 1382 of file logging.cpp.

void verboseInit ( void   ) 

Initialize the logging levels and verbose levels.

Definition at line 1398 of file logging.cpp.

Referenced by logLevelGet(), logLevelGetName(), and verboseArgParse().

void verboseHelp ( void   ) 

Outputs the Verbose levels and their descriptions (for --verbose help).

Definition at line 1423 of file logging.cpp.

Referenced by verboseArgParse().

void LogTimeStamp ( struct tm *  tm,
uint32_t usec 
)

Fill in the time structure from the current time to make a timestamp for the log message.

This is run as part of the LOG() call.

Parameters:
tm pointer to the time structure to fill in
usec pointer to a 32bit unsigned int to return the number of us

Definition at line 1004 of file logging.cpp.

Referenced by LoggingItem::LoggingItem().

char * getThreadName ( LoggingItem item  ) 

Get the name of the thread that produced the LoggingItem.

Parameters:
item the LoggingItem in question
Returns:
C-string of the thread name

Definition at line 699 of file logging.cpp.

Referenced by SyslogLogger::logmsg(), FileLogger::logmsg(), and DatabaseLogger::logqmsg().

int64_t getThreadTid ( LoggingItem item  ) 

Get the thread ID of the thread that produced the LoggingItem.

Parameters:
item the LoggingItem in question
Returns:
Thread ID of the producing thread, cast to a 64-bit signed integer In different platforms, the actual value returned here will vary. The intention is to get a thread ID that will map well to what is shown in gdb.

Definition at line 729 of file logging.cpp.

Referenced by LoggerThread::handleItem(), FileLogger::logmsg(), and DatabaseLogger::logqmsg().

void setThreadTid ( LoggingItem item  ) 

Set the thread ID of the thread that produced the LoggingItem.

This code is actually run in the thread in question as part of the call to LOG()

Parameters:
item the LoggingItem in question In different platforms, the actual value returned here will vary. The intention is to get a thread ID that will map well to what is shown in gdb.

Definition at line 750 of file logging.cpp.

Referenced by LoggingItem::LoggingItem().

static LoggingItem * createItem ( const char *  _file,
const char *  _function,
int  _line,
LogLevel_t  _level,
int  _type 
) [static]

Create a new LoggingItem.

Parameters:
_file filename of the source file where the log message is from
_function source function where the log message is from
_line line number in the source where the log message is from
_level logging level of the message (LogLevel_t)
_type type of logging message
Returns:
LoggingItem that was created

Definition at line 956 of file logging.cpp.

Referenced by loggingDeregisterThread(), loggingRegisterThread(), and LogPrintLine().

static void deleteItem ( LoggingItem item  )  [static]

Delete the LoggingItem once its reference count has run down.

Parameters:
item LoggingItem to delete.

Definition at line 986 of file logging.cpp.

Referenced by FileLogger::logmsg(), LogPrintLine(), DatabaseLogger::logqmsg(), LoggerThread::run(), DBLoggerThread::run(), and DBLoggerThread::~DBLoggerThread().

void logSighup ( int  signum,
siginfo_t *  info,
void *  secret 
)

SIGHUP handler - reopen all open logfiles for logrollers.

Definition at line 1090 of file logging.cpp.

Referenced by logStart().

void LogPrintLine ( uint64_t  mask,
LogLevel_t  level,
const char *  file,
int  line,
const char *  function,
int  fromQString,
const char *  format,
  ... 
)

Format and send a log message into the queue.

This is called from the LOG() macro. The intention is minimal blocking of the caller.

Parameters:
mask Verbosity mask of the message (VB_*)
level Log level of this message (LOG_* - matching syslog levels)
file Filename of source code logging the message
line Line number within the source of log message source
function Function name of the log message source
fromQString true if this message originated from QString
format printf format string (when not from QString), log message (when from QString)
... printf arguments (when not from QString)

Definition at line 1038 of file logging.cpp.

void logPropagateCalc ( void   ) 

Generate the logPropagateArgs global with the latest logging level, mask, etc to propagate to all of the mythtv programs spawned from this one.

Definition at line 1108 of file logging.cpp.

Referenced by MainServer::HandleSetLogLevel(), MainServer::HandleSetVerbose(), and logStart().

bool logPropagateQuiet ( void   ) 

Check if we are propagating a "--quiet".

Returns:
true if --quiet is being propagated

Definition at line 1143 of file logging.cpp.

Referenced by BurnMenu::doBurn(), ImportNative::finishedPressed(), getFileDetails(), PreviewGenerator::Run(), and ExportNative::runScript().

void logStart ( QString  logfile,
int  progress,
int  quiet,
int  facility,
LogLevel_t  level,
bool  dblog,
bool  propagate 
)

Entry point to start logging for the application.

This will start up all of the threads needed.

Parameters:
logfile Filename of the logfile to create. Empty if no file.
progress non-zero if progress output will be sent to the console. This squelches all messages less important than LOG_ERR on the console
quiet quiet level requested (squelches all console output)
facility Syslog facility to use. -1 to disable syslog output
level Minimum logging level to put into the logs
dblog true if database logging is requested
propagate true if the logfile path needs to be propagated to child processes.

Definition at line 1160 of file logging.cpp.

Referenced by MythCommandLineParser::ConfigureLogging().

void logStop ( void   ) 

Entry point for stopping logging for an application.

Definition at line 1229 of file logging.cpp.

Referenced by MythContext::~MythContext(), and MythCoreContextPrivate::~MythCoreContextPrivate().

void loggingRegisterThread ( const QString &  name  ) 

Register the current thread with the given name.

This is triggered by the RunProlog() call in each thread.

Parameters:
name the name of the thread being registered. This is used for indicating the thread each log message is coming from.

Definition at line 1257 of file logging.cpp.

Referenced by MPoolThread::run(), and MThread::ThreadSetup().

void loggingDeregisterThread ( void   ) 

Deregister the current thread's name.

This is triggered by the RunEpilog() call in each thread.

Definition at line 1275 of file logging.cpp.

Referenced by MPoolThread::run(), MThread::ThreadCleanup(), and MythCoreContextPrivate::~MythCoreContextPrivate().

int syslogGetFacility ( QString  facility  ) 

Map a syslog facility name back to the enumerated value.

Parameters:
facility QString containing the facility name
Returns:
Syslog facility as enumerated type. Negative if not found.

Definition at line 1291 of file logging.cpp.

Referenced by MythCommandLineParser::GetSyslogFacility().

LogLevel_t logLevelGet ( QString  level  ) 

Map a log level name back to the enumerated value.

Parameters:
level QString containing the log level name
Returns:
Log level as enumerated type. LOG_UNKNOWN if not found.

Definition at line 1313 of file logging.cpp.

Referenced by MythCommandLineParser::GetLogLevel(), Myth::GetLogs(), and MainServer::HandleSetLogLevel().

QString logLevelGetName ( LogLevel_t  level  ) 

Map a log level enumerated value back to the name.

Parameters:
level Enumerated value of the log level
Returns:
Log level name. "unknown" if not found.

Definition at line 1337 of file logging.cpp.

Referenced by MythCommandLineParser::addLogging(), Myth::GetLogs(), MainServer::HandleSetLogLevel(), logPropagateCalc(), and logStart().

int verboseArgParse ( QString  arg  ) 

Parse the --verbose commandline argument and set the verbose level.

Parameters:
arg the commandline argument following "--verbose"
Returns:
an exit code. GENERIC_EXIT_OK if all is well.

Definition at line 1460 of file logging.cpp.

Referenced by MythCommandLineParser::ConfigureLogging(), MainServer::HandleSetVerbose(), and NetworkControl::processSet().

QString logStrerror ( int  errnum  ) 

Verbose helper function for ENO macro.

Parameters:
errnum system errno value
Returns:
QString containing the string version of the errno value, plus the errno value itself.

Definition at line 1570 of file logging.cpp.


Variable Documentation

QMutex logQueueMutex
QQueue<LoggingItem *> logQueue
QRegExp logRegExp = QRegExp("[%]{1,2}")

Definition at line 60 of file logging.cpp.

Referenced by LogPrintLine().

Definition at line 62 of file logging.cpp.

Referenced by getThreadName(), and LoggerThread::handleItem().

QHash<uint64_t, char *> logThreadHash

Definition at line 63 of file logging.cpp.

Referenced by getThreadName(), and LoggerThread::handleItem().

Definition at line 65 of file logging.cpp.

Referenced by getThreadTid(), LoggerThread::handleItem(), and setThreadTid().

Definition at line 66 of file logging.cpp.

Referenced by getThreadTid(), LoggerThread::handleItem(), and setThreadTid().

Definition at line 68 of file logging.cpp.

Definition at line 70 of file logging.cpp.

Referenced by LoggerThread::handleItem(), and LoggerThread::LoggerThread().

Definition at line 80 of file logging.cpp.

LogLevel_t logLevel = (LogLevel_t)LOG_INFO

Definition at line 103 of file logging.cpp.

Referenced by logLevelGet(), logLevelGetName(), verboseArgParse(), and verboseInit().

Definition at line 104 of file logging.cpp.

Referenced by verboseAdd(), verboseArgParse(), verboseHelp(), and verboseInit().

Definition at line 105 of file logging.cpp.

Referenced by verboseArgParse(), and verboseInit().

const uint64_t verboseDefaultInt = VB_GENERAL

Definition at line 110 of file logging.cpp.

Referenced by verboseArgParse().

const char* verboseDefaultStr = " general"

Definition at line 111 of file logging.cpp.

Referenced by verboseArgParse().

QString verboseString = QString(verboseDefaultStr)

Definition at line 116 of file logging.cpp.

Referenced by verboseArgParse().

Definition at line 117 of file logging.cpp.

Referenced by verboseArgParse().

Definition at line 118 of file logging.cpp.

Referenced by verboseArgParse().

QList<LoggingItem*> item_recycler [static]

Definition at line 939 of file logging.cpp.

QAtomicInt item_count [static]

Definition at line 940 of file logging.cpp.

Referenced by createItem(), and deleteItem().

QAtomicInt malloc_count [static]

Definition at line 941 of file logging.cpp.

Referenced by createItem().

int max_count = 0 [static]

Definition at line 945 of file logging.cpp.

Referenced by createItem(), and CardUtil::ProbeVideoDevices().

QTime memory_time [static]

Definition at line 946 of file logging.cpp.

Referenced by createItem().

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends
Generated on Mon May 28 06:41:48 2012 for MythTV by  doxygen 1.6.3