log

package module
v0.0.0-...-319a7dc Latest Latest
Warning

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

Go to latest
Published: May 20, 2018 License: Apache-2.0 Imports: 5 Imported by: 10

README

log

log is a wrapper for logrus Go logging package. To help debugging, log added source code information and function name to logrus output.

Example

The simple example for enabling debug level for DEBUG and set output to stdout.

package main

import (
  log "github.com/coreswitch/log"
)

func main() {
  log.SetLevel("debug")
  log.SetOutput("stdout")

  log.With("animal", "walrus").Info("A walrus appears")
}

The example set formatter to JSON.

package main

import (
  log "github.com/coreswitch/log"
)

func main() {
  log.SetLevel("debug")
  log.SetJSONFormatter()

  log.With("animal", "zebra").Debug("A zebra appears")
}

Source field and function field is configurable.

package main

import (
  log "github.com/coreswitch/log"
)

func main() {
  log.SourceField = false
  log.FuncField = false

  log.With("animal", "bird").Warn("A crow appears")
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var FuncField bool = true

Output function name to the log.

View Source
var SourceField bool = true

Output source file information "filename:line number" to the log.

Functions

func Debug

func Debug(args ...interface{})

func Debugf

func Debugf(format string, args ...interface{})

func Error

func Error(args ...interface{})

func Errorf

func Errorf(format string, args ...interface{})

func Info

func Info(args ...interface{})

func Infof

func Infof(format string, args ...interface{})

func SetJSONFormatter

func SetJSONFormatter()

func SetLevel

func SetLevel(level string) error

func SetOutput

func SetOutput(output string) error

func SetTextFormatter

func SetTextFormatter()

func Warn

func Warn(args ...interface{})

func Warnf

func Warnf(format string, args ...interface{})

Types

type Logger

type Logger interface {
	Debug(...interface{})
	Debugf(string, ...interface{})
	Info(...interface{})
	Infof(string, ...interface{})
	Warn(...interface{})
	Warnf(string, ...interface{})
	Error(...interface{})
	Errorf(string, ...interface{})
	With(key string, value interface{}) Logger
}

func With

func With(key string, value interface{}) Logger

Jump to

Keyboard shortcuts

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