|
Post by papa on Jun 28, 2019 0:28:07 GMT
Send Data to a Separate Log File
Logging data throughout our openHAB programming & examining openHAB's logs are helpful to our debugging. By default, changes in item states, warnings, errors, & data we generate with logInfo() are writen to openhab.log & events.log in openHAB's log folders. For viewing, we can load these .log files into a text editor like Notepad++. We can also view their scrolling entries in real time, by entering log:tail in openHAB's Karaf console. If we generate multiple log entries, this can grow cumbersome & confusing. To debug certain projects or to record information we may want/need later, we might set openHAB to log similar-topic data in a log file other than openhab.log or events.log. A rule statement such as logInfo("Irrigation", "Valves ON") has the potential to make a time-stamped entry in a separate Irrigation.log file. However, some setup is required first. Otherwise, the log entry will just show up in openhab.log. The following is how I did it for openHAB 2.5.0.M1 which may relate to other recent versions. I adapted what I found here (See the reply after "Try:").
Continued ...
|
|
|
Post by papa on Jun 28, 2019 0:32:30 GMT
Send Data to a Separate Log File, Continued
Let's say we have the openHAB rule statement And we want that statement to make time-stamped entries of "Valves ON" in an Irrigation.log file
Find org.ops4j.pax.logging.cfg in openHAB's \userdata\etc folder. Open the file in a text editor like Notepad++. At the end of the org.ops4j.pax.logging.cfg file, add the following lines (& save the.cfg file):
### Custom Logger ### # Irrigation log4j2.logger.Irrigation.name = org.eclipse.smarthome.model.script.Irrigation log4j2.logger.Irrigation.level = DEBUG log4j2.logger.Irrigation.additivity = false log4j2.logger.Irrigation.appenderRefs = Irrigation log4j2.logger.Irrigation.appenderRef.Irrigation.ref = Irrigation
### Custom Appender ### # Irrigation log4j2.appender.Irrigation.name = Irrigation log4j2.appender.Irrigation.type = RollingRandomAccessFile log4j2.appender.Irrigation.fileName = ${openhab.logdir}/Irrigation.log log4j2.appender.Irrigation.filePattern = ${openhab.logdir}/Irrigation.log.%i log4j2.appender.Irrigation.immediateFlush = true log4j2.appender.Irrigation.append = true log4j2.appender.Irrigation.layout.type = PatternLayout log4j2.appender.Irrigation.layout.pattern = %d{yyyy-MM-dd HH:mm:ss.SSS} [%-5.5p] [%-36.36c] - %m%n log4j2.appender.Irrigation.policies.type = Policies log4j2.appender.Irrigation.policies.size.type = SizeBasedTriggeringPolicy log4j2.appender.Irrigation.policies.size.size = 10MB log4j2.appender.Irrigation.strategy.type = DefaultRolloverStrategy log4j2.appender.Irrigation.strategy.max = 10
Continued
|
|
|
Post by papa on Jun 28, 2019 0:35:08 GMT
Send Data to a Separate Log File, Continued
The above setup will create the Irrigation.log file & append each time-stamped entry generated by Rule lines that start with logInfo("Irrigation", ...)
To create entries in another file (separate from openhab.log or events.log), search the added lines in the last post AND in your Rule lines & replace Irrigation with another name (may be best to avoid spaces in the name).
|
|