fabric-sdk-go: github.com/hyperledger/fabric-sdk-go/pkg/common/logging Index | Examples | Files

package logging

import "github.com/hyperledger/fabric-sdk-go/pkg/common/logging"

Package logging enables setting custom logger implementation.

Basic Flow:
1) Initialize logger
2) Create new logger for specific module
3) Call log info

Code:

Initialize(testdata.GetSampleLoggingProvider(&buf))
//Create new logger
logger := NewLogger(modName)

logger.Info("log test data")

fmt.Println("log info is completed")

Output:

log info is completed

Index

Examples

Package Files

logger.go

func Initialize Uses

func Initialize(l api.LoggerProvider)

Initialize sets new logger which takes over logging operations. It is required to call this function before making any loggings.

Code:

Initialize(testdata.GetSampleLoggingProvider(&buf))

fmt.Println("log is completed")

Output:

log is completed

func IsEnabledFor Uses

func IsEnabledFor(module string, level Level) bool

IsEnabledFor - Check if given log level is enabled for given module

Parameters:
module is module name
level is logging level

Returns:
is logging enabled for this module and level

Code:

Initialize(testdata.GetSampleLoggingProvider(&buf))

isEnabled := IsEnabledFor(modName, DEBUG)

if !isEnabled {
    fmt.Println("log level debug is enabled")
    return
}

fmt.Println("log is completed")

Output:

log is completed

func SetLevel Uses

func SetLevel(module string, level Level)

SetLevel - setting log level for given module

Parameters:
module is module name
level is logging level

Code:

Initialize(testdata.GetSampleLoggingProvider(&buf))

SetLevel(modName, INFO)

fmt.Println("log is completed")

Output:

log is completed

type Level Uses

type Level int

Level defines all available log levels for log messages.

const (
    CRITICAL Level = iota
    ERROR
    WARNING
    INFO
    DEBUG
)

Log levels.

func GetLevel Uses

func GetLevel(module string) Level

GetLevel - getting log level for given module

Parameters:
module is module name

Returns:
logging level

Code:

Initialize(testdata.GetSampleLoggingProvider(&buf))

SetLevel(modName, DEBUG)

l := GetLevel(modName)
if l != DEBUG {
    fmt.Println("log level is not debug")
    return
}

fmt.Println("log is completed")

Output:

log is completed

func LogLevel Uses

func LogLevel(level string) (Level, error)

LogLevel returns the log level from a string representation.

Parameters:
level is logging level in string representation

Returns:
logging level

Code:

Initialize(testdata.GetSampleLoggingProvider(&buf))

level, err := LogLevel("debug")
if err != nil {
    fmt.Printf("failed LogLevel: %s\n", err)
    return
}

if level != DEBUG {
    fmt.Println("log level is not debug")
    return
}
fmt.Println("log is completed")

Output:

log is completed

type Logger Uses

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

Logger basic implementation of api.Logger interface

func NewLogger Uses

func NewLogger(module string) *Logger

NewLogger creates and returns a Logger object based on the module name.

Code:

Initialize(testdata.GetSampleLoggingProvider(&buf))
//Create new logger
NewLogger(modName)

fmt.Println("log is completed")

Output:

log is completed

func (*Logger) Debug Uses

func (l *Logger) Debug(args ...interface{})

Debug calls Debug function of underlying logger

func (*Logger) Debugf Uses

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

Debugf calls Debugf function of underlying logger

func (*Logger) Debugln Uses

func (l *Logger) Debugln(args ...interface{})

Debugln calls Debugln function of underlying logger

func (*Logger) Error Uses

func (l *Logger) Error(args ...interface{})

Error calls Error function of underlying logger

func (*Logger) Errorf Uses

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

Errorf calls Errorf function of underlying logger

func (*Logger) Errorln Uses

func (l *Logger) Errorln(args ...interface{})

Errorln calls Errorln function of underlying logger

func (*Logger) Fatal Uses

func (l *Logger) Fatal(args ...interface{})

Fatal calls Fatal function of underlying logger

func (*Logger) Fatalf Uses

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

Fatalf calls Fatalf function of underlying logger

func (*Logger) Fatalln Uses

func (l *Logger) Fatalln(args ...interface{})

Fatalln calls Fatalln function of underlying logger

func (*Logger) Info Uses

func (l *Logger) Info(args ...interface{})

Info calls Info function of underlying logger

func (*Logger) Infof Uses

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

Infof calls Infof function of underlying logger

func (*Logger) Infoln Uses

func (l *Logger) Infoln(args ...interface{})

Infoln calls Infoln function of underlying logger

func (*Logger) Panic Uses

func (l *Logger) Panic(args ...interface{})

Panic calls Panic function of underlying logger

func (*Logger) Panicf Uses

func (l *Logger) Panicf(format string, args ...interface{})

Panicf calls Panicf function of underlying logger

func (*Logger) Panicln Uses

func (l *Logger) Panicln(args ...interface{})

Panicln calls Panicln function of underlying logger

func (*Logger) Print Uses

func (l *Logger) Print(args ...interface{})

Print calls Print function of underlying logger

func (*Logger) Printf Uses

func (l *Logger) Printf(format string, args ...interface{})

Printf calls Printf function of underlying logger

func (*Logger) Println Uses

func (l *Logger) Println(args ...interface{})

Println calls Println function of underlying logger

func (*Logger) Warn Uses

func (l *Logger) Warn(args ...interface{})

Warn calls Warn function of underlying logger

func (*Logger) Warnf Uses

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

Warnf calls Warnf function of underlying logger

func (*Logger) Warnln Uses

func (l *Logger) Warnln(args ...interface{})

Warnln calls Warnln function of underlying logger

Package logging imports 4 packages (graph) and is imported by 59 packages. Updated 2018-06-06. Refresh now. Tools for package owners.