Skip to content

Commit

Permalink
Added --syslog command line option for logging
Browse files Browse the repository at this point in the history
The default syslog facility is local7, but can be overridden by this command
line option.  Setting it to "none" disables syslog use, as does any invalid
facility name.  Facility names are treated as case insensitive.
  • Loading branch information
Beirdo committed Apr 30, 2011
1 parent e3cc1ad commit 1fa7981
Show file tree
Hide file tree
Showing 16 changed files with 71 additions and 15 deletions.
12 changes: 12 additions & 0 deletions mythtv/libs/libmyth/mythcommandlineparser.cpp
Expand Up @@ -821,6 +821,9 @@ void MythCommandLineParser::addLogging(void)
"file (currently disabled).\n", "");
add(QStringList( QStringList() << "-q" << "--quiet"), "quiet", 0,
"Don't log to the console (-q). Don't log anywhere (-q -q)\n", "");
add("--syslog", "syslog", "local7",
"Set the syslog logging facility. Set to \"none\" to disable\n"
"Defaults to local7\n", "");
}

void MythCommandLineParser::addPIDFile(void)
Expand Down Expand Up @@ -1408,3 +1411,12 @@ QString MythCommandLineParser::GetLogFilePath(void)
return toString("filepath");
}

int MythCommandLineParser::GetSyslogFacility(void)
{
QString setting = toString("syslog").toLower();
if (setting == "none")
return 0;

return syslogGetFacility(setting);
}

1 change: 1 addition & 0 deletions mythtv/libs/libmyth/mythcommandlineparser.h
Expand Up @@ -130,6 +130,7 @@ class MPUBLIC MythCommandLineParser
QStringList GetArgs(void) const { return m_remainingArgs; }
QMap<QString,QString> GetSettingsOverride(void);
QString GetLogFilePath(void);
int GetSyslogFacility(void);

bool toBool(QString key) const;
int toInt(QString key) const;
Expand Down
21 changes: 19 additions & 2 deletions mythtv/libs/libmythbase/mythlogging.cpp
Expand Up @@ -456,7 +456,7 @@ void LogPrintLineNoArg( uint32_t mask, LogLevel_t level, char *file, int line,
logQueue.enqueue(item);
}

void logStart(QString logfile, int quiet)
void logStart(QString logfile, int quiet, int facility)
{
LoggerBase *logger;

Expand All @@ -471,7 +471,12 @@ void logStart(QString logfile, int quiet)
logger = new FileLogger((char *)logfile.toLocal8Bit().constData());

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

/* Database */
logger = new DatabaseLogger((char *)"logging");
Expand Down Expand Up @@ -539,6 +544,18 @@ void threadDeregister(void)
logQueue.enqueue(item);
}

int syslogGetFacility(QString facility)
{
CODE *name;
int i;
char *string = (char *)facility.toLocal8Bit().constData();

for( i = 0, name = &facilitynames[0];
name->c_name && strcmp(name->c_name, string); i++, name++ );

return( name->c_val );
}

/*
* vim:ts=4:sw=4:ai:et:si:sts=4
*/
4 changes: 3 additions & 1 deletion mythtv/libs/libmythbase/mythlogging.h
Expand Up @@ -87,10 +87,12 @@ MBASE_PUBLIC void LogPrintLineNoArg( uint32_t mask, LogLevel_t level,
#ifdef __cplusplus
}

MBASE_PUBLIC void logStart(QString logfile, int quiet = 0);
MBASE_PUBLIC void logStart(QString logfile, int quiet = 0, int facility = 0);
MBASE_PUBLIC void logStop(void);
MBASE_PUBLIC void threadRegister(QString name);
MBASE_PUBLIC void threadDeregister(void);
MBASE_PUBLIC int syslogGetFacility(QString facility);

void LogTimeStamp( time_t *epoch, uint32_t *usec );

typedef union {
Expand Down
5 changes: 4 additions & 1 deletion mythtv/programs/mythavtest/main.cpp
Expand Up @@ -29,6 +29,7 @@ using namespace std;
int main(int argc, char *argv[])
{
int quiet = 0;
int facility = 0;

MythAVTestCommandLineParser cmdline;
if (!cmdline.Parse(argc, argv))
Expand Down Expand Up @@ -70,8 +71,10 @@ int main(int argc, char *argv[])
}
}

facility = cmdline.GetSyslogFacility();

QString logfile = cmdline.GetLogFilePath();
logStart(logfile, quiet);
logStart(logfile, quiet, facility);

if (!cmdline.toString("display").isEmpty())
{
Expand Down
4 changes: 3 additions & 1 deletion mythtv/programs/mythbackend/main.cpp
Expand Up @@ -101,6 +101,8 @@ int main(int argc, char **argv)
if (cmdline.toBool("daemon") && !quiet)
quiet = 1;

int facility = cmdline.GetSyslogFacility();

///////////////////////////////////////////////////////////////////////
// Don't listen to console input
close(0);
Expand All @@ -121,7 +123,7 @@ int main(int argc, char **argv)
gContext = new MythContext(MYTH_BINARY_VERSION);

logfile = cmdline.GetLogFilePath();
logStart(logfile);
logStart(logfile, quiet, facility);

if (cmdline.toBool("event") || cmdline.toBool("systemevent") ||
cmdline.toBool("setverbose") || cmdline.toBool("printsched") ||
Expand Down
4 changes: 3 additions & 1 deletion mythtv/programs/mythcommflag/main.cpp
Expand Up @@ -1076,6 +1076,8 @@ int main(int argc, char *argv[])
}
}

int facility = cmdline.GetSyslogFacility();

if (cmdline.toBool("queue"))
queueJobInstead = true;
if (cmdline.toBool("nopercent"))
Expand All @@ -1100,7 +1102,7 @@ int main(int argc, char *argv[])
CleanupGuard callCleanup(cleanup);

QString logfile = cmdline.GetLogFilePath();
logStart(logfile, quiet);
logStart(logfile, quiet, facility);

gContext = new MythContext(MYTH_BINARY_VERSION);
if (!gContext->Init(
Expand Down
4 changes: 3 additions & 1 deletion mythtv/programs/mythfilldatabase/main.cpp
Expand Up @@ -259,6 +259,8 @@ int main(int argc, char *argv[])
}
}

int facility = cmdline.GetSyslogFacility();

mark_repeats = cmdline.toBool("markrepeats");
if (cmdline.toBool("exporticonmap"))
export_icon_data_filename = cmdline.toString("exporticonmap");
Expand All @@ -280,7 +282,7 @@ int main(int argc, char *argv[])
CleanupGuard callCleanup(cleanup);

QString logfile = cmdline.GetLogFilePath();
logStart(logfile, quiet);
logStart(logfile, quiet, facility);

gContext = new MythContext(MYTH_BINARY_VERSION);
if (!gContext->Init(false))
Expand Down
3 changes: 2 additions & 1 deletion mythtv/programs/mythfrontend/main.cpp
Expand Up @@ -1076,6 +1076,7 @@ int main(int argc, char **argv)
}
}

int facility = cmdline.GetSyslogFacility();

VERBOSE(VB_IMPORTANT, QString("%1 version: %2 [%3] www.mythtv.org")
.arg(MYTH_APPNAME_MYTHFRONTEND)
Expand Down Expand Up @@ -1110,7 +1111,7 @@ int main(int argc, char **argv)
gContext = new MythContext(MYTH_BINARY_VERSION);

logfile = cmdline.GetLogFilePath();
logStart(logfile, quiet);
logStart(logfile, quiet, facility);

if (!cmdline.toBool("noupnp"))
{
Expand Down
4 changes: 3 additions & 1 deletion mythtv/programs/mythjobqueue/main.cpp
Expand Up @@ -122,6 +122,8 @@ int main(int argc, char *argv[])
}
}

int facility = cmdline.GetSyslogFacility();

if (cmdline.toBool("pidfile"))
pidfile = cmdline.toString("pidfile");
if (cmdline.toBool("daemon"))
Expand All @@ -130,7 +132,7 @@ int main(int argc, char *argv[])
CleanupGuard callCleanup(cleanup);

logfile = cmdline.GetLogFilePath();
logStart(logfile, quiet);
logStart(logfile, quiet, facility);

ofstream pidfs;
if (pidfile.size())
Expand Down
4 changes: 3 additions & 1 deletion mythtv/programs/mythlcdserver/main.cpp
Expand Up @@ -77,8 +77,10 @@ int main(int argc, char **argv)
quiet = 1;
}

int facility = cmdline.GetSyslogFacility();

logfile = cmdline.GetLogFilePath();
logStart(logfile, quiet);
logStart(logfile, quiet, facility);


if (cmdline.toBool("port"))
Expand Down
4 changes: 3 additions & 1 deletion mythtv/programs/mythpreviewgen/main.cpp
Expand Up @@ -206,6 +206,8 @@ int main(int argc, char **argv)
}
}

int facility = cmdline.GetSyslogFacility();

///////////////////////////////////////////////////////////////////////

// Don't listen to console input
Expand All @@ -214,7 +216,7 @@ int main(int argc, char **argv)
CleanupGuard callCleanup(cleanup);

QString logfile = cmdline.GetLogFilePath();
logStart(logfile, quiet);
logStart(logfile, quiet, facility);

if (signal(SIGPIPE, SIG_IGN) == SIG_ERR)
VERBOSE(VB_IMPORTANT, LOC_WARN + "Unable to ignore SIGPIPE");
Expand Down
4 changes: 3 additions & 1 deletion mythtv/programs/mythshutdown/main.cpp
Expand Up @@ -788,6 +788,8 @@ int main(int argc, char **argv)
}
}

int facility = cmdline.GetSyslogFacility();

if (cmdline.toBool("lock"))
bLockShutdown = true;
if (cmdline.toBool("unlock"))
Expand Down Expand Up @@ -824,7 +826,7 @@ int main(int argc, char **argv)


QString logfile = cmdline.GetLogFilePath();
logStart(logfile, quiet);
logStart(logfile, quiet, facility);

int res = 0;

Expand Down
4 changes: 3 additions & 1 deletion mythtv/programs/mythtranscode/main.cpp
Expand Up @@ -292,8 +292,10 @@ int main(int argc, char *argv[])
}
}

int facility = cmdline.GetSyslogFacility();

QString logfile = cmdline.GetLogFilePath();
logStart(logfile, quiet);
logStart(logfile, quiet, facility);

// Load the context
gContext = new MythContext(MYTH_BINARY_VERSION);
Expand Down
4 changes: 3 additions & 1 deletion mythtv/programs/mythtv-setup/main.cpp
Expand Up @@ -269,6 +269,8 @@ int main(int argc, char *argv[])
}
}

int facility = cmdline.GetSyslogFacility();

if (cmdline.toBool("overridesettings"))
settingsOverride = cmdline.GetSettingsOverride();
if (cmdline.toBool("expert"))
Expand Down Expand Up @@ -309,7 +311,7 @@ int main(int argc, char *argv[])
scanInputName = cmdline.toString("inputname");

logfile = cmdline.GetLogFilePath();
logStart(logfile, quiet);
logStart(logfile, quiet, facility);

if (!display.isEmpty())
{
Expand Down
4 changes: 3 additions & 1 deletion mythtv/programs/mythwelcome/main.cpp
Expand Up @@ -90,8 +90,10 @@ int main(int argc, char **argv)
}
}

int facility = cmdline.GetSyslogFacility();

logfile = cmdline.GetLogFilePath();
logStart(logfile, quiet);
logStart(logfile, quiet, facility);

gContext = new MythContext(MYTH_BINARY_VERSION);
if (!gContext->Init())
Expand Down

0 comments on commit 1fa7981

Please sign in to comment.