logger

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2023 License: Apache-2.0 Imports: 4 Imported by: 2

README

The Logger Backend for Deck

The logger backend allows log messages to written to any io.Writer.

The logger backend supports all platforms.

Init

The logger backend takes two setup parameters, out and flags.

The out parameter must be an io.Writer. Log messages will be flushed directly to the io.Writer specified. An io.MultiWriter may be used here as well. Note that the logger backend does not close this Writer even if the user calls logger.Close(); it is up to the user to manage the io.Writer handle.

The flags parameter references one or more flag constants defined in Go's core log package. These flags can be used to modify the rendering of the log lines as they're written to the output. The default behavior is to use log.LstdFlags.

Attributes

deck.Depth

The logger package will attempt to make use of deck's core Depth attribute. This allows the caller to modify the call depth, which may affect the file names and line numbers rendered on the output, depending on which log flags are supplied during setup. If Depth isn't specified, logger tries to do the right thing and set depth to the original call site.

Usage

import (
  log
  github.com/google/deck
  github.com/google/deck/backends/logger
)

...

func main() {
  // Log to Stdout
  deck.Add(logger.Init(os.Stdout, log.LstdFlags))

  // Log to a file
  lf, err := os.OpenFile("/tmp/my_app.log", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0660)
  if err != nil {
      os.Exit(1)
  }
  defer lf.Close()
  deck.Add(logger.Init(lf, log.LstdFlags))
}

Documentation

Overview

Package logger provides a deck backend that leverages Go's core log package.

Index

Constants

This section is empty.

Variables

View Source
var (
	// TagDebug is the tag added to messages logged at the DEBUG level.
	TagDebug = "DEBUG: "
	// TagInfo is the tag added to messages logged at the INFO level.
	TagInfo = "INFO: "
	// TagWarning is the tag added to messages logged at the WARN level.
	TagWarning = "WARN: "
	// TagError is the tag added to messages logged at the ERROR level.
	TagError = "ERROR: "
	// TagFatal is the tag added to messages logged at the FATAL level.
	TagFatal = "FATAL: "
)

Functions

This section is empty.

Types

type Logger

type Logger struct {
	// contains filtered or unexported fields
}

Logger is a log deck backend that passes logs through to Go's core log package.

func Init

func Init(out io.Writer, flags int) *Logger

Init initializes the logger backend for use in a deck.

func (*Logger) Close

func (l *Logger) Close() error

Close closes the Logger backend. The io.Writer passed to Init() is not closed and must be closed by the caller.

func (*Logger) New

func (l *Logger) New(lvl deck.Level, msg string) deck.Composer

New creates a new logger message.

Jump to

Keyboard shortcuts

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