stdlogimpl

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2021 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package stdlogimpl contains stdlib logger implementation of Logger interface.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewLogger

func NewLogger(logger *stdlog.Logger) log.Logger

NewLogger creates a new log.Logger from the provided stdlog.Logger. It prints the provided fields in "key=value" form after the message. NOTE: The prefix of a standard logger is used to print the logging level, so setting it before calling NewLogger will have no effect.

Example
package main

import (
	stdlog "log"
	"os"

	"github.com/junk1tm/log"

	"github.com/junk1tm/log/stdlogimpl"
)

func main() {
	// configure stdlog logger here:
	sl := stdlog.New(os.Stdout, "", 0)

	logger := stdlogimpl.NewLogger(sl)
	logger.Debug("example 1", log.Int("foo", 1))
	logger.Info("example 2", log.Int("bar", 2))
	logger.Error("example 3", log.Int("baz", 3))

}
Output:

[DEBUG] example 1 foo=1
[INFO] example 2 bar=2
[ERROR] example 3 baz=3

func Unwrap added in v0.2.0

func Unwrap(logger log.Logger) (*stdlog.Logger, bool)

Unwrap unwraps the provided logger, allowing access to the underlying stdlog.Logger. It returns true on success, false otherwise.

Example
package main

import (
	stdlog "log"
	"os"

	"github.com/junk1tm/log/stdlogimpl"
)

func main() {
	sl := stdlog.New(os.Stdout, "", 0)
	logger := stdlogimpl.NewLogger(sl)
	if _, ok := stdlogimpl.Unwrap(logger); ok {
		// use stdlog logger here:
	}
}

Types

This section is empty.

Jump to

Keyboard shortcuts

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