Logging Configuration

PmLog provides logging configuration methods to set the log level and log file by each context.

A configuration file is used to create context(s) for your component and configure the context settings as needed. It must be added to the component’s files/conf/pmlog/<filename>.conf and installed in (WEBOS_INSTALL_SYSCONFDIR)/pmlog.d.

The format and content of the configuration file must be as follows:

{
     "contexts" : [
          {
               "name" : "mycontext",
               "level" : "info".
               "logProcessIds" : false,
               "logThreadIds" : false,
               "logToConsole" : false,
               "rules" : [
                    { "filter" : "*.*", "output" : "mycontext_log" }
               ]
          }
     ],
     "outputs" : [
          {
               "name" : "mycontext_log",
               "file" : "<at:var at:name="WEBOS_INSTALL_LOGDIR" />/mycontext.log",
               "maxSize": 2000,
               "rotations" : 5
          }
     ]
}
Please note that it is not mandated to configure your context. You can just call PmLogGetContext() to create a new context, whose settings will take the default values.

The Contexts Section

Here you can specify logging context names and what the default level should be for them. Changes to the Contexts section will only be read at boot time. If you change this section, device has to be rebooted or use PmLogCtl app to see real time changes without rebooting.

The <default> context is specially defined, otherwise client context names should follow the regular rules, i.e. use alphanumeric characters only and use a period (".") to separate component hierarchies.

Parameter Description

level

One of the standard pmlog levels or none to disable logging.

logProcessIds

Enables to turn on process ID tagging.

logThreadIds

Enables to turn on thread ID tagging.

logToConsole

Enables to turn on stdout output.

bufferSize

[OPTIONAL - integer] The ring buffer size for a context

flushLevel

[OPTIONAL - integer] The flush level for a ring buffer. This is one of the pmlog levels.

rules

Specifies routing rules for each context. A rule specifies filter and output.

rules.filter

A filter format is as follows:

<facility>[.<level>[.<program>]]
  • facility: One of the standard syslog facilities or use an asterisk ("*") to indicate all - http://en.wikipedia.org/wiki/Syslog#Facility_Levels
  • level: One of the standard syslog levels or use an asterisk ("*") to indicate all. When specifying a level, it implicitly matches that level or higher. The level may be prefixed with '!' to match only lower levels.
  • program: Specify an exact program name or use an asterisk ("*") to indicate all.

rules.output

Indicates one of the named output targets previously defined. If a single quote (' ') is specified before the output, it indicates that the specified filter should omit matched messages.

The Outputs Section

Each output defines settings for a particular log file.

Parameter Description
file
Path to file.
maxSize
Maximum size the file can reach before rotation.
rotations
The maximum number of rotations before rotating files out the oldest files.

 

All context logs are routed to /var/log/messages by default. However, if you want to route context logs to a particular file, you should create a configuration file as above format in /etc/pmlog.d/ directory and set the contextLogging parameter to true as shown in line 23 below in /etc/pmlog.d/default.conf. Then, each component logs are written in an individual file separately.

The /etc/pmlog.d/default.conf has the following default format: 

{
     "contexts" : [
          {
               "name" : "<default>",
               "level" : "info".
               "logProcessIds" : false,
               "logThreadIds" : false,
               "logToConsole" : false,
               "rules" : [
                    { "filter" : "*.*", "output" : "stdlog" },
                    { "filter" : "kern.!info", "output" : "-stdlog" }
               ]
          }
     ],
     "outputs" : [
          {
               "name" : "stdlog",
               "file" : "/var/log/messages",
               "maxSize" : 2000,
               "rotations" : 5
          }
     ],
     "contextLogging" : false
}

After changing the value of contextLogging parameter, device needs to be rebooted.

Except as noted, this content is licensed under Creative Commons Attribution 4.0 and sample code is licensed under Apache License 2.0.