Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add priority on journald log format #950

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open

Conversation

baelter
Copy link
Member

@baelter baelter commented Feb 13, 2025

WHAT is this pull request doing?

Adds priority to journald formatter

HOW can this pull request be tested?

LOG_LEVEL=DEBUG ./bin/lavinmq -D /tmp/amqp 2>&1 | systemd-cat -t lavinmq

journalctl -t lavinmq --output-fields=PRIORITY,MESSAGE

@baelter baelter requested a review from a team as a code owner February 13, 2025 12:15
kickster97
kickster97 previously approved these changes Feb 13, 2025
Copy link
Member

@kickster97 kickster97 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't test this on my mac, but mapping looks good to me

@jage
Copy link
Member

jage commented Feb 13, 2025

Tried it out, not 100%:

...
Feb 13 12:31:14 dev-frozen-toucan-01 lavinmq[51876]:   INFO<6> lmq.server Listening for MQTT on 127.0.0.1:1883
Feb 13 12:33:28 dev-frozen-toucan-01 lavinmq[51876]:   WARN<6> lmq.launcher Stopping
Feb 13 12:33:28 dev-frozen-toucan-01 lavinmq[51876]:   INFO<6> lmq.vhost[vhost: "/"] Closing connections
...

That warning should be <4>, logged here

Log.warn { "Stopping" }

@kickster97 kickster97 dismissed their stale review February 13, 2025 13:06

too quick to approve

src/lavinmq/log_formatter.cr Outdated Show resolved Hide resolved
src/lavinmq/log_formatter.cr Outdated Show resolved Hide resolved
@baelter baelter requested review from spuun, kickster97 and jage February 14, 2025 07:36
Copy link
Member

@spuun spuun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice with the JournalErrorWriter!

src/lavinmq/config.cr Outdated Show resolved Hide resolved
src/lavinmq/journal_error_writer.cr Show resolved Hide resolved
@baelter baelter requested review from spuun and jage February 14, 2025 13:21
@jage
Copy link
Member

jage commented Feb 14, 2025

Took the last build for a spin, much better!
Though the re-raised exception not handled byLog is still info.

3  lmq.vhost_store Failed to load vhosts
3  Failed to load vhosts (JSON::ParseException)
3    from usr/share/crystal/src/json/lexer.cr:116 in 'raise'
3    from usr/share/crystal/src/json/lexer.cr:330 in 'unexpected_char'
3    from usr/share/crystal/src/json/lexer.cr:326 in 'unexpected_char'
3    from usr/share/crystal/src/json/lexer/io_based.cr:11:21 in 'consume_number'
3    from usr/share/crystal/src/json/lexer.cr:63:7 in 'next_token'
3    from usr/share/crystal/src/json/lexer.cr:75:5 in 'parse_object'
3    from usr/share/crystal/src/json/parser.cr:37:7 in 'parse_value'
3    from usr/share/crystal/src/json/parser.cr:49:18 in 'parse_array'
3    from usr/share/crystal/src/json/parser.cr:37:7 in 'parse_value'
3    from usr/share/crystal/src/json/parser.cr:117:29 in 'parse'
3    from usr/share/crystal/src/json/any.cr:259:3 in 'initialize'
3    from usr/share/crystal/src/gc/boehm.cr:184:7 in 'start'
3    from usr/src/lavinmq_2.1.0-46-g23e21b5d/src/lavinmq/launcher.cr:76:9 in '__crystal_main'
3    from usr/share/crystal/src/crystal/main.cr:118:5 in 'main'
3    from usr/share/crystal/src/crystal/system/unix/main.cr:10:3 in 'main'
3    from /lib/aarch64-linux-gnu/libc.so.6 in '??'
3    from /lib/aarch64-linux-gnu/libc.so.6 in '__libc_start_main'
3    from /usr/bin/lavinmq in '_start'
3    from ???
6 Unhandled exception: Unexpected char 'b' at line 8, column 5 (JSON::ParseException)
6   from usr/share/crystal/src/json/lexer.cr:116 in 'raise'
6   from usr/share/crystal/src/json/lexer.cr:330 in 'unexpected_char'
6   from usr/share/crystal/src/json/lexer.cr:326 in 'unexpected_char'
6   from usr/share/crystal/src/json/lexer/io_based.cr:11:21 in 'consume_number'
6   from usr/share/crystal/src/json/lexer.cr:63:7 in 'next_token'
6   from usr/share/crystal/src/json/lexer.cr:75:5 in 'parse_object'
6   from usr/share/crystal/src/json/parser.cr:37:7 in 'parse_value'
6   from usr/share/crystal/src/json/parser.cr:49:18 in 'parse_array'
6   from usr/share/crystal/src/json/parser.cr:37:7 in 'parse_value'
6   from usr/share/crystal/src/json/parser.cr:117:29 in 'parse'
6   from usr/share/crystal/src/json/any.cr:259:3 in 'initialize'
6   from usr/share/crystal/src/gc/boehm.cr:184:7 in 'start'
6   from usr/src/lavinmq_2.1.0-46-g23e21b5d/src/lavinmq/launcher.cr:76:9 in '__crystal_main'
6   from usr/share/crystal/src/crystal/main.cr:118:5 in 'main'
6   from usr/share/crystal/src/crystal/system/unix/main.cr:10:3 in 'main'
6   from /lib/aarch64-linux-gnu/libc.so.6 in '??'
6   from /lib/aarch64-linux-gnu/libc.so.6 in '__libc_start_main'
6   from /usr/bin/lavinmq in '_start'
6   from ???
5 lavinmq.service: Main process exited, code=exited, status=1/FAILURE
4 lavinmq.service: Failed with result 'exit-code'.
3 Failed to start lavinmq.service - LavinMQ.
Screenshot 2025-02-14 at 15 25 37

@baelter
Copy link
Member Author

baelter commented Feb 14, 2025

humm, worked before jon suggestion :) I'll have a look....

@carlhoerberg
Copy link
Member

Another way is to use sd_journal_print(int priority, const char *format, ...); and write directly to systemd: https://www.man7.org/linux/man-pages/man3/sd_journal_print.3.html

@carlhoerberg
Copy link
Member

We can also set the default prioity level for stdout/stderr with the SyslogLevel directive in the [Service] section: https://www.freedesktop.org/software/systemd/man/latest/systemd.exec.html#SyslogLevel=

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants