logging

package
v2.11.26 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetupLogger

func SetupLogger(ctx context.Context, w io.Writer) context.Context

SetupLogger returns a context with a logger setup on it.

Example
package main

import (
	"context"
	"os"

	configlogging "github.com/google/kf/v2/pkg/kf/commands/config/logging"
	"go.uber.org/zap"
	"knative.dev/pkg/logging"
)

func main() {
	logger := logging.FromContext(configlogging.SetupLogger(context.Background(), os.Stdout))

	logger.Debug("debug message")
	logger.Info("info message")
	logger.Warn("warning message")
	logger.Error("error message")
	logger.With(zap.Namespace("some namespace")).Info("info message with namespace")
	logger.With(zap.String("some key", "some value")).Debug("debug message with key/value")
	logger.With(zap.Namespace("ns1")).With(zap.Namespace("ns2")).Info("info message with multiple namespaces")

}
Output:

DEBUG debug message
info message
WARN warning message
ERROR error message
[some namespace] info message with namespace
DEBUG [some key/some value] debug message with key/value
[ns1] [ns2] info message with multiple namespaces

Types

This section is empty.

Jump to

Keyboard shortcuts

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