atc0005 / learn

Various topics that I want to learn more about, either for professional development or for my own use
0 stars 0 forks source link

Golang's Logging Packages #37

Open atc0005 opened 5 years ago

atc0005 commented 5 years ago

Background

According to the Go developers, they have no plans to further develop the log/syslog package:

We have no plans to further develop the log/syslog package in the standard library.

We welcome the community to fork it and give it features elsewhere. It was probably a mistake putting it in the standard library to begin with.

Need to do some additional research and determine which logging packages are approachable to a newbie like myself, but still offer enough flexibility to work with the systems that I interact with on a routine basis.

Preferences

Packages that I explore and use will ideally have support for these features:

atc0005 commented 5 years ago

https://github.com/go-kit/kit/blob/master/log/README.md

provides a minimal interface for structured logging in services. It may be wrapped to encode conventions, enforce type-safety, provide leveled logging, and so on. It can be used for both typical application log events, and log-structured data streams.

I didn't see syslog support mentioned, but I've not dug very far into the feature list.

EDIT: Looks like syslog support is included?

https://godoc.org/github.com/go-kit/kit/log/syslog

atc0005 commented 5 years ago

https://github.com/RackSec/srslog

The repo is marked read-only; presumably the project has been abandoned?

atc0005 commented 5 years ago

Logrus is a structured logger for Go (golang), completely API compatible with the standard library logger.

You can add hooks for logging levels. For example to send errors to an exception tracking service on Error, Fatal and Panic, info to StatsD or log to multiple places simultaneously, e.g. syslog.

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.

import (
  "log/syslog"
  "github.com/sirupsen/logrus"
  lSyslog "github.com/sirupsen/logrus/hooks/syslog"
)

func main() {
  log       := logrus.New()
  hook, err := lSyslog.NewSyslogHook("", "", syslog.LOG_INFO, "")

  if err == nil {
    log.Hooks.Add(hook)
  }
}
atc0005 commented 5 years ago

https://github.com/golang/glog