GithubHelp home page GithubHelp logo

systemd journal support about logrus HOT 15 CLOSED

sirupsen avatar sirupsen commented on May 22, 2024
systemd journal support

from logrus.

Comments (15)

sirupsen avatar sirupsen commented on May 22, 2024 1

Doesn't systemd journal just fine from stdout/stderr? Is the advantage of using the API directly performance for super logging heavy applications, or what's your use-case?

from logrus.

pquerna avatar pquerna commented on May 22, 2024

@sirupsen: So, strictly speaking, systemd's journal can consume stdout / stderr, but it can also understand structure logs, eg sd_journal_send with key/values, and you can search the journal based on any key/value, and it can print them as JSON:

http://0pointer.de/blog/projects/journal-submit.html

from logrus.

sirupsen avatar sirupsen commented on May 22, 2024

For syslog we actually have it as a hook, but still log to stdout/stderr. Is the simplest approach here to pass an io.Writer to logrus that does nothing, rendering the formatter useless, and then using a hook?

Actually... that's not really great either, because hooks are fired before the formatter and ordering is not guaranteed so it quickly turns into a hack.

hm

from logrus.

sirupsen avatar sirupsen commented on May 22, 2024

For now I'd probably recommend doing that, and then being explicit about making it the last hook.

from logrus.

mwhooker avatar mwhooker commented on May 22, 2024

going to be implementing this internally. The use-case for us is journald will only read up to LINE_MAX characters per line, and our lines are a bit longer. LMK if anyone's interested and will see about open sourcing it.

from logrus.

sirupsen avatar sirupsen commented on May 22, 2024

@mwhooker how are you going implement it?

from logrus.

mwhooker avatar mwhooker commented on May 22, 2024

@sirupsen it's actually pretty simple

func (hook *JournaldHook) Fire(entry *logrus.Entry) error {
    return journal.Send(entry.Message, severityMap[entry.Level], stringifyEntries(entry.Data))
}

where stringifyEntries has the signature func stringifyEntries(data map[string]interface{}) map[string]string

I didn't see the same points above about wanting a formatter since journal wants a string message and a map of key/values.

We also have to log.SetOutput(ioutil.Discard)

from logrus.

mwhooker avatar mwhooker commented on May 22, 2024

Here's the published library. https://github.com/wercker/journalhook

happy to take comments

from logrus.

sirupsen avatar sirupsen commented on May 22, 2024

Thanks @mwhooker!

Added to README 4d9b4f0

from logrus.

pauldotknopf avatar pauldotknopf commented on May 22, 2024

It looks like this was removed from the readme.

Is there any particular reason? Is this still a valid approach?

from logrus.

davidnorthetal avatar davidnorthetal commented on May 22, 2024

you can use stdout / stderr with systemd but systemd doesn't set the log-level accordingly
i.e. both stdout / stderr messages always have the same log-level for systemd

to circumvent that you have to do syslog or direct systemd journal logging

from logrus.

pauldotknopf avatar pauldotknopf commented on May 22, 2024

Yeah, I need the specific log levels implemented properly.

from logrus.

gsauthof avatar gsauthof commented on May 22, 2024

pauldotknopf wrote:

It looks like this was removed from the readme.

Is there any particular reason? Is this still a valid approach?

Well, the readme now links to a long hook list in the wiki which still includes the original systemd journald hook link.

I presume that at some point the hook list was moved to a separate page because it grew to long.

from logrus.

potuz avatar potuz commented on May 22, 2024

I couldn't find a proper place to ask for help so I figured I'll try in this issue since the hook page is archived. Using the journalhook with logs with fields like in

log.WithFields(logrus.Fields{
                "att":      att,
                "dep":          dep,
                "lenatt": len(att),
        }).Info("Finished adding att")

Logging with the journalhook I'll see the message "Finshed adding att" but would not get the fields.

from logrus.

gguridi avatar gguridi commented on May 22, 2024

@potuz the problem relies on the journalhook hook that you are using. If it's the same as the wiki references then the problem is that the code is old and the Fire method is not using any formatter but directly sending the message only to the journal.

If you can't find another journalhook that uses the formatter, then copy that hook code into your project and make it use the formatter in your Fire method, like:

func (hook *JournalHook) Fire(entry *logrus.Entry) error {
        message, err := entry.String()
	if err == nil {
		return journal.Send(message, severityMap[entry.Level], stringifyEntries(entry.Data))
	}
	return err
}

Logrus is not responsible for hooks not using the formatters.

from logrus.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.