Documentation ¶
Overview ¶
Package dietdog couples log.Logger from the standard library with the DataDog logs API.
Index ¶
Constants ¶
const DefaultIntakeEndpoint = "https://http-intake.logs.datadoghq.com/api/v2/logs"
DefaultIntakeEndpoint is a default endpoint to send logs
Variables ¶
This section is empty.
Functions ¶
func New ¶
func New(opts ...Option) *writer
New returns an io.WriteCloser which can be used as a log.Logger underlying writer. It buffers logged messages and submits them to the DataDog logs API endpoint.
To get it working, you need to create a new writer providing an API key:
sink := dietdog.New(dietdog.WithAuth(apiKey)) defer sink.Close() logger := log.New(io.MultiWriter(os.Stderr, sink), "", 0) logger.Println("Hello, world!")
When used without an API key, writes to it become no-op.
On a high log rate writes may occasionally block until the background log consumer catches up.
To release resouces and trigger the unsubmitted logs delivery, call its Close method. Be careful not to call Fatal* and Panic* methods of its parent Logger. Because this package delivers logs to DataDog asynchronously, it won't have time to deliver those final messages, because Fatal* and Panic* methods terminate the program.
Types ¶
type Metadata ¶
type Metadata struct { Tags string // ddtags Source string // ddsource Service string // service Hostname string // hostname }
Metadata describes additional fields of a log message. See DataDog API documentation for more details.
type Option ¶
type Option func(*config)
Options customize behavior of this package.
func WithEndpoint ¶
WithEndpoint overrides which endpoint logs are sent to.
func WithLogger ¶
WithLogger configures writer with an additional logger to log its own errors to. Some errors it may log include: failed delivery attempts, dropped messages because of internal queue overflow.
Be careful not to provide Logger that you plan to reconfigure to write to this writer. Such configuration may eventually result in a deadlock.
It is recommended to use a dedicated logger with a custom prefix:
sink := dietdog.New(dietdog.WithAuth(apiKey), dietdog.WithLogger(log.New(os.Stderr, "DataDog logging: ", 0)))
func WithMetadata ¶
WithMetadata adds additional metatada to every log message sent.