Comments (15)
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.
@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.
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.
For now I'd probably recommend doing that, and then being explicit about making it the last hook.
from logrus.
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.
@mwhooker how are you going implement it?
from logrus.
@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.
Here's the published library. https://github.com/wercker/journalhook
happy to take comments
from logrus.
Thanks @mwhooker!
Added to README 4d9b4f0
from logrus.
It looks like this was removed from the readme.
Is there any particular reason? Is this still a valid approach?
from logrus.
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.
Yeah, I need the specific log levels implemented properly.
from logrus.
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.
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.
@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)
- Data race withFields() HOT 2
- v1.9.1 causes panic in writer
- How to change log level of all logrus loggers? HOT 2
- Skip debug level log from console output but should present in log file HOT 2
- CVE reported on logrus HOT 2
- How to Access IsDebugEnabled in FieldLogger? HOT 3
- can't build for wasm (go 1.21 rc) HOT 3
- Data race in hooks.test package HOT 3
- virter vm cp not working HOT 2
- Info requested: How to buffer messages and release at the end HOT 2
- Vulnerability of dependency "gopkg.in/yaml.v3" HOT 2
- Logrus potential DOS - Please open a CVE for issue #1370 to encourage users to patch HOT 3
- Feature: Add slog compatibility layer HOT 5
- logrus+lumberjackrus, After the old log is deleted, the hard drive will not be released, HOT 2
- Vulnerability: gopkg.in/yaml.v3 CVE-2022-28948 HOT 2
- Bazel compilation failling HOT 2
- Question: Any way to view the value of a field from a logrus.FieldLogger? HOT 2
- How to apply colours for a custom log format? HOT 2
- How to safely change Logger.Out on the fly? HOT 2
- How should I position my problem? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from logrus.