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

Feature: journal output option #2

Closed
philips opened this issue Sep 17, 2013 · 12 comments
Closed

Feature: journal output option #2

philips opened this issue Sep 17, 2013 · 12 comments

Comments

@philips
Copy link

philips commented Sep 17, 2013

This might be a nice thing to add- a JournalLogger class:

https://github.com/systemd/python-systemd

Cool project! I wish I used more Python so I could make use of it.

@hynek
Copy link
Owner

hynek commented Sep 18, 2013

What exactly would be necessary for that? I have no access to a systemd system but wouldn’t it just require a convenience factory? The examples look like there is no need for adapting/formatting at all.

@cjw296
Copy link
Sponsor

cjw296 commented Oct 11, 2016

I bet you do by now ;-)

@hynek
Copy link
Owner

hynek commented Oct 13, 2016

Almost! :) We’re in the process of upgrading to Xenial and logging is a part of that. I hope to get around this ASAP.

@cjw296
Copy link
Sponsor

cjw296 commented Oct 13, 2016

@hynek - glad to see you're alive, tried to say hi on irc but tumbleweed...

@hynek
Copy link
Owner

hynek commented Oct 13, 2016

heh just came back from PyCon ZA

@paravoid
Copy link

Daiquiri's JournalHandler code is a good example of how that could be done. It's 38 lines of code, so it's not that complicated.

Essentially it boils down to just journal.send(message, {"KEY1": "value1", "KEY2": "value2"}, but with the quirk that it needs uppercase keys, and that there are some special well-known keys (like PRIORITY) that would be good to support.

@paravoid
Copy link

Also, the systemd module provides a logging.handler JournalHandler that is reasonable. So one can rely on the logging module for this.

This example is gross, but works:

    logging.basicConfig(format="%(message)s", handlers=(systemd.journal.JournalHandler(),))
    structlog.configure(
        processors=[
            structlog.stdlib.add_log_level,
            lambda _, __, d: {k.upper() if k != "event" else k: v for k, v in d.items()},
            structlog.stdlib.render_to_log_kwargs,
        ],
        context_class=structlog.threadlocal.wrap_dict(dict),
        logger_factory=structlog.stdlib.LoggerFactory(),
        wrapper_class=structlog.stdlib.BoundLogger,
    )

@hynek
Copy link
Owner

hynek commented Feb 29, 2020

I wonder if we should add this to http://www.structlog.org/en/stable/logging-best-practices.html?

@hynek
Copy link
Owner

hynek commented Oct 9, 2023

At this point I think this should be an external package. I don't care about this, it adds a dependency, and the headaches I have from standard library logging are bad enough.

I'll be happy to help anyone, who would like to tackle that.

@hynek hynek closed this as not planned Won't fix, can't repro, duplicate, stale Oct 9, 2023
@andrewshadura
Copy link

andrewshadura commented Oct 9, 2023 via email

@hynek
Copy link
Owner

hynek commented Oct 9, 2023

Right let it put me this way then: If someone shows up with a good PR that doesn't introduce too much complexity, I will consider merging it. Either way, if someone cares enough, they can publish it separately if I decline, so there's no risk to do work in vain.

I do not want to have it in my public todo list anymore, though.

@hynek
Copy link
Owner

hynek commented Oct 9, 2023

Oh and one last thing: in my other projects I've started experimenting with GitHub discussions which is a bit better medium for cases like this. If y'all who care about this want to talk/coordinate you can of course do it here; I'm not locking the issue. But I could also be convinced to activate Discussions for structlog. I don't want to stop anyone from communicating; I just want to manage my blood pressure.

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

No branches or pull requests

5 participants