Documentation ¶
Index ¶
- Constants
- Variables
- func Debugf(format string, v ...interface{})
- func Debugln(v ...interface{})
- func Errorf(format string, v ...interface{})
- func Errorln(v ...interface{})
- func Fatalf(format string, v ...interface{})
- func Fatalln(v ...interface{})
- func Infof(format string, v ...interface{})
- func Infoln(v ...interface{})
- func NewDefaultLogger()
- func SetCallPath(caller int)
- func SetDefaultLogFile()
- func SetFormatter(f Formatter)
- func SetLevel(lv string)
- func SetLogFile(path string)
- func Tracef(format string, v ...interface{})
- func Traceln(v ...interface{})
- func Warnf(format string, v ...interface{})
- func Warnln(v ...interface{})
- type Context
- type Entry
- func (e *Entry) Debugf(format string, v ...interface{})
- func (e *Entry) Debugln(v ...interface{})
- func (e *Entry) Errorf(format string, v ...interface{})
- func (e *Entry) Errorln(v ...interface{})
- func (e *Entry) Fatalf(format string, v ...interface{})
- func (e *Entry) Fatalln(v ...interface{})
- func (e *Entry) Infof(format string, v ...interface{})
- func (e *Entry) Infoln(v ...interface{})
- func (e *Entry) Tracef(format string, v ...interface{})
- func (e *Entry) Traceln(v ...interface{})
- func (e *Entry) Warnf(format string, v ...interface{})
- func (e *Entry) Warnln(v ...interface{})
- func (e *Entry) WithContext(ctx Context) *Entry
- type Fields
- type Formatter
- type JSONFormatter
- type Logger
- func (l *Logger) Debugf(format string, v ...interface{})
- func (l *Logger) Debugln(v ...interface{})
- func (l *Logger) EnableAsync() *Logger
- func (l *Logger) Errorf(format string, v ...interface{})
- func (l *Logger) Errorln(v ...interface{})
- func (l *Logger) Fatalf(format string, v ...interface{})
- func (l *Logger) Fatalln(v ...interface{})
- func (l *Logger) Infof(format string, v ...interface{})
- func (l *Logger) Infoln(v ...interface{})
- func (l *Logger) SetCallPath(callPath int)
- func (l *Logger) SetContext(ctx Context) *Entry
- func (l *Logger) SetFormatter(f Formatter) *Logger
- func (l *Logger) SetLevel(level int)
- func (l *Logger) SetLevelByName(level string)
- func (l *Logger) Tracef(format string, v ...interface{})
- func (l *Logger) Traceln(v ...interface{})
- func (l *Logger) Warnf(format string, v ...interface{})
- func (l *Logger) Warnln(v ...interface{})
- type TextFormatter
Constants ¶
const ( LogLevelUnspecified int = iota LogLevelTrace LogLevelDebug LogLevelInfo LogLevelWarn LogLevelError LogLevelFatal )
UNSPECIFIED means no log level
const ( EnvLogLevelTrace = "TRACE" EnvLogLevelDebug = "DEBUG" EnvLogLevelInfo = "INFO" EnvLogLevelWarn = "WARN" EnvLogLevelError = "ERROR" EnvLogLevelFatal = "FATAL" )
const ( // CallPath is The depth of a function is called CallPathDepth1 = 1 CallPathDepth2 = 2 CallPathDepth3 = 3 CallPathDefault = CallPathDepth3 )
const ( // Color refers to if ColorOn = true ColorOff = false // Default LogLevel LogLevelDefault = LogLevelInfo // Local is the default time zone LocationLocal = "Local" // TimeFormatDefault is The default format of time TimeFormatDefault = "2006-01-02 15:04:05.0000" // DefaultLogFile is the default log file path DefaultLogFile = "./access.log" )
Variables ¶
var LogLevelMap = map[int]string{
LogLevelUnspecified: "UNSPECIFIED",
LogLevelTrace: "TRACE",
LogLevelDebug: "DEBUG",
LogLevelInfo: "INFO",
LogLevelWarn: "WARN",
LogLevelError: "ERROR",
LogLevelFatal: "FATAL",
}
LogLevelMap is log level map
Functions ¶
func Debugf ¶
func Debugf(format string, v ...interface{})
Debugf print debug level logs in a specific format
func Errorf ¶
func Errorf(format string, v ...interface{})
Errorf print error level logs in a specific format
func Fatalf ¶
func Fatalf(format string, v ...interface{})
Fatalf print fatal level logs in a specific format
func Infof ¶
func Infof(format string, v ...interface{})
Infof print info level logs in a specific format
func NewDefaultLogger ¶
func NewDefaultLogger()
NewDefaultLogger returns a instance of Logger with default configurations
func SetDefaultLogFile ¶
func SetDefaultLogFile()
func Tracef ¶
func Tracef(format string, v ...interface{})
Tracef print trace level logs in a specific format
Types ¶
type Entry ¶
type Entry struct { // Ctx context.Context Context Context // contains filtered or unexported fields }
func (*Entry) Debugf ¶
Debugf print debug level logs in a specific format
func (*Entry) Debugln ¶
func (e *Entry) Debugln(v ...interface{})
Debugln print debug level logs in a line
func (*Entry) Errorf ¶
Errorf print error level logs in a specific format
func (*Entry) Errorln ¶
func (e *Entry) Errorln(v ...interface{})
Errorln print error level logs in a line
func (*Entry) Fatalf ¶
Fatalf print fatal level logs in a specific format
func (*Entry) Fatalln ¶
func (e *Entry) Fatalln(v ...interface{})
Fatalln print fatal level logs in a line
func (*Entry) Infof ¶
Infof print info level logs in a specific format
func (*Entry) Infoln ¶
func (e *Entry) Infoln(v ...interface{})
Infoln print info level logs in a line
func (*Entry) Tracef ¶
Tracef print trace level logs in a specific format
func (*Entry) Traceln ¶
func (e *Entry) Traceln(v ...interface{})
Traceln print trace level logs in a line
func (*Entry) Warnf ¶
Warnf print warn level logs in a specific format
type Fields ¶
type Formatter ¶
Formatter will decide how logs are printed Default consist of: * TextFormatter, print as "deployment=kubestar namespace=default msg=deployment not found" * JSONFormatter, print as "{"deployment": "kubestar", "namespace": "default", "msg": "deployment not found"}"
type JSONFormatter ¶
type JSONFormatter struct {
Color bool
}
func (*JSONFormatter) Print ¶
func (t *JSONFormatter) Print(fields *Fields, ctx Context) string
func (*JSONFormatter) SetColor ¶
func (t *JSONFormatter) SetColor(color bool)
type Logger ¶
type Logger struct { Writer io.Writer Level int CallPath int Async bool // contains filtered or unexported fields }
Logger defines a general logger which could write specific logs
func NewLogger ¶
NewLogger returns a instance of Logger
func (*Logger) Debugf ¶
Debugf print debug level logs in a specific format
func (*Logger) Debugln ¶
func (l *Logger) Debugln(v ...interface{})
Debugln print debug level logs in a line
func (*Logger) Errorf ¶
Errorf print error level logs in a specific format
func (*Logger) Errorln ¶
func (l *Logger) Errorln(v ...interface{})
Errorln print error level logs in a line
func (*Logger) Fatalf ¶
Fatalf print fatal level logs in a specific format
func (*Logger) Fatalln ¶
func (l *Logger) Fatalln(v ...interface{})
Fatalln print fatal level logs in a line
func (*Logger) Infof ¶
Infof print info level logs in a specific format
func (*Logger) Infoln ¶
func (l *Logger) Infoln(v ...interface{})
Infoln print info level logs in a line
func (*Logger) SetLevelByName ¶
SetLevelByName set the log level by name
func (*Logger) Tracef ¶
Tracef print trace level logs in a specific format
func (*Logger) Traceln ¶
func (l *Logger) Traceln(v ...interface{})
Traceln print trace level logs in a line
func (*Logger) Warnf ¶
Warnf print warn level logs in a specific format
type TextFormatter ¶
type TextFormatter struct {
Color bool
}
func (*TextFormatter) Print ¶
func (t *TextFormatter) Print(fields *Fields, ctx Context) string
func (*TextFormatter) SetColor ¶
func (t *TextFormatter) SetColor(color bool)