Documentation ¶
Index ¶
- Constants
- Variables
- func Critical(arg0 interface{}, args ...interface{}) error
- func Debug(arg0 interface{}, args ...interface{})
- func Error(arg0 interface{}, args ...interface{}) error
- func Fatal(v ...interface{})
- func Fatalf(format string, v ...interface{})
- func Fatalln(v ...interface{})
- func Fine(arg0 interface{}, args ...interface{})
- func Finest(arg0 interface{}, args ...interface{})
- func Flags() int
- func Info(arg0 interface{}, args ...interface{})
- func LogLogDebug(arg0 interface{}, args ...interface{})
- func LogLogError(arg0 interface{}, args ...interface{}) error
- func LogLogInfo(arg0 interface{}, args ...interface{})
- func LogLogTrace(arg0 interface{}, args ...interface{})
- func LogLogWarn(arg0 interface{}, args ...interface{}) error
- func NewBeginColorizer(typ string) patt.Encoder
- func NewEndColorizer(typ string) patt.Encoder
- func NewLevelEncoder(typ string) patt.Encoder
- func NewStdLog(e *Entry) *log.Logger
- func NewStdLogAt(e *Entry, level interface{}) *log.Logger
- func Output(calldepth int, s string) error
- func Panic(v ...interface{})
- func Panicf(format string, v ...interface{})
- func Panicln(v ...interface{})
- func Prefix() string
- func Print(v ...interface{})
- func Printf(format string, v ...interface{})
- func Println(v ...interface{})
- func RedirectStdLog(e *Entry) func()
- func RedirectStdLogAt(e *Entry, level interface{}) func()
- func SetFlags(flag int)
- func SetOutput(w io.Writer)
- func SetPrefix(prefix string)
- func Trace(arg0 interface{}, args ...interface{})
- func Warn(arg0 interface{}, args ...interface{}) error
- func Writer() io.Writer
- type Entry
- func (e *Entry) AddCallerSkip(addSkip int) *Entry
- func (e *Entry) Critical(arg0 interface{}, args ...interface{})
- func (e *Entry) Debug(arg0 interface{}, args ...interface{})
- func (e *Entry) Error(arg0 interface{}, args ...interface{})
- func (e *Entry) Fine(arg0 interface{}, args ...interface{})
- func (e *Entry) Finest(arg0 interface{}, args ...interface{})
- func (e *Entry) Info(arg0 interface{}, args ...interface{})
- func (e *Entry) Log(calldepth int, level int, arg0 interface{}, args ...interface{})
- func (e *Entry) SetPrefix(prefix string) *Entry
- func (e *Entry) Trace(arg0 interface{}, args ...interface{})
- func (e *Entry) Warn(arg0 interface{}, args ...interface{})
- func (e *Entry) With(args ...interface{}) *Entry
- func (e *Entry) WithMore(args ...interface{}) *Entry
- type FilterConfig
- type Level
- type Logger
- func (l *Logger) AddFilter(name string, level int, apps ...driver.Appender) *Logger
- func (l *Logger) Attach(filters ...*driver.Filter) *Logger
- func (l *Logger) Clone() *Logger
- func (l *Logger) Close()
- func (l *Logger) Copy(src *Logger)
- func (l *Logger) Critical(arg0 interface{}, args ...interface{}) error
- func (l *Logger) Debug(arg0 interface{}, args ...interface{})
- func (l *Logger) Detach(filters ...*driver.Filter) *Logger
- func (l *Logger) Dispatch(r *driver.Recorder)
- func (l *Logger) Enable(enable bool) *Logger
- func (l *Logger) Error(arg0 interface{}, args ...interface{}) error
- func (l *Logger) Fatal(v ...interface{})
- func (l *Logger) Fatalf(format string, v ...interface{})
- func (l *Logger) Fatalln(v ...interface{})
- func (l *Logger) Filters() map[string]*driver.Filter
- func (l *Logger) Fine(arg0 interface{}, args ...interface{})
- func (l *Logger) Finest(arg0 interface{}, args ...interface{})
- func (l *Logger) Flags() int
- func (l *Logger) Info(arg0 interface{}, args ...interface{})
- func (l *Logger) Layout() driver.Layout
- func (l *Logger) LoadConfiguration(lc *LoggerConfig) (errs []error)
- func (l *Logger) Log(calldepth int, level int, arg0 interface{}, args ...interface{})
- func (l *Logger) Output(calldepth int, s string) error
- func (l *Logger) Panic(v ...interface{})
- func (l *Logger) Panicf(format string, v ...interface{})
- func (l *Logger) Panicln(v ...interface{})
- func (l *Logger) Prefix() string
- func (l *Logger) Print(v ...interface{})
- func (l *Logger) Printf(format string, v ...interface{})
- func (l *Logger) Println(v ...interface{})
- func (l *Logger) Set(k string, v interface{}) (err error)
- func (l *Logger) SetFilters(filters map[string]*driver.Filter) *Logger
- func (l *Logger) SetFlags(flag int) *Logger
- func (l *Logger) SetLayout(layout driver.Layout) *Logger
- func (l *Logger) SetOptions(args ...interface{}) *Logger
- func (l *Logger) SetOutput(w io.Writer) *Logger
- func (l *Logger) SetPrefix(prefix string) *Logger
- func (l *Logger) Trace(arg0 interface{}, args ...interface{})
- func (l *Logger) Warn(arg0 interface{}, args ...interface{}) error
- func (l *Logger) With(args ...interface{}) *Entry
- func (l *Logger) Writer() io.Writer
- type LoggerConfig
- type NameValue
Examples ¶
Constants ¶
const ( FINEST int = iota FINE DEBUG TRACE INFO WARN ERROR CRITICAL )
logging levels used by the logger
const ( Ldate = 1 << iota // the date in the local time zone: 2009/01/23 Ltime // the time in the local time zone: 01:23:23 Lmicroseconds // microsecond resolution: 01:23:23.123123. assumes Ltime. Llongfile // full file name and line number: /a/b/c/d.go:23 Lshortfile // final file name element and line number: d.go:23. overrides Llongfile LUTC // if Ldate or Ltime is set, use UTC rather than the local time zone LstdFlags = Ldate | Ltime // initial values for the standard logger )
These flags define which text to prefix to each log entry generated by the Logger. Bits are or'ed together to control what's printed. There is no control over the order they appear (the order listed here) or the format they present (as described in the comments). The prefix is followed by a colon only when Llongfile or Lshortfile is specified. For example, flags Ldate | Ltime (or LstdFlags) produce,
2009/01/23 01:23:23 message
while flags Ldate | Ltime | Lmicroseconds | Llongfile produce,
2009/01/23 01:23:23.123123 /a/b/c/d.go:23: message
const ( Version = "nxlog4go-v2.0.3" Major = 2 Minor = 0 Build = 3 )
Version information
Variables ¶
var FormatLogLog = "%T %P %L %M"
FormatLogLog is format for internal log
Functions ¶
func Critical ¶
func Critical(arg0 interface{}, args ...interface{}) error
Critical is a wrapper for (*Logger).Critical
func Debug ¶
func Debug(arg0 interface{}, args ...interface{})
Debug is a wrapper for (*Logger).Debug
func Error ¶
func Error(arg0 interface{}, args ...interface{}) error
Error is a wrapper for (*Logger).Error
func Fatal ¶
func Fatal(v ...interface{})
Fatal is equivalent to Print() followed by a call to os.Exit(1).
func Fatalf ¶
func Fatalf(format string, v ...interface{})
Fatalf is equivalent to Printf() followed by a call to os.Exit(1).
func Fatalln ¶
func Fatalln(v ...interface{})
Fatalln is equivalent to Println() followed by a call to os.Exit(1).
func Finest ¶
func Finest(arg0 interface{}, args ...interface{})
Finest is a wrapper for (*Logger).Finest
func LogLogDebug ¶
func LogLogDebug(arg0 interface{}, args ...interface{})
LogLogDebug logs a message at the debug log level.
func LogLogError ¶
func LogLogError(arg0 interface{}, args ...interface{}) error
LogLogError logs a message at the error log level.
func LogLogInfo ¶
func LogLogInfo(arg0 interface{}, args ...interface{})
LogLogInfo logs a message at the info log level.
func LogLogTrace ¶
func LogLogTrace(arg0 interface{}, args ...interface{})
LogLogTrace logs a message at the trace log level.
func LogLogWarn ¶
func LogLogWarn(arg0 interface{}, args ...interface{}) error
LogLogWarn logs a message at the warn log level.
func NewBeginColorizer ¶
NewBeginColorizer creates a new color begin encoder.
func NewEndColorizer ¶
NewEndColorizer creates a new color reset encoder.
func NewLevelEncoder ¶ added in v1.0.4
NewLevelEncoder creates a new level encoder.
func NewStdLog ¶
NewStdLog returns a *log.Logger which writes to the supplied logger Entry at Info Level.
func NewStdLogAt ¶
NewStdLogAt returns *log.Logger which writes to supplied logger Entry at required level.
func Output ¶
Output writes the output for a logging event. The string s contains the text to print after the prefix specified by the flags of the Logger. A newline is appended if the last character of s is not already a newline. Calldepth is the count of the number of frames to skip when computing the file name and line number if Llongfile or Lshortfile is set; a value of 1 will print the details for the caller of Output.
func Panic ¶
func Panic(v ...interface{})
Panic is equivalent to Print() followed by a call to panic().
func Panicf ¶
func Panicf(format string, v ...interface{})
Panicf is equivalent to Printf() followed by a call to panic().
func Panicln ¶
func Panicln(v ...interface{})
Panicln is equivalent to Println() followed by a call to panic().
func Print ¶
func Print(v ...interface{})
Print calls Output to print to the standard logger. Arguments are handled in the manner of fmt.Print.
func Printf ¶
func Printf(format string, v ...interface{})
Printf calls Output to print to the standard logger. Arguments are handled in the manner of fmt.Printf.
func Println ¶
func Println(v ...interface{})
Println calls Output to print to the standard logger. Arguments are handled in the manner of fmt.Println.
func RedirectStdLog ¶
func RedirectStdLog(e *Entry) func()
RedirectStdLog redirects output from the standard library's package-global logger to the supplied logger at InfoLevel. Since zap already handles caller annotations, timestamps, etc., it automatically disables the standard library's annotations and prefixing.
It returns a function to restore the original prefix and flags and reset the standard library's output to os.Stderr.
func RedirectStdLogAt ¶
func RedirectStdLogAt(e *Entry, level interface{}) func()
RedirectStdLogAt redirects output from the standard library's package-global logger to the supplied logger at the specified level. Since zap already handles caller annotations, timestamps, etc., it automatically disables the standard library's annotations and prefixing.
It returns a function to restore the original prefix and flags and reset the standard library's output to os.Stderr.
func SetPrefix ¶
func SetPrefix(prefix string)
SetPrefix sets the output prefix for the standard logger.
func Trace ¶
func Trace(arg0 interface{}, args ...interface{})
Trace is a wrapper for (*Logger).Trace
Types ¶
type Entry ¶ added in v1.0.1
type Entry struct {
// contains filtered or unexported fields
}
A Entry contains all of the pertinent information for each message It is the final or intermediate logging entry also. It contains all the fields passed with prefix and With(key, value ...). It's finally logged when Trace, Debug, Info, Warn, Error, Critical called on it.
func (*Entry) AddCallerSkip ¶
AddCallerSkip increases the number of callers skipped by caller annotation. When building wrappers around the logger Entry, supplying this function to reporting the caller's caller information of the wrapper code.
func (*Entry) Critical ¶ added in v1.0.1
func (e *Entry) Critical(arg0 interface{}, args ...interface{})
Critical logs a message at the critical log level and returns the formatted error, See Warn for an explanation of the performance and Debug for an explanation of the parameters.
func (*Entry) Debug ¶ added in v1.0.1
func (e *Entry) Debug(arg0 interface{}, args ...interface{})
Debug is a utility method for debug log messages. The behavior of Debug depends on the first argument:
- arg0 is a string When given a string as the first argument, this behaves like Logf but with the DEBUG log level: the first argument is interpreted as a format for the latter arguments.
- arg0 is a func()string When given a closure of type func()string, this logs the string returned by the closure iff it will be logged. The closure runs at most one time.
- arg0 is interface{} When given anything else, formatted as string (ala Sprint).
func (*Entry) Error ¶ added in v1.0.1
func (e *Entry) Error(arg0 interface{}, args ...interface{})
Error logs a message at the error log level and returns the formatted error, See Warn for an explanation of the performance and Debug for an explanation of the parameters.
func (*Entry) Fine ¶ added in v1.0.1
func (e *Entry) Fine(arg0 interface{}, args ...interface{})
Fine logs a message at the fine log level. See Debug for an explanation of the arguments.
func (*Entry) Finest ¶ added in v1.0.1
func (e *Entry) Finest(arg0 interface{}, args ...interface{})
Finest logs a message at the finest log level. See Debug for an explanation of the arguments.
func (*Entry) Info ¶ added in v1.0.1
func (e *Entry) Info(arg0 interface{}, args ...interface{})
Info logs a message at the info log level. See Debug for an explanation of the arguments.
func (*Entry) Log ¶ added in v1.0.1
Log sends a log message with level, and message. Call depth:
2 - Where calling the wrapper of entry.Log(...) 1 - Where calling entry.Log(...) 0 - Where internal calling entry.flush()
func (*Entry) Trace ¶ added in v1.0.1
func (e *Entry) Trace(arg0 interface{}, args ...interface{})
Trace logs a message at the trace log level. See Debug for an explanation of the arguments.
func (*Entry) Warn ¶ added in v1.0.1
func (e *Entry) Warn(arg0 interface{}, args ...interface{})
Warn logs a message at the warn log level and returns the formatted error. At the warn level and higher, there is no performance benefit if the message is not actually logged, because all formats are processed and all closures are executed to format the error message. See Debug for further explanation of the arguments.
type FilterConfig ¶
type FilterConfig struct { Enabled string `xml:"enabled,attr" json:"enabled"` Tag string `xml:"tag" json:"tag"` Type string `xml:"type" json:"type"` Dsn string `xml:"dsn" json:"dsn"` Level string `xml:"level" json:"level"` Properties []NameValue `xml:"property" json:"properties"` }
FilterConfig offers a declarative way to construct a logger's default writer, internal log and 3rd appenders
type Level ¶
type Level int
Level is the integer logging levels
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
A Logger represents an active logging object that generates lines of output to an io.Writer, and a collection of Filters through which log messages are written. Each logging operation makes a single call to the Writer's Write method. A Logger can be used simultaneously from multiple goroutines; it guarantees to serialize access to the Writer.
Example ¶
package main import ( "bytes" "fmt" log "github.com/ccpaging/nxlog4go" ) func main() { var ( buf bytes.Buffer logger = log.New(&buf, "logger: ", log.Lshortfile) ) logger.Print("Hello, log file!") fmt.Print(&buf) }
Output: logger: example_test.go:19: Hello, log file!
func GetLogLog ¶
func GetLogLog() *Logger
GetLogLog creates internal logger if not existed, and returns it. This logger used to output log statements from within the package. Do not set any filters.
func New ¶
New creates a new Logger. The out variable sets the destination to which log data will be written. The prefix appears at the beginning of each generated log line. The flag argument defines the logging properties.
func NewLogger ¶
NewLogger creates a new logger with a "stderr" writer to send formatted log messages at or above level to standard output.
func (*Logger) AddFilter ¶
AddFilter adds the named appenders to the Logger which will only log messages at or above level. This function should not be called from multiple goroutines.
Returns the logger for chaining.
func (*Logger) Clone ¶
Clone creates a new clone logger.
New logger can be used in different module. Using owner prefix and runtime caller switch. Running in the parallel go routines and packages is safe.
func (*Logger) Close ¶ added in v1.0.4
func (l *Logger) Close()
Close closes all log filters in preparation for exiting the program. Calling this is not really imperative, unless you want to guarantee that all log messages are written.
Notice: Close() removes all filters (and thus all appenders) except "stdout" from the logger.
func (*Logger) Critical ¶
Critical logs a message at the critical log level and returns the formatted error, See Warn for an explanation of the performance and ArgsToString for an explanation of the parameters.
func (*Logger) Debug ¶
func (l *Logger) Debug(arg0 interface{}, args ...interface{})
Debug is a utility method for debug log messages. See ArgsToString for an explanation of the arguments.
func (*Logger) Enable ¶
Enable sets the standard filter's Enabler to deny all, or restores the default at/above level enabler.
func (*Logger) Error ¶
Error logs a message at the error log level and returns the formatted error, See Warn for an explanation of the performance and ArgsToString for an explanation of the parameters.
func (*Logger) Fatal ¶
func (l *Logger) Fatal(v ...interface{})
Fatal is equivalent to l.Print() followed by a call to os.Exit(1).
func (*Logger) Fatalln ¶
func (l *Logger) Fatalln(v ...interface{})
Fatalln is equivalent to l.Println() followed by a call to os.Exit(1).
func (*Logger) Fine ¶
func (l *Logger) Fine(arg0 interface{}, args ...interface{})
Fine logs a message at the fine log level. See Debug for an explanation of the arguments.
func (*Logger) Finest ¶
func (l *Logger) Finest(arg0 interface{}, args ...interface{})
Finest logs a message at the finest log level. See Debug for an explanation of the arguments.
func (*Logger) Info ¶
func (l *Logger) Info(arg0 interface{}, args ...interface{})
Info logs a message at the info log level. See Debug for an explanation of the arguments.
func (*Logger) LoadConfiguration ¶
func (l *Logger) LoadConfiguration(lc *LoggerConfig) (errs []error)
LoadConfiguration sets options of logger, and creates/loads/sets appenders.
func (*Logger) Log ¶
Log sends a log message with level and message. Call depth:
2 - Where calling the wrapper of logger.Log(...) 1 - Where calling logger.Log(...) 0 - Where internal calling entry.flush()
func (*Logger) Output ¶
Output writes the output for a logging event. The string s contains the text to print after the prefix specified by the flags of the Logger. A newline is appended if the last character of s is not already a newline. Calldepth is used to recover the PC and is provided for generality, although at the moment on all pre-defined paths it will be 2.
Example ¶
package main import ( "bytes" "fmt" log "github.com/ccpaging/nxlog4go" ) func main() { var ( buf bytes.Buffer logger = log.New(&buf, "INFO: ", log.Lshortfile) infof = func(info string) { logger.Output(2, info) } ) infof("Hello world") fmt.Print(&buf) }
Output: INFO: example_test.go:36: Hello world
func (*Logger) Panic ¶
func (l *Logger) Panic(v ...interface{})
Panic is equivalent to l.Print() followed by a call to panic().
func (*Logger) Panicln ¶
func (l *Logger) Panicln(v ...interface{})
Panicln is equivalent to l.Println() followed by a call to panic().
func (*Logger) Print ¶
func (l *Logger) Print(v ...interface{})
Print calls l.Output to print to the logger. Arguments are handled in the manner of fmt.Print.
func (*Logger) Printf ¶
Printf calls l.Output to print to the logger. Arguments are handled in the manner of fmt.Printf.
func (*Logger) Println ¶
func (l *Logger) Println(v ...interface{})
Println calls l.Output to print to the logger. Arguments are handled in the manner of fmt.Println.
func (*Logger) Set ¶
Set sets name-value option with:
prefix - The output prefix caller - Enable or disable the runtime caller function level - The output level
layout options...
Return errors.
func (*Logger) SetFilters ¶
SetFilters sets the output filters for the logger.
func (*Logger) Trace ¶
func (l *Logger) Trace(arg0 interface{}, args ...interface{})
Trace logs a message at the trace log level. See ArgsToString for an explanation of the arguments.
func (*Logger) Warn ¶
Warn logs a message at the warn log level and returns the formatted error. At the warn level and higher, there is no performance benefit if the message is not actually logged, because all formats are processed and all closures are executed to format the error message. See ArgsToString for further explanation of the arguments.
type LoggerConfig ¶
type LoggerConfig struct { Version string `xml:"version,attr" json:"version"` Filters []*FilterConfig `xml:"filter" json:"filters"` }
LoggerConfig offers a declarative way to construct a logger. See examples/config.xml and examples/config.json for documentation