Skip to content

sdcio/logger

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

SDC logger

sdc logo

Usage Example

This package exposes functions to help with logging using the logr.Logger interface, mainly regarding context-based passing of the logger instance.

Any logging implementation which implements logr.Logger can be used, and there are many implementations which provide the logr.Logger interface (zapr, logr, ...).

It also contains a few preset log levels corresponding to levels provided by slog.

package main

import (
	"context"
	"log/slog"

	"github.com/go-logr/logr"
	logf "github.com/sdcio/logger"
)

func main() {
	log := logr.FromSlogHandler(slog.NewJSONHandler(os.Stdout, nil))
	logf.SetDefaultLogger(log)

	ctx := logf.IntoContext(context.Background(), log)

	log.Info("first log message", "key", "value")

    RunContext(ctx)

    log = log.WithValues("additionalkey", "key2")
    ctx = logf.IntoContext(ctx, log)
    RunContext(ctx)
}

func RunContext(ctx context.Context) {
    log := logf.FromContext(ctx)
    log.Info("log from context logger")
}

Join us

Have questions, ideas, bug reports or just want to chat? Come join our discord server.

License and Code of Conduct

Code is under the Apache License 2.0, documentation is CC BY 4.0.

The SDC project is following the CNCF Code of Conduct. More information and links about the CNCF Code of Conduct are here.

About

No description, website, or topics provided.

Resources

License

Apache-2.0, CC-BY-4.0 licenses found

Licenses found

Apache-2.0
LICENSE
CC-BY-4.0
LICENSE-documentation

Code of conduct

Security policy

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •  

Languages