mirror of
https://github.com/goharbor/harbor.git
synced 2024-12-21 08:07:59 +01:00
39 lines
949 B
Markdown
39 lines
949 B
Markdown
|
# Syslog Hooks for Logrus <img src="http://i.imgur.com/hTeVwmJ.png" width="40" height="40" alt=":walrus:" class="emoji" title=":walrus:"/>
|
||
|
|
||
|
## Usage
|
||
|
|
||
|
```go
|
||
|
import (
|
||
|
"log/syslog"
|
||
|
"github.com/Sirupsen/logrus"
|
||
|
logrus_syslog "github.com/Sirupsen/logrus/hooks/syslog"
|
||
|
)
|
||
|
|
||
|
func main() {
|
||
|
log := logrus.New()
|
||
|
hook, err := logrus_syslog.NewSyslogHook("udp", "localhost:514", syslog.LOG_INFO, "")
|
||
|
|
||
|
if err == nil {
|
||
|
log.Hooks.Add(hook)
|
||
|
}
|
||
|
}
|
||
|
```
|
||
|
|
||
|
If you want to connect to local syslog (Ex. "/dev/log" or "/var/run/syslog" or "/var/run/log"). Just assign empty string to the first two parameters of `NewSyslogHook`. It should look like the following.
|
||
|
|
||
|
```go
|
||
|
import (
|
||
|
"log/syslog"
|
||
|
"github.com/Sirupsen/logrus"
|
||
|
logrus_syslog "github.com/Sirupsen/logrus/hooks/syslog"
|
||
|
)
|
||
|
|
||
|
func main() {
|
||
|
log := logrus.New()
|
||
|
hook, err := logrus_syslog.NewSyslogHook("", "", syslog.LOG_INFO, "")
|
||
|
|
||
|
if err == nil {
|
||
|
log.Hooks.Add(hook)
|
||
|
}
|
||
|
}
|
||
|
```
|