Okay so I think this is definitely what I am looking for. However for some reason I am struggling to get it to work, want to make sure its not ignitions implementation of logback
that is affecting what I did.
I updated my logback.xml to include the following:
Appender:
<appender name="CUSTOM-LOGGER-FILE" class="ch.qos.logback.core.FileAppender">
<file>logs/custom-logger.log</file>
<append>true</append>
<encoder>
<pattern>%.-1p [%-30c{1}] [%d{HH:mm:ss,SSS}]: %m %X%n</pattern>
</encoder>
</appender>
Logger:
<logger name="custom-logger" level="TRACE" additivity="false">
<appender-ref ref="CUSTOM-LOGGER-FILE"/>
</logger>
Full logback.xml
<?xml version="1.0" encoding="UTF-8"?>
<!-- For assistance related to logback-translator or configuration -->
<!-- files in general, please contact the logback user mailing list -->
<!-- at http://www.qos.ch/mailman/listinfo/logback-user -->
<!-- -->
<!-- For professional support please see -->
<!-- http://www.qos.ch/shop/products/professionalSupport -->
<!-- -->
<configuration debug="true">
<appender name="SysoutAppender" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%.-1p [%-30c{1}] [%d{HH:mm:ss,SSS}]: %m %X%n</pattern>
</encoder>
</appender>
<appender name="CUSTOM-LOGGER-FILE" class="ch.qos.logback.core.FileAppender">
<file>logs/custom-logger.log</file>
<append>true</append>
<encoder>
<pattern>%.-1p [%-30c{1}] [%d{HH:mm:ss,SSS}]: %m %X%n</pattern>
</encoder>
</appender>
<appender name="DB" class="com.inductiveautomation.logging.SQLiteAppender">
<dir>logs</dir>
<!--
Maintenance Settings
entryLimit: The maximum number of entries in the database. However, at any given time, there may be more than this number, due to how cleanup works.
maxEventsPerMaintenance: The number of event that can happen before a maintenance cycle occurs.
minTimeBetweenMaintenance: The minimum time (max frequency) between maintenance events. Takes precedent over max events.
vacuumFrequency: The number of maintenance cycles before a "vacuum" is performed, to recover disk space.
On disk, most log events are between 600-800 bytes.
<entryLimit>50000</entryLimit>
<maxEventsPerMaintenance>5000</maxEventsPerMaintenance>
<minTimeBetweenMaintenance>60000</minTimeBetweenMaintenance>
<vacuumFrequency>3</vacuumFrequency>
-->
</appender>
<appender name="SysoutAsync" class="ch.qos.logback.classic.AsyncAppender" queueSize="1000" discardingThreshold="0">
<appender-ref ref="SysoutAppender" />
</appender>
<appender name="DBAsync" class="ch.qos.logback.classic.AsyncAppender" queueSize="100000" discardingThreshold="0">
<appender-ref ref="DB" />
</appender>
<logger name="custom-logger" level="TRACE" additivity="false">
<appender-ref ref="CUSTOM-LOGGER-FILE"/>
</logger>
<root level="INFO">
<appender-ref ref="SysoutAsync"/>
<appender-ref ref="DBAsync"/>
</root>
</configuration>
And then I tried to run this in both the script console and a perspective button to test different scopes:
logger = system.util.getLogger("custom-logger")
logger.trace("trace")
logger.debug("debug")
logger.info("info")
logger.warn("warn")
logger.error("error")
However I only get the logs when I do it from the perspective button, not the script console.
T [custom-logger ] [17:40:52]: trace component=root/Button, view=Button@D, project-name=TEST
D [custom-logger ] [17:40:52]: debug component=root/Button, view=Button@D, project-name=TEST
I [custom-logger ] [17:40:52]: info component=root/Button, view=Button@D, project-name=TEST
W [custom-logger ] [17:40:52]: warn component=root/Button, view=Button@D, project-name=TEST
E [custom-logger ] [17:40:52]: error component=root/Button, view=Button@D, project-name=TEST
Any idea if there is something I have configured wrong that is not allowing it to work from the client scope as well?
Note: I did try using ch.qos.logback.core.ConsoleAppender
instead of ch.qos.logback.core.FileAppender
but then I couldn’t get anything to write to the file, so I used the FileAppender
class mentioned in the above link.