lagerflags

package
v3.0.3 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2023 License: Apache-2.0, Apache-2.0 Imports: 6 Imported by: 72

README

lagerflags

Note: This repository should be imported as code.cloudfoundry.org/lager/lagerflags.

This library provides a flag called logLevel. The logger returned by lagerflags.New() will use the value of that flag to determine the log level.

To use, simply import this package in your main.go and call lagerflags.New(COMPONENT_NAME) to get a logger.

For example:

package main

import (
    "flag"
    "fmt"

    "code.cloudfoundry.org/lager/v3/lagerflags"
    "code.cloudfoundry.org/lager/v3"
)

func main() {
    lagerflags.AddFlags(flag.CommandLine)

    flag.Parse()

    logger, reconfigurableSink := lagerflags.New("my-component")
    logger.Info("starting")

    // Display the current minimum log level
    fmt.Printf("Current log level is ")
    switch reconfigurableSink.GetMinLevel() {
    case lager.DEBUG:
        fmt.Println("debug")
    case lager.INFO:
        fmt.Println("info")
    case lager.ERROR:
        fmt.Println("error")
    case lager.FATAL:
        fmt.Println("fatal")
    }

    // Change the minimum log level dynamically
    reconfigurableSink.SetMinLevel(lager.ERROR)
    logger.Debug("will-not-log")
}

Running the program above as go run main.go --logLevel debug will generate the following output:

{"timestamp":"1464388983.540486336","source":"my-component","message":"my-component.starting","log_level":1,"data":{}}
Current log level is debug

Documentation

Index

Constants

View Source
const (
	DEBUG = "debug"
	INFO  = "info"
	ERROR = "error"
	FATAL = "fatal"
)

Variables

This section is empty.

Functions

func AddFlags

func AddFlags(flagSet *flag.FlagSet)

func New

func New(component string) (lager.Logger, *lager.ReconfigurableSink)

func NewFromConfig

func NewFromConfig(component string, config LagerConfig) (lager.Logger, *lager.ReconfigurableSink)

func NewFromSink

func NewFromSink(component string, sink lager.Sink) (lager.Logger, *lager.ReconfigurableSink)

Types

type LagerConfig

type LagerConfig struct {
	LogLevel            string     `json:"log_level,omitempty"`
	RedactSecrets       bool       `json:"redact_secrets,omitempty"`
	RedactPatterns      []string   `json:"redact_patterns,omitempty"`
	TimeFormat          TimeFormat `json:"time_format"`
	MaxDataStringLength int        `json:"max_data_string_length"`
}

func ConfigFromFlags

func ConfigFromFlags() LagerConfig

func DefaultLagerConfig

func DefaultLagerConfig() LagerConfig

type RedactPatterns

type RedactPatterns []string

func (*RedactPatterns) Set

func (p *RedactPatterns) Set(value string) error

func (*RedactPatterns) String

func (p *RedactPatterns) String() string

type TimeFormat

type TimeFormat int
const (
	FormatUnixEpoch TimeFormat = iota
	FormatRFC3339
)

func (TimeFormat) Get

func (t TimeFormat) Get(s string) interface{}

Set implements the flag.Getter interface

func (TimeFormat) MarshalJSON

func (t TimeFormat) MarshalJSON() ([]byte, error)

func (*TimeFormat) Set

func (t *TimeFormat) Set(s string) error

Set implements the flag.Value interface

func (TimeFormat) String

func (t TimeFormat) String() string

func (*TimeFormat) UnmarshalJSON

func (t *TimeFormat) UnmarshalJSON(data []byte) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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