Skip to content

A unified logging interface for Golang that supports multiple libraries.

License

Notifications You must be signed in to change notification settings

secureworks/logger

Repository files navigation

Secureworks Unified Logging Library

secureworks/logger is a unified interface that wraps popular logging libraries such as Logrus and Zerolog: and that is just the beginning!

This is the logging library used in SecureWorks Taegis™ XDR (Extended Detection and Response) Cloud Platform, and is suggested for use with the Taegis Golang SDK.

Installation

This library is broken into submodules that are linked together. You may download them separately, but the easiest thing to do is import whichever driver you want to use (logrus, zerolog, or testlogger), and these will include the dependencies you need:

$ go get -u github.com/secureworks/logger/logrus

If you want the middleware you would also need:

$ go get -u github.com/secureworks/logger/middleware

Alternatively, if your project is using Go modules then, reference the driver package(s) in a file's import:

import (
	// ...
	"github.com/secureworks/logger/middleware"
	_ "github.com/secureworks/logger/zerolog"
)

You may run any Go command and the toolchain will resolve and fetch the required modules automatically.

Usage

Documentation is available on pkg.go.dev. You may also look at the examples in the logger package.

FAQ

  • Why are there so many submodules / why do all the packages have go.mods?
    • We have broken the packages up in order to keep dependencies in line with the log implementations. If you want zerolog you shouldn't also need logrus; if you want to write code that consumes the shared interface you shouldn't need to depend on either implementation.
  • There are some packages with "safe" and "unsafe" versions of code. Why is this?
    • unsafe refers to using the Go standard library unsafe, which allows us to step outside of Go's type-safety rules. This code is no more "not safe" than a typical C program.
    • While we use the unsafe code (less type-safe) by default, this can be disabled by adding a safe or !unsafe build tag. This may be useful if you are building for an environment that does not allow unsafe (less type-safe) code.
    • For zerolog and logrus the unsafe code is used for a big performance boost.
    • For zerolog it also addresses a small behavior change in the zerolog.Hook interface. See this issue for more.

License

This library is distributed under the Apache-2.0 license found in the LICENSE file.

Dependencies

Library Purpose License
github.com/secureworks/errors Extracts error stack traces. BSD 2-Clause
github.com/rs/zerolog Logger. MIT
github.com/sirupsen/logrus Logger. MIT

As well as any transitive dependencies of the above.