Skip to content

Commit

Permalink
Cleanup use of LogPrintLine to use const
Browse files Browse the repository at this point in the history
So the C part will compile with no warnings (as in the kerneldeint filter),
the message format must be const char *.  Adjusted to this, and also for
filename and function.  Fixed the variadic preprocessor part to use
 ##__VA_ARGS__ so if no extra args are there, it will swallow the preceeding
comma as well.  This meant LogPrintLineNoArg could be gotten rid of.
  • Loading branch information
Beirdo committed May 29, 2011
1 parent 4a7e83c commit 0f50c51
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 51 deletions.
53 changes: 19 additions & 34 deletions mythtv/libs/libmythbase/mythlogging.cpp
Expand Up @@ -93,7 +93,7 @@ FileLogger::FileLogger(char *filename) : LoggerBase(filename, 0),
{
m_opened = true;
m_fd = 1;
LogPrintNoArg( VB_IMPORTANT, LOG_INFO, "Added logging to the console" );
LogPrint( VB_IMPORTANT, LOG_INFO, "Added logging to the console" );
}
else
{
Expand All @@ -114,8 +114,8 @@ FileLogger::~FileLogger()
close( m_fd );
}
else
LogPrintNoArg( VB_IMPORTANT, LOG_INFO,
"Removed logging to the console" );
LogPrint( VB_IMPORTANT, LOG_INFO,
"Removed logging to the console" );
}
}

Expand Down Expand Up @@ -192,7 +192,7 @@ SyslogLogger::SyslogLogger(int facility) : LoggerBase(NULL, facility),

SyslogLogger::~SyslogLogger()
{
LogPrintNoArg(VB_IMPORTANT, LOG_INFO, "Removing syslogging");
LogPrint(VB_IMPORTANT, LOG_INFO, "Removing syslogging");
free(m_application);
closelog();
}
Expand Down Expand Up @@ -244,7 +244,7 @@ DatabaseLogger::DatabaseLogger(char *table) : LoggerBase(table, 0),

DatabaseLogger::~DatabaseLogger()
{
LogPrintNoArg(VB_IMPORTANT, LOG_INFO, "Removing database logging");
LogPrint(VB_IMPORTANT, LOG_INFO, "Removing database logging");

if( m_thread )
{
Expand Down Expand Up @@ -519,27 +519,11 @@ void LogTimeStamp( time_t *epoch, uint32_t *usec )
#endif
}

void LogPrintLine( uint32_t mask, LogLevel_t level, char *file, int line,
char *function, char *format, ... )
void LogPrintLine( uint32_t mask, LogLevel_t level, const char *file, int line,
const char *function, const char *format, ... )
{
va_list arguments;
char *message;

message = (char *)malloc(LOGLINE_MAX+1);
if( !message )
return;

va_start(arguments, format);
vsnprintf(message, LOGLINE_MAX, format, arguments);
va_end(arguments);

LogPrintLineNoArg( mask, level, file, line, function, message );
free( message );
}

void LogPrintLineNoArg( uint32_t mask, LogLevel_t level, char *file, int line,
char *function, char *message )
{
LoggingItem_t *item;
time_t epoch;
uint32_t usec;
Expand All @@ -556,23 +540,25 @@ void LogPrintLineNoArg( uint32_t mask, LogLevel_t level, char *file, int line,

memset( item, 0, sizeof(LoggingItem_t) );

message = (char *)malloc(LOGLINE_MAX+1);
if( !message )
return;

va_start(arguments, format);
vsnprintf(message, LOGLINE_MAX, format, arguments);
va_end(arguments);

LogTimeStamp( &epoch, &usec );

localtime_r(&epoch, &item->tm);
item->usec = usec;
item->usec = usec;

item->level = level;
item->file = file;
item->line = line;
item->function = function;
item->threadId = (uint64_t)QThread::currentThreadId();

item->message = strdup(message);
if( !item->message )
{
delete item;
return;
}
item->message = message;

QMutexLocker qLock(&logQueueMutex);
logQueue.enqueue(item);
Expand All @@ -594,9 +580,8 @@ void logStart(QString logfile, int quiet, int facility, bool dblog)

/* Syslog */
if( facility < 0 )
LogPrintNoArg(VB_IMPORTANT, LOG_CRIT,
"Syslogging facility unknown, disabling syslog "
"output");
LogPrint(VB_IMPORTANT, LOG_CRIT,
"Syslogging facility unknown, disabling syslog output");
else if( facility > 0 )
logger = new SyslogLogger(facility);

Expand Down
27 changes: 10 additions & 17 deletions mythtv/libs/libmythbase/mythlogging.h
Expand Up @@ -49,9 +49,9 @@ typedef struct
{
LogLevel_t level;
uint64_t threadId;
char *file;
const char *file;
int line;
char *function;
const char *function;
struct tm tm;
uint32_t usec;
char *message;
Expand All @@ -67,25 +67,18 @@ typedef struct
extern "C" {
#endif

#define LogPrintQString(mask, level, ...) \
LogPrintLineNoArg(mask, (LogLevel_t)level, (char *)__FILE__, __LINE__, \
(char *)__FUNCTION__, \
(char *)QString(__VA_ARGS__).toLocal8Bit().constData())
#define LogPrintQString(mask, level, string) \
LogPrintLine(mask, (LogLevel_t)level, __FILE__, __LINE__, __FUNCTION__, \
QString(string).toLocal8Bit().constData())

#define LogPrint(mask, level, format, ...) \
LogPrintLine(mask, (LogLevel_t)level, (char *)__FILE__, __LINE__, \
(char *)__FUNCTION__, (char *)format, ## __VA_ARGS__)

#define LogPrintNoArg(mask, level, string) \
LogPrintLineNoArg(mask, (LogLevel_t)level, (char *)__FILE__, __LINE__, \
(char *)__FUNCTION__, (char *)string)
LogPrintLine(mask, (LogLevel_t)level, __FILE__, __LINE__, __FUNCTION__, \
(const char *)format, ##__VA_ARGS__)

/* Define the external prototype */
MBASE_PUBLIC void LogPrintLine( uint32_t mask, LogLevel_t level, char *file,
int line, char *function, char *format, ... );
MBASE_PUBLIC void LogPrintLineNoArg( uint32_t mask, LogLevel_t level,
char *file, int line, char *function,
char *message );
MBASE_PUBLIC void LogPrintLine( uint32_t mask, LogLevel_t level,
const char *file, int line,
const char *function, const char *format, ... );

#ifdef __cplusplus
}
Expand Down

0 comments on commit 0f50c51

Please sign in to comment.