How can I show Loggers in Console which log to extra files?

Hello everybody,

can someone help me with a little question?
I made some loggers which log to extra files. However, I have now noticed that these loggers are not displayed in the console when I run the log:display command. Is it possible for loggers to write to extra files but still show up in the console? Attached is the log4j2.xml with the loggers I created and are working so far. log4j2.xml.txt (9.6 KB)

  • Platform information:
    • Hardware: Raspberry Pi 4, 8 GB RAM
    • OS: Raspberry Pi OS 10 (Buster)
    • Java Runtime Environment:
      openjdk 11.0.11 2021-04-20 LTS
      OpenJDK Runtime Environment Zulu11.48+21-CA (build 11.0.11+9-LTS)
      OpenJDK Client VM Zulu11.48+21-CA (build 11.0.11+9-LTS, mixed mode)
    • openHAB version: openHAB 3.2.0 Release Build

Thank you in advance for the support.

Christian

Adding the related log level for your scripts will add the output to the console as well.

Hello Wolfgang,
sorry but I don’t understand your answer. As written in my first post, I created new loggers using log4j2.xml, which log in extra files. See the file attached to my first post. After restarting the openhab service, these extra files were also created automatically. I then used these loggers in small rules.
Here is the content of an example rules file:

rule "Logtest EIN"
when
    Item TestItemLogging changed to ON
then
    logInfo("EXTRA","Test extra.log EIN")
end

rule "Logtest AUS"
when
    Item TestItemLogging changed to OFF
then
    logInfo("EXTRA","Test extra.log AUS")
end

If TestItemLogging changes, the corresponding information is also written to the respective log file:

2022-04-26 11:14:18.707 [INFO ] [org.openhab.core.model.script.EXTRA ] - Test extra.log EIN
2022-04-26 11:14:25.913 [INFO ] [org.openhab.core.model.script.EXTRA ] - Test extra.log AUS

I thought I defined the loglevel with the “logInfo” command in my rules. I only want to see the LogInfo output in addition to the log files in the console, and that permanently.
But unfortunately the output in the console remains empty.

openhab> log:display org.openhab.core.model.script.EXTRA

openhab>

When I run log:list in the console, I also see my scripts in the list, with each configured level:

openhab> log:list
Logger                                             │ Level
───────────────────────────────────────────────────┼──────
ROOT                                               │ WARN
javax.jmdns                                        │ ERROR
javax.mail                                         │ ERROR
openhab.event                                      │ INFO
openhab.event.AddonEvent                           │ ERROR
openhab.event.ChannelDescriptionChangedEvent       │ ERROR
openhab.event.InboxUpdatedEvent                    │ ERROR
openhab.event.ItemAddedEvent                       │ ERROR
openhab.event.ItemChannelLinkAddedEvent            │ ERROR
openhab.event.ItemChannelLinkRemovedEvent          │ ERROR
openhab.event.ItemRemovedEvent                     │ ERROR
openhab.event.ItemStateEvent                       │ ERROR
openhab.event.RuleAddedEvent                       │ ERROR
openhab.event.RuleRemovedEvent                     │ ERROR
openhab.event.RuleStatusInfoEvent                  │ ERROR
openhab.event.StartlevelEvent                      │ ERROR
openhab.event.ThingAddedEvent                      │ ERROR
openhab.event.ThingRemovedEvent                    │ ERROR
openhab.event.ThingStatusInfoEvent                 │ ERROR
openhab.event.ThingUpdatedEvent                    │ ERROR
org.apache.cxf.jaxrs.sse.SseEventSinkImpl          │ ERROR
org.apache.karaf.jaas.modules.audit                │ INFO
org.apache.karaf.kar.internal.KarServiceImpl       │ ERROR
org.apache.karaf.shell.ssh.SshUtils                │ ERROR
org.apache.karaf.shell.support                     │ OFF
org.apache.sshd                                    │ ERROR
org.eclipse.lsp4j                                  │ OFF
org.jupnp                                          │ ERROR
org.openhab                                        │ INFO
org.openhab.automation.script                      │ TRACE
org.openhab.core.model.script.BATTERIERAUM         │ INFO
org.openhab.core.model.script.BEWAESSERUNG         │ INFO
org.openhab.core.model.script.EXTRA                │ INFO
org.openhab.core.model.script.HEATING              │ INFO
org.openhab.core.model.script.ROHRREINIGUNG        │ INFO
org.openhab.core.model.script.RUECKSTAUKLAPPE      │ INFO
org.openhab.core.model.script.ZISTERNE             │ INFO
org.ops4j.pax.url.mvn.internal.AetherBasedResolver │ ERROR
org.ops4j.pax.web.pax-web-runtime                  │ OFF
su.litvak.chromecast.api.v2.Channel                │ ERROR
openhab>

At what point do I have to configure the log level so that the same content from the extra files is always output in the console?

Many thanks and greetings

Christian

Logger additivity="false"

prevents that the log message is forwarded to another logger. Thus the console logger will not receive it. Try to change it to “true” in the configuration of your additional loggers, that should yield the desired result.

Hello Stefan,
Thank you for your reply. That was the trick. Now it works!
A small further question, how long are the log entries visible under log:display? I noticed that these are no longer displayed after a short time. Is it possible to extend the display in log:display?

That I can’t answer, sorry. Hopefully someone else can step in.