Difference between revisions of "Logging"

From MythTV Official Wiki
Jump to: navigation, search
(Suggest replacing logrotate with cron entries. May cause some welcome discussion.)
(Special interim note for mythfilldatabase, add references for existing logrotate examples.)
Line 1: Line 1:
MythTV (starting with version 0.25) supports logging to various different loggers. Logging to the various loggers is enabled with command-line arguments. Additional information about application command-line arguments is available using the <code>--help</code> argument, for example:
+
MythTV (starting with version 0.25) supports logging to various loggers. Logging to them is enabled with command-line arguments. Additional information about application command-line arguments is available using the <code>--help</code> argument, for example:
  
 
  mythbackend --help
 
  mythbackend --help
Line 63: Line 63:
 
will scan the log file at <code>/path/to/logfile</code> and output (to <code>stdout</code>) a simplified log format equivalent to that used by console logging.  Change the <code>/path/to/logfile</code>, as appropriate for your system.
 
will scan the log file at <code>/path/to/logfile</code> and output (to <code>stdout</code>) a simplified log format equivalent to that used by console logging.  Change the <code>/path/to/logfile</code>, as appropriate for your system.
  
 +
{{note box|Currently, <code>mythfilldatabase</code>
 +
has separate logging for the command itself and for the <code>wget</code> command it calls.
 +
 +
The following sample changes are made using <code>mythtv-setup</code>; select General, Program Schedule Download Options:
 +
Guide data arguments: --logpath /var/log/mythtv (added to existing arguments)
 +
Guide data program log path: /var/log/mythtv/mythfilldatabase_wget.log
 +
This note should be removed or updated after <code>wget</code> is replaced.
 +
}}
 
=== syslog Logging ===
 
=== syslog Logging ===
  
Line 81: Line 89:
 
== Log file cleanup ==
 
== Log file cleanup ==
  
When using <code>--logpath /path/to/log_directory</code>, one file for each run of a program and each of its children will be generated.
+
When using myth''programname''.log files, see [[Logrotate - mythbackend]] or [[Logrotate - mythfrontend]] for configuration examples.
As mentioned above, expect to see (for example) /var/log/mythtv/mythbackend.date.pid.log plus
+
 
 +
When using <code>--logpath /path/to/log_directory</code>, one file for '''each run''' of a program and each of its children will be generated.
 +
As mentioned above, expect to see (for example) /var/log/mythtv/mythbackend.''date''.''pid''.log plus
 
similar entries for <code>mythcommflag, mythmetadatalookup</code> and <code>mythpreviewgen</code>.
 
similar entries for <code>mythcommflag, mythmetadatalookup</code> and <code>mythpreviewgen</code>.
Since this will create a lot of files in the logging directory, cleanup is '''strongly''' recommended.
+
Since this will create a lot of files in the logging directory, cleanup is strongly recommended.
Existing <code>logrotate</code> files might be removed and be replaced by cron entries.
+
Existing entries in <code>logrotate</code> files can be removed and be replaced by cron entries.
 +
{{Code box|/etc/cron.hourly/mythtv|
 
  #!/bin/sh
 
  #!/bin/sh
# Sample /etc/cron/cron.hourly/mythtv file.
 
 
  find /var/log/mythtv -type f -mtime +1 -name "mythpreviewgen.*.log" -delete
 
  find /var/log/mythtv -type f -mtime +1 -name "mythpreviewgen.*.log" -delete
 
  find /var/log/mythtv -type f -mtime +1 -name "mythcommflag.*.log" -delete
 
  find /var/log/mythtv -type f -mtime +1 -name "mythcommflag.*.log" -delete
Line 93: Line 103:
 
  find /var/log/mythtv -type f -mtime +6 -name "mythbackend.*.log" -delete
 
  find /var/log/mythtv -type f -mtime +6 -name "mythbackend.*.log" -delete
 
  find /var/log/mythtv -type f -mtime +4 -name "mythfrontend.*.log" -delete
 
  find /var/log/mythtv -type f -mtime +4 -name "mythfrontend.*.log" -delete
 +
find /var/log/mythtv -type f -mtime +7 -name "mythfilldatabase.*.log" -delete
 +
}}
 
The above will remove <code>mythpreviewgen, mythcommflag</code> and <code>mythmetadatalookup</code> log files that are one day old.
 
The above will remove <code>mythpreviewgen, mythcommflag</code> and <code>mythmetadatalookup</code> log files that are one day old.
 
<code>mythbackend</code> log files get removed after 6 days etc.
 
<code>mythbackend</code> log files get removed after 6 days etc.
 
Adjust as necessary for you system.
 
Adjust as necessary for you system.

Revision as of 23:32, 21 September 2011

MythTV (starting with version 0.25) supports logging to various loggers. Logging to them is enabled with command-line arguments. Additional information about application command-line arguments is available using the --help argument, for example:

mythbackend --help

or

mythfrontend --help

Detailed help information is available for each argument by including the argument name after --help, for example:

mythbackend --help setloglevel
mythbackend --help logpath

General

All logging (regardless of specified logger) is affected by the arguments:

--setloglevel                   Change logging level of the existing master
                                backend.
--verbose OR -v                 Specify log filtering. Use '-v help' for level
                                info.

Typically, the default value for --setloglevel and --verbose are appropriate for normal application execution. However, you may be asked to provide logs at a specific log level when helping debug issues.

Loggers

Console Logging

If running a MythTV application in a non-daemon mode, console logging will be enabled. Console logging is output to stdout.

Console logging is automatically disabled with the argument:

--daemon OR -d                  Fork application into background after startup.

(for MythTV daemon applications).

The console logging output contains a shortened format which better fits a standard terminal. Therefore, please provide full file logging output when attaching log files to bug tickets.

File Logging

The primary logger for MythTV applications is the file logger. File logging outputs detailed "debug" logging information about process execution, which can be very useful in debugging issues with MythTV. All log files uploaded to bug tickets should be those created from the file logger.

File logging is disabled by default and may be enabled with the argument:

--logfile OR --logpath OR -l    Writes logging messages to a file at logpath.
                                If a directory is given, a logfile will be
                                created in that directory with a filename of
                                applicationName.date.pid.log.
                                If a full filename is given, that file will be
                                used.
                                This is typically used in combination with
                                --daemon, and if used in combination with
                                --pidfile, this can be used with log rotators,
                                using the HUP call to inform MythTV to reload
                                the file (currently disabled).

When specifying a file path, file logging is only enabled for the application you are starting. All logging will be disabled for child processes started by that application (for example, preview generation, commercial detection, transcoding, and other jobs started by mythbackend). Therefore, you should always specify a directory as the argument for --logpath or -l.

File logging output may be challenging to read in a terminal due to the amount of information included. You may simplify the log file output with a log processor. For example, the command:

perl -pwe 's#^(\d{4}(?:-\d{2}){2} \d{2}(?:\:\d{2}){2}\.\d{6} \w) \[\d+/\d+\] \S+ \S+ \(\S+\) - (.*$)#$1  $2#' /path/to/logfile

will scan the log file at /path/to/logfile and output (to stdout) a simplified log format equivalent to that used by console logging. Change the /path/to/logfile, as appropriate for your system.


Important.png Note: Currently, mythfilldatabase has separate logging for the command itself and for the wget command it calls.

The following sample changes are made using mythtv-setup; select General, Program Schedule Download Options:

Guide data arguments: --logpath /var/log/mythtv (added to existing arguments)
Guide data program log path: /var/log/mythtv/mythfilldatabase_wget.log

This note should be removed or updated after wget is replaced.

syslog Logging

Logging to syslog may be enabled with the argument:

--syslog                        Set the syslog logging facility.
                                Set to "none" to disable, defaults to none

By default, logging to syslog is disabled. You should only enable syslog logging if you have also configured syslog on your host to handle the MythTV log messages appropriately.

Database Logging

Database logging is enabled by default. It may be disabled with the argument:

--nodblog                       Disable database logging.

MythTV automatically cleans up the database logging information, to ensure your database does not grow out of control. All database logging information is removed within 2 weeks, so database logging is primarily useful for short-term log access, and should not be considered a valid long-term logging mechanism.

Log file cleanup

When using mythprogramname.log files, see Logrotate - mythbackend or Logrotate - mythfrontend for configuration examples.

When using --logpath /path/to/log_directory, one file for each run of a program and each of its children will be generated. As mentioned above, expect to see (for example) /var/log/mythtv/mythbackend.date.pid.log plus similar entries for mythcommflag, mythmetadatalookup and mythpreviewgen. Since this will create a lot of files in the logging directory, cleanup is strongly recommended. Existing entries in logrotate files can be removed and be replaced by cron entries.

Script.png /etc/cron.hourly/mythtv

#!/bin/sh
find /var/log/mythtv -type f -mtime +1 -name "mythpreviewgen.*.log" -delete
find /var/log/mythtv -type f -mtime +1 -name "mythcommflag.*.log" -delete
find /var/log/mythtv -type f -mtime +1 -name "mythmetadatalookup.*.log" -delete
find /var/log/mythtv -type f -mtime +6 -name "mythbackend.*.log" -delete
find /var/log/mythtv -type f -mtime +4 -name "mythfrontend.*.log" -delete
find /var/log/mythtv -type f -mtime +7 -name "mythfilldatabase.*.log" -delete

The above will remove mythpreviewgen, mythcommflag and mythmetadatalookup log files that are one day old. mythbackend log files get removed after 6 days etc. Adjust as necessary for you system.