| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
This package is not in the latest version of its module.
Go to latest Published: May 16, 2022 License: Apache-2.0The Go module system was introduced in Go 1.11 and is the official dependency management solution for Go.
Redistributable licenses place minimal restrictions on how software can be used, modified, and redistributed.
Modules with tagged versions give importers more predictable builds.
When a project reaches major version v1 it is considered stable.
package main
import (
"fmt"
"github.com/Masterminds/log-go"
"github.com/Masterminds/log-go/impl/logrus"
)
type Foo struct {
Logger log.Logger
}
func (f *Foo) DoSomething() {
f.Logger.Info("Hello Logging")
}
func main() {
// Using the default Logger
log.Info("Hello")
log.Error("World")
// Create a logrus logger with default configuration that uses the log
// interface. Note, logrus can be setup with default settings or setup with
// custom settings using a second constructor.
lgrs := logrus.NewStandard()
// Set logrus as the global logger
log.Current = lgrs
// Logrus is now used globally for logging
log.Warn("Warning through logrus")
f1 := Foo{
Logger: lgrs,
}
// Logging in DoSomething will use the set logger which is logrus
f1.DoSomething()
f2 := Foo{
// The log package uses the global logger from the standard library log
// package. A custom standard library logger can be used with the
// github.com/Masterminds/log-go/impl/std package.
Logger: log.NewStandard(),
}
// Logging in DoSomething will the logger from the standard library
f2.DoSomething()
// Need to detect the logger being used? You can check for the type.
switch log.Current.(type) {
case *log.StdLogger:
fmt.Println("The default logger")
case *logrus.Logger:
fmt.Printf("Logrus is used for logging")
default:
fmt.Printf("Something else that implements the interface")
}
}
Output:
const ( // TraceLevel is the constant to use when setting the Trace level for loggers // provided by this library. TraceLevel = iota // DebugLevel is the constant to use when setting the Debug level for loggers // provided by this library. DebugLevel // InfoLevel is the constant to use when setting the Info level for loggers // provided by this library. InfoLevel // WarnLevel is the constant to use when setting the Warn level for loggers // provided by this library. WarnLevel // ErrorLevel is the constant to use when setting the Error level for loggers // provided by this library. ErrorLevel // PanicLevel is the constant to use when setting the Panic level for loggers // provided by this library. PanicLevel // FatalLevel is the constant to use when setting the Fatal level for loggers // provided by this library. FatalLevel )
This section is empty.
func Debugf(template string, args ...interface{})
Debugf formats a message according to a format specifier and logs the message at the Debug level
Debugw logs a message at the Debug level along with some additional context (key-value pairs)
func Errorf(template string, args ...interface{})
Errorf formats a message according to a format specifier and logs the message at the Error level
Errorw logs a message at the Error level along with some additional context (key-value pairs)
func Fatal(msg ...interface{})
Fatal logs a message at the Fatal level and exists the application
func Fatalf(template string, args ...interface{})
Fatalf formats a message according to a format specifier and logs the message at the Fatal level and exits the application
Fatalw logs a message at the Fatal level along with some additional context (key-value pairs) and exits the application
func Infof(template string, args ...interface{})
Infof formats a message according to a format specifier and logs the message at the Info level
Infow logs a message at the Info level along with some additional context (key-value pairs)
func Panicf(template string, args ...interface{})
Panicf formats a message according to a format specifier and logs the message at the Panic level and then panics
Panicw logs a message at the Panic level along with some additional context (key-value pairs) and then panics
func Tracef(template string, args ...interface{})
Tracef formats a message according to a format specifier and logs the message at the Trace level
Tracew logs a message at the Trace level along with some additional context (key-value pairs)
func Warnf(template string, args ...interface{})
Warnf formats a message according to a format specifier and logs the message at the Warning level
Warnw logs a message at the Warning level along with some additional context (key-value pairs)
type Fields map[string]interface{}
Fields represents a map of key-value pairs where the value can be any Go type. The value must be able to be converted to a string.
type Logger interface {
// Trace logs a message at the Trace level
Trace(msg ...interface{})
// Tracef formats a message according to a format specifier and logs the
// message at the Trace level
Tracef(template string, args ...interface{})
// Tracew logs a message at the Trace level along with some additional
// context (key-value pairs)
Tracew(msg string, fields Fields)
// Debug logs a message at the Debug level
Debug(msg ...interface{})
// Debugf formats a message according to a format specifier and logs the
// message at the Debug level
Debugf(template string, args ...interface{})
// Debugw logs a message at the Debug level along with some additional
// context (key-value pairs)
Debugw(msg string, fields Fields)
// Info logs a message at the Info level
Info(msg ...interface{})
// Infof formats a message according to a format specifier and logs the
// message at the Info level
Infof(template string, args ...interface{})
// Infow logs a message at the Info level along with some additional
// context (key-value pairs)
Infow(msg string, fields Fields)
// Warn logs a message at the Warn level
Warn(msg ...interface{})
// Warnf formats a message according to a format specifier and logs the
// message at the Warning level
Warnf(template string, args ...interface{})
// Warnw logs a message at the Warning level along with some additional
// context (key-value pairs)
Warnw(msg string, fields Fields)
// Error logs a message at the Error level
Error(msg ...interface{})
// Errorf formats a message according to a format specifier and logs the
// message at the Error level
Errorf(template string, args ...interface{})
// Errorw logs a message at the Error level along with some additional
// context (key-value pairs)
Errorw(msg string, fields Fields)
// Panic logs a message at the Panic level and panics
Panic(msg ...interface{})
// Panicf formats a message according to a format specifier and logs the
// message at the Panic level and then panics
Panicf(template string, args ...interface{})
// Panicw logs a message at the Panic level along with some additional
// context (key-value pairs) and then panics
Panicw(msg string, fields Fields)
// Fatal logs a message at the Fatal level and exists the application
Fatal(msg ...interface{})
// Fatalf formats a message according to a format specifier and logs the
// message at the Fatal level and exits the application
Fatalf(template string, args ...interface{})
// Fatalw logs a message at the Fatal level along with some additional
// context (key-value pairs) and exits the application
Fatalw(msg string, fields Fields)
}
Logger is an interface for Logging
var Current Logger
Current contains the logger used for the package level logging functions
type StdLogger struct {
Level int
}
StdLogger is a struct that wraps the general logger provided by the Go standard library and causes it to meet the log.Logger interface
func NewStandard() *StdLogger
NewStandard sets up a basic logger using the general one provided in the Go standard library
func (l StdLogger) Debug(msg ...interface{})
Debug logs a message at the Debug level
Debugf formats a message according to a format specifier and logs the message at the Debug level
Debugw logs a message at the Debug level along with some additional context (key-value pairs)
func (l StdLogger) Error(msg ...interface{})
Error logs a message at the Error level
Errorf formats a message according to a format specifier and logs the message at the Error level
Errorw logs a message at the Error level along with some additional context (key-value pairs)
func (l StdLogger) Fatal(msg ...interface{})
Fatal logs a message at the Fatal level and exists the application
Fatalf formats a message according to a format specifier and logs the message at the Fatal level and exits the application
Fatalw logs a message at the Fatal level along with some additional context (key-value pairs) and exits the application
func (l StdLogger) Info(msg ...interface{})
Info logs a message at the Info level
Infof formats a message according to a format specifier and logs the message at the Info level
Infow logs a message at the Info level along with some additional context (key-value pairs)
func (l StdLogger) Panic(msg ...interface{})
Panic logs a message at the Panic level and panics
Panicf formats a message according to a format specifier and logs the message at the Panic level and then panics
Panicw logs a message at the Panic level along with some additional context (key-value pairs) and then panics
func (l StdLogger) Trace(msg ...interface{})
Trace logs a message at the Trace level
Tracef formats a message according to a format specifier and logs the message at the Trace level
Tracew logs a message at the Trace level along with some additional context (key-value pairs)
func (l StdLogger) Warn(msg ...interface{})
Warn logs a message at the Warn level
| Path | Synopsis |
|---|---|
|
_examples
|
|
|
cli
command
|
|
|
default
command
|
|
|
iowriter
command
|
|
|
logrus
command
|
|
|
logrus_custom
command
|
|
|
impl
|
|
|
Package io provides a means of turning a log.Logger into an io.Writer for a chosen level.
|
Package io provides a means of turning a log.Logger into an io.Writer for a chosen level. |
| Back | FazBrowse Home | New Git URL |