logger

package module
v0.0.0-...-b76d979 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2018 License: BSD-2-Clause Imports: 7 Imported by: 14

README

Logging framework for Integrity components

This logger components is used by Integrity components that logs output.

Based on Logrus.

It manages logger context and settings on a global level by using the package level functions.

Usage

package main

import (
  "github.com/brickchain/go-logger.v1"
  "os"
)

func main() {
  logger.SetOutput(os.Stdout)
  logger.SetFormatter("json")
  logger.SetLevel("debug")
  
  logger.AddContext("some_key", "some_value")
   
  localLogger := logger.WithField("my_local_key", "my_local_value")
  localLogger.Info("Test")
}

Documentation

Overview

Package logger is a wrapper for the Logrus logger package.

Logger is used by most Brickchain software to enable context based logging with details needed by each component.

Installation

# How to install logger
$ go get github.com/Brickchain/go-logger.v1

Example

logger.SetOutput(os.Stdout)
logger.SetFormatter("text")
logger.SetLevel("debug")
logger.AddContext("service", path.Base(os.Args[0]))
logger.AddContext("version", constant.Version)

logger.Infof("Running version %s", version)
logger.Error(err)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddContext

func AddContext(key string, value interface{})

AddContext adds another context to the logger

func Debug

func Debug(args ...interface{})

Debug is the wrapper for Logrus Debug()

func Debugf

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

Debugf is the wrapper for Logrus Debugf()

func Error

func Error(args ...interface{})

Error is the wrapper for Logrus Error()

func Errorf

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

Errorf is the wrapper for Logrus Errorf()

func Fatal

func Fatal(args ...interface{})

Fatal is the wrapper for Logrus Fatal()

func Fatalf

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

Fatalf is the wrapper for Logris Fatalf()

func GetLogger

func GetLogger() *logrus.Entry

GetLogger returns the context logger

func GetLoglevel

func GetLoglevel() string

GetLoglevel returns the current log level

func Info

func Info(args ...interface{})

Info is the wrapper for Logrus Info()

func Infof

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

Infof is the wrapper for Logrus Infof()

func SetFormatter

func SetFormatter(formatter string)

SetFormatter sets the formatter to be used, either "json" or "text"

func SetLevel

func SetLevel(level string)

SetLevel sets the lowest level to log

func SetLogrusFormatter

func SetLogrusFormatter(formatter logrus.Formatter)

SetLogrusFormatter sets the logrus formatter to be used

func SetOutput

func SetOutput(out io.Writer)

SetOutput sets the io.Writer to use

func Warn

func Warn(args ...interface{})

Warn is the wrapper for Logrus Warn()

func Warningf

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

Warningf is the wrapper for Logrus Warningf()

Types

type Entry

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

Entry contains a Logrus entry

func ForContext

func ForContext(ctx context.Context) *Entry

ForContext TODO docs

func WithField

func WithField(key string, value interface{}) *Entry

WithField adds another field to the logger entry context

func WithFields

func WithFields(fields Fields) *Entry

WithFields adds more Fields to the logger entry context

func (*Entry) AddField

func (e *Entry) AddField(key string, value interface{})

AddField adds a field to the current context

func (*Entry) Debug

func (e *Entry) Debug(args ...interface{})

Debug is the wrapper for Logrus Debug()

func (*Entry) Debugf

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

Debugf is the wrapper for Logrus Debugf()

func (*Entry) Error

func (e *Entry) Error(args ...interface{})

Error is the wrapper for Logrus Error()

func (*Entry) Errorf

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

Errorf is the wrapper for Logrus Errorf()

func (*Entry) Fatal

func (e *Entry) Fatal(args ...interface{})

Fatal is the wrapper for Logrus Fatal()

func (*Entry) Info

func (e *Entry) Info(args ...interface{})

Info is the wrapper for Logrus Info()

func (*Entry) Infof

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

Infof is the wrapper for Logrus Infof()

func (*Entry) Warn

func (e *Entry) Warn(args ...interface{})

Warn is the wrapper for Logrus Warn()

func (*Entry) Warningf

func (e *Entry) Warningf(format string, args ...interface{})

Warningf is the wrapper for Logrus Warninf()

func (*Entry) WithField

func (e *Entry) WithField(key string, value interface{}) *Entry

WithField adds another field to the Logrus entry context

func (*Entry) WithFields

func (e *Entry) WithFields(fields Fields) *Entry

WithFields adds more Fields to the Logrus entry context

type Fields

type Fields map[string]interface{}

Fields is a map of fields used by the logger

Jump to

Keyboard shortcuts

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