Configure Wrapper Log for single-line messages

Just because I noticed this thread got referenced and it jogged my memory
We ended up using the below for our appender and after getting CirrusLink to fix a bug in the logs on a module, we saw great success getting the useful lines of a stack trace. Note that because we’re digesting the logs in another system and because we’ve gone rounds with the log formatting above, we’ve got start, section and end markers in the pattern to make it obvious which part of the template is or is not responsible for each part.

It’s important to note that you can adjust the logging for modules that are too noisy in the Logs settings on the gateway itself and it does make changes to the volume coming through logback. This ended up being our ultimate way to get a handle on anything that we find generating too much volume. This makes it less critical if a given log type has bad interactions with logback.

 <appender name="SysoutAppender" class="ch.qos.logback.core.ConsoleAppender">
    <encoder>
     <pattern>%p |M: %m |S: %replace(%ex{short}){'[\r\n]+', ''}%nopex | END %n</pattern>

    </encoder>
  </appender>
2 Likes

This thread was a big help to me in understanding the layers involved in Ignition logging. I was able to get external logging working with our centralized Seq logging server using GELF.

All I needed was an Seq GELF plugin and a Logback GELF appender:

  • Install the Seq plugin Seq.Input.Gelf
  • Place the jar for the Logback GELF appender into C:\Program Files\Inductive Automation\Ignition\lib\core\common on my gateway server.
  • Configure the appender in logback.xml:
    ...
      <appender name="SeqGelfInput" class="de.siegmar.logbackgelf.GelfUdpAppender">
        <graylogHost>1.2.3.4</graylogHost>
        <graylogPort>12201</graylogPort>
      </appender>
      <root level="WARN">
        <appender-ref ref="SeqGelfInput" />
      </root>
    ...
    
  • Restart Ignition and peep those nice, structured logs (with stack traces!)

We'll also be using Seq to send SMTP email notifications whenever any of our gateways throw errors.

5 Likes

Thank you very much for the detailled answers. It helped a lot and it is working like a charm.
On the top of this, I would like to set an additionnal syslogAppender that would only log DEBUG level message from a specific logger (in that case ignition.UserSourceManager.Wrapper). The idea is to save loggin attemps (success and failures) to syslog.
My guess is to use the Filter setting for that but I cannot find how to (it seems that one can filter on the message content but not on the logger).
Has anyone an idea that could help me on this point ?
Thanks.

Here is a supplement to logback.xml to include a separate configuration file (that will contain our additions):

  ...
  <!-- Add this to your `data/logback.xml` file -->
  <include file="data/logback-custom.xml" />
</configuration>

And then, in data/logback-custom.xml place the following contents:

<included>
  <appender name="GatewayAuth" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <file>logs/gateway-auth.log</file>
    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
      <!-- Rollover each day and keep 30 days history -->
      <fileNamePattern>logs/gateway-auth.%d{yyyy-MM-dd}.log</fileNamePattern>
      <maxHistory>30</maxHistory>
    </rollingPolicy>
    <encoder>
      <pattern>%date{ISO8601} [%-30c{1}] [%-5p]: %m %X%n</pattern>
    </encoder>
  </appender>
  <logger name="gateway.AuthenticationRoutes" level="DEBUG" additivity="false">
    <appender-ref ref="GatewayAuth"/>
  </logger>
  <logger name="ignition.UserSourceManager.Wrapper" level="DEBUG" additivity="false">
    <appender-ref ref="GatewayAuth"/>
  </logger>
  <logger name="UserSource.Internal" level="INFO">
    <appender-ref ref="GatewayAuth"/>
  </logger>
</included>

The example above uses a RollingFileAppender, but you can substitute what you like here. Note the additivity setting (which defaults to true when omitted) on the supplemental loggers that we use to force these specific loggers to only be applied to our specified appender (instead of also to the root, which we let happen for UserSource.Internal at INFO level).

3 Likes

Thank you very much for the cristal clear reply.

1 Like