Skip to content

Commit

Permalink
Add mechanism to MythSystem for log argument passthrough.
Browse files Browse the repository at this point in the history
This adds the kMSPropagateLogs bit to the flags accepted by MythSystem,
for use with MythTV binaries. If enabled, it will automatically append
the necessary command line logging arguments, as a String or StringList,
which ever is appropriate.

Refs #11026
  • Loading branch information
wagnerrp committed Oct 6, 2012
1 parent 2b74a68 commit ecfa569
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 3 deletions.
15 changes: 15 additions & 0 deletions mythtv/libs/libmythbase/logging.cpp
Expand Up @@ -88,6 +88,7 @@ typedef struct {

LogPropagateOpts logPropagateOpts;
QString logPropagateArgs;
QStringList logPropagateArgList;

#define TIMESTAMP_MAX 30
#define MAX_STRING_LENGTH (LOGLINE_MAX+120)
Expand Down Expand Up @@ -776,22 +777,35 @@ void LogPrintLine( uint64_t mask, LogLevel_t level, const char *file, int line,
/// spawned from this one.
void logPropagateCalc(void)
{
logPropagateArgList.clear();

QString mask = verboseString.trimmed();
mask.replace(QRegExp(" "), ",");
mask.remove(QRegExp("^,"));
logPropagateArgs = " --verbose " + mask;
logPropagateArgList << "--verbose" << mask;

if (logPropagateOpts.propagate)
{
logPropagateArgs += " --logpath " + logPropagateOpts.path;
logPropagateArgList << "--logpath" << logPropagateOpts.path;
}

QString name = logLevelGetName(logLevel);
logPropagateArgs += " --loglevel " + name;
logPropagateArgList << "--loglevel" << name;

for (int i = 0; i < logPropagateOpts.quiet; i++)
{
logPropagateArgs += " --quiet";
logPropagateArgList << "--quiet";
}

if (!logPropagateOpts.dblog)
{
logPropagateArgs += " --nodblog";
logPropagateArgList << "--nodblog";
}

#ifndef _WIN32
if (logPropagateOpts.facility >= 0)
Expand All @@ -803,6 +817,7 @@ void logPropagateCalc(void)
syslogname->c_val != logPropagateOpts.facility); syslogname++);

logPropagateArgs += QString(" --syslog %1").arg(syslogname->c_name);
logPropagateArgList << "--syslog" << syslogname->c_name;
}
#endif
}
Expand Down
6 changes: 4 additions & 2 deletions mythtv/libs/libmythbase/mythlogging.h
Expand Up @@ -3,6 +3,7 @@

#ifdef __cplusplus
#include <QString>
#include <QStringList>
#endif
#include <stdint.h>
#include <errno.h>
Expand Down Expand Up @@ -60,8 +61,9 @@ extern MBASE_PUBLIC uint64_t verboseMask;
#ifdef __cplusplus
}

extern MBASE_PUBLIC QString logPropagateArgs;
extern MBASE_PUBLIC QString verboseString;
extern MBASE_PUBLIC QStringList logPropagateArgList;
extern MBASE_PUBLIC QString logPropagateArgs;
extern MBASE_PUBLIC QString verboseString;

MBASE_PUBLIC void logStart(QString logfile, int progress = 0, int quiet = 0,
int facility = 0, LogLevel_t level = LOG_INFO,
Expand Down
19 changes: 19 additions & 0 deletions mythtv/libs/libmythbase/mythsystem.cpp
Expand Up @@ -105,6 +105,23 @@ void MythSystem::SetCommand(const QString &command,

ProcessFlags(flags);

// add logging arguments
if (GetSetting("PropagateLogs"))
{
if (m_args.isEmpty())
{
m_command += logPropagateArgs;
if (!logPropagateQuiet())
m_command += " --quiet";
}
else
{
m_args << logPropagateArgList;
if (!logPropagateQuiet())
m_args << "--quiet";
}
}

// check for execute rights
if (!GetSetting("UseShell") && access(command.toUtf8().constData(), X_OK))
{
Expand Down Expand Up @@ -320,6 +337,8 @@ void MythSystem::ProcessFlags(uint flags)
m_settings["AnonLog"] = true;
if( flags & kMSLowExitVal )
m_settings["OnlyLowExitVal"] = true;
if( flags & kMSPropagateLogs )
m_settings["PropagateLogs"] = true;
}

QByteArray MythSystem::Read(int size)
Expand Down
2 changes: 2 additions & 0 deletions mythtv/libs/libmythbase/mythsystem.h
Expand Up @@ -26,6 +26,8 @@ typedef enum MythSystemMask {
kMSLowExitVal = 0x00008000, ///< allow exit values 0-127 only
kMSDisableUDPListener = 0x00010000, ///< disable MythMessage UDP listener
/// for the duration of application.
kMSPropagateLogs = 0x00020000, ///< add arguments for MythTV log
/// propagation
} MythSystemFlag;

#ifdef __cplusplus
Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythbase/mythversion.h
Expand Up @@ -12,7 +12,7 @@
/// Update this whenever the plug-in API changes.
/// Including changes in the libmythbase, libmyth, libmythtv, libmythav* and
/// libmythui class methods used by plug-ins.
#define MYTH_BINARY_VERSION "0.26.20120822-1"
#define MYTH_BINARY_VERSION "0.27.20120906-1"

/** \brief Increment this whenever the MythTV network protocol changes.
*
Expand Down

0 comments on commit ecfa569

Please sign in to comment.