Documentation ¶
Overview ¶
Package log implements a common logging like log4j.
Index ¶
- Constants
- func Debug(obj ...interface{})
- func Debugf(msg string, args ...interface{})
- func Error(obj ...interface{})
- func Errorf(msg string, args ...interface{})
- func Fatal(obj ...interface{})
- func Fatalf(msg string, args ...interface{})
- func GetAppName() string
- func GetFlags() int
- func GetLevel() int
- func GetLevelName() string
- func GetTimeFormat() string
- func Info(obj ...interface{})
- func Infof(msg string, args ...interface{})
- func IsDebugEnabled() bool
- func IsErrorEnabled() bool
- func IsFatalEnabled() bool
- func IsInfoEnabled() bool
- func IsWarnEnabled() bool
- func SetAppName(name string)
- func SetFlags(flags int)
- func SetLevel(level int)
- func SetLevelName(level string)
- func SetTimeFormat(format string)
- func SetWriter(w io.Writer)
- func Warn(obj ...interface{})
- func Warnf(msg string, args ...interface{})
- type AlwaysNewFileWriter
- type DailyFileWriter
- type FixedSizeFileWriter
- type Logger
- func (l *Logger) Debug(obj ...interface{})
- func (l *Logger) Debugf(msg string, args ...interface{})
- func (l *Logger) Error(obj ...interface{})
- func (l *Logger) Errorf(msg string, args ...interface{})
- func (l *Logger) Fatal(obj ...interface{})
- func (l *Logger) Fatalf(msg string, args ...interface{})
- func (l *Logger) GetAppName() string
- func (l *Logger) GetFlags() int
- func (l *Logger) GetLevel() int
- func (l *Logger) GetLevelName() string
- func (l *Logger) GetTimeFormat() string
- func (l *Logger) Info(obj ...interface{})
- func (l *Logger) Infof(msg string, args ...interface{})
- func (l *Logger) IsDebugEnabled() bool
- func (l *Logger) IsErrorEnabled() bool
- func (l *Logger) IsFatalEnabled() bool
- func (l *Logger) IsInfoEnabled() bool
- func (l *Logger) IsWarnEnabled() bool
- func (l *Logger) SetAppName(name string) *Logger
- func (l *Logger) SetFlags(flags int) *Logger
- func (l *Logger) SetLevel(level int) *Logger
- func (l *Logger) SetLevelName(level string)
- func (l *Logger) SetTimeFormat(format string) *Logger
- func (l *Logger) SetWriter(w io.Writer) *Logger
- func (l *Logger) SkipCaller(skip int) *Logger
- func (l *Logger) Warn(obj ...interface{})
- func (l *Logger) Warnf(msg string, args ...interface{})
Examples ¶
Constants ¶
View Source
const ( // log level L_DEBUG = iota L_INFO L_WARN L_ERROR L_FATAL L_OFF // Bits or'ed together to control what's printed. F_TIME = 1 << iota F_LONG_FILE F_SHORT_FILE F_PID F_GID F_COLOR // default flags DEFAULT_FLAGS = F_TIME | F_SHORT_FILE | F_PID // default time format DEFAULT_TIME_FORMAT = "2006-01-02 15:04:05.000" )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type AlwaysNewFileWriter ¶
type AlwaysNewFileWriter struct { Name string MaxCount int // contains filtered or unexported fields }
AlwaysNewFileWriter create new log for every process
Example ¶
log.SetWriter(&log.AlwaysNewFileWriter{ Name: "/tmp/test.log", MaxCount: 10, })
Output:
type DailyFileWriter ¶
DailyFileWriter create new log for every day
Example ¶
log.SetWriter(&log.DailyFileWriter{ Name: "/tmp/test.log", MaxCount: 10, })
Output:
type FixedSizeFileWriter ¶
type FixedSizeFileWriter struct { Name string MaxSize int64 MaxCount int // contains filtered or unexported fields }
FixedSizeFileWriter create new log if log size exceed
Example ¶
log.SetWriter(&log.FixedSizeFileWriter{ Name: "/tmp/test.log", MaxSize: 10 * 1024 * 1024, // 10M MaxCount: 10, })
Output:
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
func New ¶
Example ¶
logger := log.New(os.Stdout) logger.SetAppName("app") logger.SetFlags(log.DEFAULT_FLAGS | log.F_GID) logger.Info("testing ...") logger.Errorf("err = %v", os.ErrInvalid) // Outputs: // 2001-10-10 12:00:00,000 1234 app 987 INFO main.go:13 testing ... // 2001-10-10 12:00:00,000 1234 app 987 ERROR main.go:14 err = invalid argument
Output:
func (*Logger) GetAppName ¶
func (*Logger) GetLevelName ¶
func (*Logger) GetTimeFormat ¶
func (*Logger) IsDebugEnabled ¶
func (*Logger) IsErrorEnabled ¶
func (*Logger) IsFatalEnabled ¶
func (*Logger) IsInfoEnabled ¶
func (*Logger) IsWarnEnabled ¶
func (*Logger) SetAppName ¶
func (*Logger) SetLevelName ¶
func (*Logger) SetTimeFormat ¶
func (*Logger) SkipCaller ¶
Click to show internal directories.
Click to hide internal directories.