Skip to content
Node: winston, pinogithub.com/sahilkhaire/gox/log

Logger.NewWithLevel

Overview

NewWithLevel returns a Logger at the given level.

Part of the log package — Node.js analog: winston, pino.

Method on Logger — call it on a value of that type after constructing or receiving one from a constructor.

Signature

go
func NewWithLevel(level slog.Level) *Logger

Compare: Node.js · Standard Go · gox

js
// Typical winston, pino pattern in Node.js
go
logger := slog.New(slog.NewJSONHandler(os.Stdout, nil))
logger.Info("msg", "key", val)
go
import "github.com/sahilkhaire/gox/log"

l := NewWithLevel(slog.LevelError)

Example

go
import "github.com/sahilkhaire/gox/log"

l := NewWithLevel(slog.LevelError)

Tips

Obtain a Logger value first (see constructors on the package overview), then call NewWithLevel.

Standard library alternative

Use the standard library directly:

go
logger := slog.New(slog.NewJSONHandler(os.Stdout, nil))
logger.Info("msg", "key", val)

Back to log package overview

MIT Licensed · Built for Node.js developers moving to Go