
Security News
The Changelog Podcast: Practical Steps to Stay Safe on npm
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.
github.com/LuisAntezana/logrus-hooks
Advanced tools
Logrus is a popular structured logger that allows to add hooks that are invoked for every message. These hooks can be used to send the messages to remote tracking and reporting system. Things may go wrong when talking to remote systems, like delays and errors.
The hooks from this package are decorators that help to deal with:
The examples will use the syslog hook to send messages to syslog daemon. The setup looks like this:
import (
"log/syslog"
"github.com/misho-kr/logrus-hooks"
"github.com/sirupsen/logrus"
lSyslog "github.com/sirupsen/logrus/hooks/syslog"
)
func init() {
// create a hook to be added to an instance of logger
hook, err := NewSyslogHook("udp", "server.fqdn:514", syslog.LOG_DEBUG, "")
}
From here additional hooks can be added for enhanced logging functionality.
Prevent transient errors from procesing the log messages with retries
log.AddHook(RetryHook(
hook,
100 * time.Millisecond, // delay between retries
hooks.Retries(3), // retry 3 times
hooks.FactorPct(100), // increase delay by 100% between retries
hooks.JitterPct(10), // jitter of 10% to the delay between retries
))
Put a cap on the number of logging messages per time interval
log.AddHook(RateLimitHook(
hook,
hooks.PerSecond(10), // 10 messages per second
hooks.Burst(20), // burst of 20 messages allowed
))
Fire the hook in separate goroutine to avoid blocking the logger and main application
log.AddHook(AsyncHook(
hook,
hooks.Senders(10), // 10 goroutines to send messages
hooks.BoostSenders(20), // up to 20 additional goroutines when needed
))
FAQs
Unknown package
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.

Security News
Ruby's creator Matz assumes control of RubyGems and Bundler repositories while former maintainers agree to step back and transfer all rights to end the dispute.