btclog

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

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

Go to latest
Published: Feb 7, 2015 License: ISC Imports: 5 Imported by: 6

README

btclog

[Build Status] (https://travis-ci.org/conformal/btclog)

Package btclog implements a subsystem aware logger backed by seelog.

Seelog allows you to specify different levels per backend such as console and file, but it doesn't support levels per subsystem well. You can create multiple loggers, but when those are backed by a file, they have to go to different files. That is where this package comes in. It provides a SubsystemLogger which accepts the backend seelog logger to do the real work. Each instance of a SubsystemLogger then allows you specify (and retrieve) an individual level per subsystem. All messages are then passed along to the backend seelog logger.

Documentation

Full go doc style documentation for the project can be viewed online without installing this package by using the GoDoc site here: http://godoc.org/github.com/btcsuite/btclog

You can also view the documentation locally once the package is installed with the godoc tool by running godoc -http=":6060" and pointing your browser to http://localhost:6060/pkg/github.com/btcsuite/btclog

Installation

$ go get github.com/btcsuite/btclog

GPG Verification Key

All official release tags are signed by Conformal so users can ensure the code has not been tampered with and is coming from Conformal. To verify the signature perform the following:

  • Download the public key from the Conformal website at https://opensource.conformal.com/GIT-GPG-KEY-conformal.txt

  • Import the public key into your GPG keyring:

    gpg --import GIT-GPG-KEY-conformal.txt
    
  • Verify the release tag with the following command where TAG_NAME is a placeholder for the specific tag:

    git tag -v TAG_NAME
    

License

Package btclog is licensed under the liberal ISC License.

Documentation

Overview

Package btclog implements a subsystem aware logger backed by seelog.

Seelog allows you to specify different levels per backend such as console and file, but it doesn't support levels per subsystem well. You can create multiple loggers, but when those are backed by a file, they have to go to different files. That is where this package comes in. It provides a SubsystemLogger which accepts the backend seelog logger to do the real work. Each instance of a SubsystemLogger then allows you specify (and retrieve) an individual level per subsystem. All messages are then passed along to the backend seelog logger.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewDefaultBackendLogger

func NewDefaultBackendLogger() seelog.LoggerInterface

NewDefaultBackendLogger returns a new seelog logger with default settings that can be used as a backend for SubsystemLoggers.

Types

type LogLevel

type LogLevel uint8

LogLevel is the level at which a logger is configured. All messages sent to a level which is below the current level are filtered.

const (
	TraceLvl LogLevel = iota
	DebugLvl
	InfoLvl
	WarnLvl
	ErrorLvl
	CriticalLvl
	Off
)

LogLevel contants.

func LogLevelFromString

func LogLevelFromString(level string) (LogLevel, bool)

LogLevelFromString returns a LogLevel given a string representation of the level along with a boolean that indicates if the provided string could be converted.

func (LogLevel) String

func (level LogLevel) String() string

String converts level to a human-readable string.

type Logger

type Logger interface {
	// Tracef formats message according to format specifier and writes to
	// to log with TraceLvl.
	Tracef(format string, params ...interface{})

	// Debugf formats message according to format specifier and writes to
	// log with DebugLvl.
	Debugf(format string, params ...interface{})

	// Infof formats message according to format specifier and writes to
	// log with InfoLvl.
	Infof(format string, params ...interface{})

	// Warnf formats message according to format specifier and writes to
	// to log with WarnLvl.
	Warnf(format string, params ...interface{}) error

	// Errorf formats message according to format specifier and writes to
	// to log with ErrorLvl.
	Errorf(format string, params ...interface{}) error

	// Criticalf formats message according to format specifier and writes to
	// log with CriticalLvl.
	Criticalf(format string, params ...interface{}) error

	// Trace formats message using the default formats for its operands
	// and writes to log with TraceLvl.
	Trace(v ...interface{})

	// Debug formats message using the default formats for its operands
	// and writes to log with DebugLvl.
	Debug(v ...interface{})

	// Info formats message using the default formats for its operands
	// and writes to log with InfoLvl.
	Info(v ...interface{})

	// Warn formats message using the default formats for its operands
	// and writes to log with WarnLvl.
	Warn(v ...interface{}) error

	// Error formats message using the default formats for its operands
	// and writes to log with ErrorLvl.
	Error(v ...interface{}) error

	// Critical formats message using the default formats for its operands
	// and writes to log with CriticalLvl.
	Critical(v ...interface{}) error

	// Level returns the current logging level.
	Level() LogLevel

	// SetLevel changes the logging level to the passed level.
	SetLevel(level LogLevel)

	// Close the logger.  Any future log messages will be ignored.
	Close()
}

Logger is an interface which describes a level-based logger.

var Disabled Logger = &SubsystemLogger{level: Off}

Disabled is a default logger that can be used to disable all logging output. The level must not be changed since it's not backed by a real logger.

func NewLoggerFromWriter

func NewLoggerFromWriter(w io.Writer, minLevel LogLevel) (Logger, error)

NewLoggerFromWriter creates a logger for use with non-btclog based systems.

func NewSubsystemLogger

func NewSubsystemLogger(logger seelog.LoggerInterface, prefix string) Logger

NewSubsystemLogger returns a new SubsystemLogger backed by logger with prefix before all logged messages at the default log level. See SubsystemLogger for more details.

type SubsystemLogger

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

SubsystemLogger is a concrete implementation of the Logger interface which provides a level-base logger backed by a single seelog instance suitable for use by subsystems (and packages) in an overall application. It allows a logger instance per subsystem to be created so each can have its own logging level and a prefix which identifies which subsystem the message is coming from. Each instance is backed by a provided seelog instance which typically is the same instance for all subsystems, so it doesn't interfere with ability to do things create splitters which log to the console and a file.

func (*SubsystemLogger) Close

func (l *SubsystemLogger) Close()

Close closes the subsystem logger so no further messages are logged. It does NOT close the underlying seelog logger as it will likely be used by other subsystem loggers. Closing the underlying seelog logger is the responsibility of the caller.

This is part of the Logger interface implementation.

func (*SubsystemLogger) Critical

func (l *SubsystemLogger) Critical(v ...interface{}) error

Critical formats message using the default formats for its operands, prepends the prefix (if there is one), and writes to log with CriticalLvl.

This is part of the Logger interface implementation.

func (*SubsystemLogger) Criticalf

func (l *SubsystemLogger) Criticalf(format string, params ...interface{}) error

Criticalf formats message according to format specifier, prepends the prefix (if there is one), and writes to log with CriticalLvl.

This is part of the Logger interface implementation.

func (*SubsystemLogger) Debug

func (l *SubsystemLogger) Debug(v ...interface{})

Debug formats message using the default formats for its operands, prepends the prefix (if there is one), and writes to log with DebugLvl.

This is part of the Logger interface implementation.

func (*SubsystemLogger) Debugf

func (l *SubsystemLogger) Debugf(format string, params ...interface{})

Debugf formats message according to format specifier, prepends the prefix (if there is one), and writes to log with DebugLvl.

This is part of the Logger interface implementation.

func (*SubsystemLogger) Error

func (l *SubsystemLogger) Error(v ...interface{}) error

Error formats message using the default formats for its operands, prepends the prefix (if there is one), and writes to log with ErrorLvl.

This is part of the Logger interface implementation.

func (*SubsystemLogger) Errorf

func (l *SubsystemLogger) Errorf(format string, params ...interface{}) error

Errorf formats message according to format specifier, prepends the prefix (if there is one) and writes to log with ErrorLvl.

This is part of the Logger interface implementation.

func (*SubsystemLogger) Info

func (l *SubsystemLogger) Info(v ...interface{})

Info formats message using the default formats for its operands, prepends the prefix (if there is one), and writes to log with InfoLvl.

This is part of the Logger interface implementation.

func (*SubsystemLogger) Infof

func (l *SubsystemLogger) Infof(format string, params ...interface{})

Infof formats message according to format specifier, prepends the prefix (if there is one) and writes to log with InfoLvl.

This is part of the Logger interface implementation.

func (*SubsystemLogger) Level

func (l *SubsystemLogger) Level() LogLevel

Level returns the current logging level.

This is part of the Logger interface implementation.

func (*SubsystemLogger) SetLevel

func (l *SubsystemLogger) SetLevel(level LogLevel)

SetLevel changes the logging level to the passed level.

This is part of the Logger interface implementation.

func (*SubsystemLogger) Trace

func (l *SubsystemLogger) Trace(v ...interface{})

Trace formats message using the default formats for its operands, prepends the prefix (if there is one), and writes to log with TraceLvl.

This is part of the Logger interface implementation.

func (*SubsystemLogger) Tracef

func (l *SubsystemLogger) Tracef(format string, params ...interface{})

Tracef formats message according to format specifier, prepends the prefix (if there is one), and writes to log with TraceLvl.

This is part of the Logger interface implementation.

func (*SubsystemLogger) Warn

func (l *SubsystemLogger) Warn(v ...interface{}) error

Warn formats message using the default formats for its operands, prepends the prefix (if there is one), and writes to log with WarnLvl.

This is part of the Logger interface implementation.

func (*SubsystemLogger) Warnf

func (l *SubsystemLogger) Warnf(format string, params ...interface{}) error

Warnf formats message according to format specifier, prepends the prefix (if there is one), and writes to log with WarnLvl.

This is part of the Logger interface implementation.

Jump to

Keyboard shortcuts

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