OH3: date format without local bits

  • opennHABian 3.3.0 rPi4 with 4GB

I used to have this date format (lines 1 and 2) in log files created by rules in OH2.
After migrating the format changed as seen in line 3 and 4.

2022-11-19T11:31:28.034+10:00 MEGA_MODBUS_ERROR_Invalid CRC at 8059
2022-11-19T11:51:15.686+10:00 MEGA_MODBUS_ERROR_Invalid CRC at 8059
2022-11-19T13:18:48.865143+10:00[Australia/Brisbane] MEGA_MODBUS_ERROR_Invalid CRC at 8051
2022-11-19T13:39:07.000743+10:00[Australia/Brisbane] MEGA_MODBUS_ERROR_Response Timed Out at 8000
OH2: val startOfDay = now.withTimeAtStartOfDay
OH3: val START_OF_DAY = ZonedDateTime.now().with(LocalTime.MIDNIGHT)

Is there a format on OH3 that matches lines 1 and 2?

Any hints appreciated.

The question seems to be “how to format a Java zonedDateTime for pretty printing”?
example

1 Like

You’re talking about the timestamps on log entries, right?

All logging stuff is controlled by $OH_USERDATA/etc/log4j2.xml. But the default pattern layouts there shouldn’t be showing the timezone at all, in neither OH 2.5 nor OH 3. Also, those examples are missing a bunch of stuff that is normally there like the logging level and where the log statement came from.

So have you ever edited this file? Do the contents of this file differ from the official one?

Is this one of your “other” logs that you create using echo instead of the built in logging features?

My apologies to all for putting a half-*rse case forward…

The logging I am referring to is done via a rule writing to item-specific files. Like so:

        if (spm_Message.state.toString == "MEGA_MODBUS|INFO|has rebooted")
        {
            logInfo(LOG_PREFIX + "01.01", "--> MEGA_MODBUS has rebooted :(")
            spm_LastReboot.postUpdate(new DateTimeType())

            // logging controller reboots
            val String ERROR_MESSAGE = ZonedDateTime.now().toString + " " + spm_Message.state.toString.replace('|', '_')
            val String CLI_RETURN_CODE = executeCommandLine(Duration.ofSeconds(3), "/bin/sh", "-c", "echo " + ERROR_MESSAGE + " >> /etc/openhab/html/Modbus.txt; echo -n $?")
            logInfo(LOG_PREFIX + "01.02","Modbus message logged to file")

            if (Integer::parseInt(CLI_RETURN_CODE) != 0)
            {
                logInfo(LOG_PREFIX + "01.03","Return code: {}", CLI_RETURN_CODE)
            }
        }

I am talking about date formats coming from now()…

Good article!

Changing to LocalDateTime resulted in the 2nd line…

2022-12-13T18:25:33.244697+10:00[Australia/Brisbane] MEGA_MODBUS_ERROR_Invalid CRC at 8059
2022-12-13T19:17:12.899308 MEGA_MODBUS_ERROR_Invalid CRC at 8100

… close enough.