slog

package module
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 12, 2020 License: MIT Imports: 8 Imported by: 0

README

slog

A repo for slog

pkg.go.dev Version License

package main

import (
        "errors"
        "os"
        "go.seankhliao.com/slog"
)

func main() {
        l := slog.NewText(os.Stderr)
        l.Info("hello", "foo", "bar")
        l.Error(errors.New("an error"), "oops", "hello", "world")

        l = slog.NewJSON(os.Stderr)
        l.Info("hello", "foo", "bar")
        l.Error(errors.New("an error"), "oops", "hello", "world")

        http.Server{
                Errorlog: slog.StdLogger(l),
        }
}

output:

2020-10-12T21:46:13+02:00 INF msg="hello" foo="bar"
2020-10-12T21:46:13+02:00 ERR msg="oops" err="an error" hello="world"
{"time":"2020-10-12T21:46:13+02:00", "level":"INF", "msg":"hello", "foo":"bar"}
{"time":"2020-10-12T21:46:13+02:00", "level":"ERR", "msg":"oops", "err":"an error", "hello":"world"}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func StdLogger

func StdLogger(l Logger) *log.Logger

StdLogger returns a stdlib log.Logger for use with net/http.Server, etc. logging at INF level

Types

type JSON

type JSON lg

func (*JSON) Error

func (l *JSON) Error(err error, msg string, keyvalues ...interface{})

func (*JSON) Info

func (l *JSON) Info(msg string, keyvalues ...interface{})

type Logger

type Logger interface {
	Info(msg string, keyvalues ...interface{})
	Error(err error, msg string, keyvalues ...interface{})
}

func NewJSON

func NewJSON(w io.Writer) Logger

func NewText

func NewText(w io.Writer) Logger

type Text

type Text lg

func (*Text) Error

func (l *Text) Error(err error, msg string, keyvalues ...interface{})

func (*Text) Info

func (l *Text) Info(msg string, keyvalues ...interface{})

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL