Logging to csv or some txt at fixed interval of cron rule

Hi Nadir,

After installing the Binding, in the Paper UI select Mapdb as your preferred persistent service.

In the directory /etc/openhab2/persistence

You need to create a file called mapdb.persist

Here you have an example of the content:

Strategies {

Items {
    thermostat_livingroom_mode: strategy = everyChange, restoreOnStartup

That will log the value of thermostat_livingroom_mode every time it changes and will reload it on Startup.

Keep in mind that Mapdb only persists the latest value, hence, if your idea is to analyze the data, you would be better off using something like InfluxDB and Grafana.

The idea of creating custom logs I think is going to be more work in the long run.

I hope this helps.

Hmmmmm. This is where I am at now.

I tried to go with influx but quickly gave up do to BV the need to compile for the pi.

I am also trying to log data from my smartmeter into a separate log file.

This is the setting for the logs:

#Meter logger
log4j2.logger.Meter.name = Meter
log4j2.logger.Meter.level = INFO
log4j2.logger.Meter.additivity = false
log4j2.logger.Meter.appenderRefs = Meter
log4j2.logger.Meter.appenderRef.Meter.ref = Meter

# Meter File Appender - Meter.log
log4j2.appender.Meter.name = Meter
log4j2.appender.Meter.type = RollingRandomAccessFile
log4j2.appender.Meter.fileName = ${openhab.logdir}/Meter.log
log4j2.appender.Meter.filePattern = ${openhab.logdir}/Meter.log.%i
log4j2.appender.Meter.immediateFlush = true
log4j2.appender.Meter.append = true
log4j2.appender.Meter.layout.type = PatternLayout
log4j2.appender.Meter.layout.pattern = %d{yyyy-MM-dd HH:mm:ss.SSS} [%-5.5p] [%-36.36c] - %m%n
log4j2.appender.Meter.policies.type = Policies
log4j2.appender.Meter.policies.size.type = SizeBasedTriggeringPolicy
log4j2.appender.Meter.policies.size.size = 10MB
log4j2.appender.Meter.strategy.type = DefaultRolloverStrategy
log4j2.appender.Meter.strategy.max = 10

The log command in the rules file:

logInfo("Meter", "Ebezug: "+ Ebezug.state.toString)

and the result in the openhab.log:

2020-01-03 12:45:20.572 [INFO ] [eclipse.smarthome.model.script.Meter] - Ebezug: 4159.0728

So far, so good. But this is not in the Meter.log file, what I expected.
The file is created, but the size is =0.

Can someone point me to the fault?

I think the logger name needs to be the full path, i.e. org.eclipse.smarthome.model.script.Meter. I’m no expert though and could be wrong on that. But all of the examples already in the pax logger config use the full path.

This does the trick, thanks! :+1:
But only in the logger, not in the appender, then it stops working again.

Correct, the name in the appender is a reference to the name of the logger(s) the appender logs for.