Skip to content

Commit

Permalink
Clarify logger usage docs (#93)
Browse files Browse the repository at this point in the history
  • Loading branch information
jimtng authored Jul 22, 2023
1 parent a3553f7 commit 9eaf740
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -740,23 +740,24 @@ Exec.execute_command_line('/path/to/program')

### Logging

The JRuby Scripting addon has a global `logger` object for logging.
The JRuby Scripting addon has a global `logger` object for logging. To log a message on `INFO` log level:

```text
log:set DEBUG org.openhab.automation.jrubyscripting.script
```ruby
logger.info("The current time is #{Time.now}")
```

The default logger name for UI rules is `org.openhab.automation.jrubyscripting.script`.
For file-based rules, it's based on the rule's ID, such as `org.openhab.automation.jrubyscripting.rule.myrule.rb:15`
This can be changed by assigning a new logger locally.

Please be aware that messages might not appear in the logs if the logger name does not start with `org.openhab`.
This behaviour is due to [log4j2](https://logging.apache.org/log4j/2.x/) requiring definition for each logger prefix.
To use a custom logger name:

```ruby
logger = OpenHAB::Log.logger("org.openhab.custom")
```

Please be aware that messages might not appear in the logs if the logger name does not start with `org.openhab`.
This behaviour is due to [log4j2](https://logging.apache.org/log4j/2.x/) requiring definition for each logger prefix.

The {OpenHAB::Logger logger} is similar to a standard [Ruby Logger](https://docs.ruby-lang.org/en/master/Logger.html).
Supported logging functions include:

Expand Down

0 comments on commit 9eaf740

Please sign in to comment.