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

Yes. You named the appender “MEASURE” so everywhere you want to use that appender including in your logInfo calls needs to use “MEASURE”.

Maybe I got lost…

I names:

log4j2.logger.Measure.name= Measure
and
log4j2.appender.Measure.name = Measure

and used

logInfo(“Measure”,logString)

but nothing, is my definition fine? I based it on examples I found int he forum, and couldn’t completely connect the dots between that example and the tutorial, so I would appreciate if you could detect any short-comings in my config entry.

Thanks for you support.

For completeness sake - is it necessary to restart openhab?

I’m not on a recent enough version of OH to help. All I know is the names must all match.

I tried the tutorial and just changed DEBUG to INFO and demo to gas:

# Logger - Gas.log
log4j.logger.org.eclipse.smarthome.model.script.Gas = INFO, Gas

# File appender - Gas.log
log4j.appender.Gas=org.apache.log4j.RollingFileAppender
log4j.appender.Gas.layout=org.apache.log4j.PatternLayout
log4j.appender.Gas.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss.SSS} [%-5.5p] [%-36.36c] - %m%n
log4j.appender.Gas.file=${openhab.logdir}/Gas.log
log4j.appender.Gas.append=true
log4j.appender.Gas.maxFileSize=10MB
log4j.appender.Gas.maxBackupIndex=10

No luck…

I never used that, however reading your posts you are switching back to the old “log4j” instead of “log4j2”. Was this on purpose?

Yes, I was, because the tutorial used log4j.
Anyway, I finally copied someone’s working solution.
But it has more than I need:

%d{yyyy-MM-dd HH:mm:ss.SSS} [%-5.5p] [%-36.36c] - %m%n <-- how much of this can I remove?

I do not really need the bolded section of the output.
2017-12-28 02:21:00.475 [INFO ] [.smarthome.model.script.rules.timers] - Gas Information 2017-12-28 02:21:00.465

My rule sends this:
val String logString = String::format(“Gas Information, %s, %s, %s”,date,time,GasString)

You can remove whatever you want. To get rid of the bolded section delete everything up to %m%n.

Or it might be more efficient, not that that really matters in this context, drop the date, time part of your logString and keep the %d{yyyy-MM-dd HH:mm:ss.SSS} and modify it as necessary.

I actually would not mind to remove the date from my log string, BUT, I would like ot have a comma for the “CSV”

Would it work as:

%d{yyyy-MM-dd}, d{HH:mm:ss.SSS}, %m%n <— a) can I split the data and time, and b) can I put commas in there?

Thanks guys, you all helped me get so far.

I see no reason why that won’t work. Comma does not appear to have any special meaning to log4j2.

Thanks. I will give that a try in the future, currently I did as said, I removed most of it and kept the date from my string.

Thanks.

Quick question - is it possible to save an item state for the next system restart or sitemap rebuild?

As I update my sitemap, I lose track of the last defined state of the item.
I wish to save it.

https://docs.openhab.org/configuration/persistence.html

I have enabled persistence, and think it works, because even when I rebuild my sitemap / items, things reload.

However, when I restarted the OS, it is not loading any previous value.

I have this in gas.persist
Strategies {
default = everyUpdate, restoreOnStartup
}
Items {
// persist all items once a day and on every change and restore them from the db at startup
// GasCounter : strategy = everyChange, everyChange, restoreOnStartup
}

You have all the lines commented out that would define items to be persisted.

Because I assumed the default ontop prevails.
Right? Or does it apply differently?

I think I figured it out!

GasCounter was only set as a text, not saved as an item.
Will try again.

Not figuring it out… :frowning:
I changed it to:

Strategies {
default = everyUpdate
}

Items {

  • : strategy = everyChange, restoreOnStartup
    }

Maybe a dumb question but, I am trying to use MapDB. Do I have to install MapDB somehow (is there something else besides the binding “addon”) ?

If you have the service loaded in PaperUI that should be all.
The .persist file should have the name of the loaded service, gas is definitely wrong.

cool, i like finding mistakes.
so should it be called mapdb.persist

Will try again.

Fixed the name, but no luck so far… :frowning: