Update comments on public structs and methods

remotes/r/develop
Guoqiang Chen 7 years ago
parent 89dee3a1df
commit 36cf27f324

@ -14,6 +14,7 @@ type Formatter interface {
type simpleFormatter struct { type simpleFormatter struct {
} }
// Format implements log.Formatter
func (f simpleFormatter) Format(level Level, msg string, logger *Logger) []byte { func (f simpleFormatter) Format(level Level, msg string, logger *Logger) []byte {
time := time.Now().Format("15:04:05.000") time := time.Now().Format("15:04:05.000")
return []byte(fmt.Sprintf("%s %s %s\n", time, level.String(), msg)) return []byte(fmt.Sprintf("%s %s %s\n", time, level.String(), msg))

@ -5,6 +5,7 @@ import (
"strings" "strings"
) )
// FilelineCaller returns file and line for caller
func FilelineCaller(skip int) (file string, line int) { func FilelineCaller(skip int) (file string, line int) {
for i := 0; i < 10; i++ { for i := 0; i < 10; i++ {
_, file, line, ok := runtime.Caller(skip + i) _, file, line, ok := runtime.Caller(skip + i)

@ -7,6 +7,7 @@ import (
"golang.org/x/crypto/ssh/terminal" "golang.org/x/crypto/ssh/terminal"
) )
// IsTerminal returns whether is a valid tty for io.Writer
func IsTerminal(w io.Writer) bool { func IsTerminal(w io.Writer) bool {
switch v := w.(type) { switch v := w.(type) {
case *os.File: case *os.File:

@ -3,147 +3,147 @@ package log
// Default is a default Logger instance // Default is a default Logger instance
var Default = New() var Default = New()
// Indicate whether output debug message // IsDebugEnabled indicates whether output message
func IsDebugEnabled() bool { func IsDebugEnabled() bool {
return Default.IsDebugEnabled() return Default.IsDebugEnabled()
} }
// Indicate whether output info message // IsInfoEnabled indicates whether output message
func IsInfoEnabled() bool { func IsInfoEnabled() bool {
return Default.IsInfoEnabled() return Default.IsInfoEnabled()
} }
// Indicate whether output info message // IsPrintEnabled indicates whether output message
func IsPrintEnabled() bool { func IsPrintEnabled() bool {
return Default.IsPrintEnabled() return Default.IsPrintEnabled()
} }
// Indicate whether output warning message // IsWarnEnabled indicates whether output message
func IsWarnEnabled() bool { func IsWarnEnabled() bool {
return Default.IsWarnEnabled() return Default.IsWarnEnabled()
} }
// Indicate whether output error message // IsErrorEnabled indicates whether output message
func IsErrorEnabled() bool { func IsErrorEnabled() bool {
return Default.IsErrorEnabled() return Default.IsErrorEnabled()
} }
// Indicate whether output panic message // IsPanicEnabled indicates whether output message
func IsPanicEnabled() bool { func IsPanicEnabled() bool {
return Default.IsPanicEnabled() return Default.IsPanicEnabled()
} }
// Indicate whether output fatal message // IsFatalEnabled indicates whether output message
func IsFatalEnabled() bool { func IsFatalEnabled() bool {
return Default.IsFatalEnabled() return Default.IsFatalEnabled()
} }
// Indicate whether output is off // IsDisabled indicates whether output message
func IsDisabled() bool { func IsDisabled() bool {
return Default.IsDisabled() return Default.IsDisabled()
} }
// Output a debug message // Debug outputs message, Arguments are handled by fmt.Sprint
func Debug(obj ...interface{}) { func Debug(obj ...interface{}) {
Default.Debug(obj...) Default.Debug(obj...)
} }
// Output an info message // Info outputs message, Arguments are handled by fmt.Sprint
func Info(obj ...interface{}) { func Info(obj ...interface{}) {
Default.Info(obj...) Default.Info(obj...)
} }
// Output an info message // Print outputs message, Arguments are handled by fmt.Sprint
func Print(obj ...interface{}) { func Print(obj ...interface{}) {
Default.Print(obj...) Default.Print(obj...)
} }
// Output a warning message // Warn outputs message, Arguments are handled by fmt.Sprint
func Warn(obj ...interface{}) { func Warn(obj ...interface{}) {
Default.Warn(obj...) Default.Warn(obj...)
} }
// Output an error message // Error outputs message, Arguments are handled by fmt.Sprint
func Error(obj ...interface{}) { func Error(obj ...interface{}) {
Default.Error(obj...) Default.Error(obj...)
} }
// Output a panic message with full stack // Panic outputs message, and followed by a call to panic() Arguments are handled by fmt.Sprint
func Panic(obj ...interface{}) { func Panic(obj ...interface{}) {
Default.Panic(obj...) Default.Panic(obj...)
} }
// Output a fatal message with full stack // Fatal outputs message, and followed by a call to os.Exit(1) Arguments are handled by fmt.Sprint
func Fatal(obj ...interface{}) { func Fatal(obj ...interface{}) {
Default.Fatal(obj...) Default.Fatal(obj...)
} }
// Output a debug message // Debugln outputs message, Arguments are handled by fmt.Sprintln
func Debugln(obj ...interface{}) { func Debugln(obj ...interface{}) {
Default.Debugln(obj...) Default.Debugln(obj...)
} }
// Output an info message // Infoln outputs message, Arguments are handled by fmt.Sprintln
func Infoln(obj ...interface{}) { func Infoln(obj ...interface{}) {
Default.Infoln(obj...) Default.Infoln(obj...)
} }
// Output an info message // Println outputs message, Arguments are handled by fmt.Sprintln
func Println(obj ...interface{}) { func Println(obj ...interface{}) {
Default.Println(obj...) Default.Println(obj...)
} }
// Output a warning message // Warnln outputs message, Arguments are handled by fmt.Sprintln
func Warnln(obj ...interface{}) { func Warnln(obj ...interface{}) {
Default.Warnln(obj...) Default.Warnln(obj...)
} }
// Output an error message // Errorln outputs message, Arguments are handled by fmt.Sprintln
func Errorln(obj ...interface{}) { func Errorln(obj ...interface{}) {
Default.Errorln(obj...) Default.Errorln(obj...)
} }
// Output a panic message with full stack // Panicln outputs message and followed by a call to panic(), Arguments are handled by fmt.Sprintln
func Panicln(obj ...interface{}) { func Panicln(obj ...interface{}) {
Default.Panicln(obj...) Default.Panicln(obj...)
} }
// Output a fatal message with full stack // Fatalln outputs message and followed by a call to os.Exit(1), Arguments are handled by fmt.Sprintln
func Fatalln(obj ...interface{}) { func Fatalln(obj ...interface{}) {
Default.Fatalln(obj...) Default.Fatalln(obj...)
} }
// Output a debug message // Debugf outputs message, Arguments are handled by fmt.Sprintf
func Debugf(msg string, args ...interface{}) { func Debugf(msg string, args ...interface{}) {
Default.Debugf(msg, args...) Default.Debugf(msg, args...)
} }
// Output an info message // Infof outputs message, Arguments are handled by fmt.Sprintf
func Infof(msg string, args ...interface{}) { func Infof(msg string, args ...interface{}) {
Default.Infof(msg, args...) Default.Infof(msg, args...)
} }
// Output an info message // Printf outputs message, Arguments are handled by fmt.Sprintf
func Printf(msg string, args ...interface{}) { func Printf(msg string, args ...interface{}) {
Default.Printf(msg, args...) Default.Printf(msg, args...)
} }
// Output a warning message // Warnf outputs message, Arguments are handled by fmt.Sprintf
func Warnf(msg string, args ...interface{}) { func Warnf(msg string, args ...interface{}) {
Default.Warnf(msg, args...) Default.Warnf(msg, args...)
} }
// Output an error message // Errorf outputs message, Arguments are handled by fmt.Sprintf
func Errorf(msg string, args ...interface{}) { func Errorf(msg string, args ...interface{}) {
Default.Errorf(msg, args...) Default.Errorf(msg, args...)
} }
// Output a panic message with full stack // Panicf outputs message and followed by a call to panic(), Arguments are handled by fmt.Sprintf
func Panicf(msg string, args ...interface{}) { func Panicf(msg string, args ...interface{}) {
Default.Panicf(msg, args...) Default.Panicf(msg, args...)
} }
// Output a fatal message with full stack // Fatalf outputs message and followed by a call to os.Exit(1), Arguments are handled by fmt.Sprintf
func Fatalf(msg string, args ...interface{}) { func Fatalf(msg string, args ...interface{}) {
Default.Fatalf(msg, args...) Default.Fatalf(msg, args...)
} }

@ -7,8 +7,10 @@ import (
"sync" "sync"
) )
// Exit is equals os.Exit
var Exit = os.Exit var Exit = os.Exit
// Logger is represents an active logging object
type Logger struct { type Logger struct {
m sync.Mutex m sync.Mutex
Level Level Level Level
@ -16,6 +18,7 @@ type Logger struct {
Out io.Writer Out io.Writer
} }
// New creates a new Logger
func New() *Logger { func New() *Logger {
return &Logger{ return &Logger{
Level: INFO, Level: INFO,
@ -24,68 +27,82 @@ func New() *Logger {
} }
} }
// IsDebugEnabled indicates whether output message
func (l *Logger) IsDebugEnabled() bool { func (l *Logger) IsDebugEnabled() bool {
return l.Level >= DEBUG return l.Level >= DEBUG
} }
// IsInfoEnabled indicates whether output message
func (l *Logger) IsInfoEnabled() bool { func (l *Logger) IsInfoEnabled() bool {
return l.Level >= INFO return l.Level >= INFO
} }
// IsPrintEnabled indicates whether output message
func (l *Logger) IsPrintEnabled() bool { func (l *Logger) IsPrintEnabled() bool {
return l.Level > OFF return l.Level > OFF
} }
// IsWarnEnabled indicates whether output message
func (l *Logger) IsWarnEnabled() bool { func (l *Logger) IsWarnEnabled() bool {
return l.Level >= WARN return l.Level >= WARN
} }
// IsErrorEnabled indicates whether output message
func (l *Logger) IsErrorEnabled() bool { func (l *Logger) IsErrorEnabled() bool {
return l.Level >= ERROR return l.Level >= ERROR
} }
// IsPanicEnabled indicates whether output message
func (l *Logger) IsPanicEnabled() bool { func (l *Logger) IsPanicEnabled() bool {
return l.Level >= PANIC return l.Level >= PANIC
} }
// IsFatalEnabled indicates whether output message
func (l *Logger) IsFatalEnabled() bool { func (l *Logger) IsFatalEnabled() bool {
return l.Level >= FATAL return l.Level >= FATAL
} }
// IsDisabled indicates whether output message
func (l *Logger) IsDisabled() bool { func (l *Logger) IsDisabled() bool {
return l.Level <= OFF return l.Level <= OFF
} }
// Debug outputs message, Arguments are handled by fmt.Sprint
func (l *Logger) Debug(obj ...interface{}) { func (l *Logger) Debug(obj ...interface{}) {
if l.Level >= DEBUG { if l.Level >= DEBUG {
l.log(DEBUG, fmt.Sprint(obj...)) l.log(DEBUG, fmt.Sprint(obj...))
} }
} }
// Info outputs message, Arguments are handled by fmt.Sprint
func (l *Logger) Info(obj ...interface{}) { func (l *Logger) Info(obj ...interface{}) {
if l.Level >= INFO { if l.Level >= INFO {
l.log(INFO, fmt.Sprint(obj...)) l.log(INFO, fmt.Sprint(obj...))
} }
} }
// Print outputs message, Arguments are handled by fmt.Sprint
func (l *Logger) Print(obj ...interface{}) { func (l *Logger) Print(obj ...interface{}) {
if l.Level != OFF { if l.Level != OFF {
l.log(INFO, fmt.Sprint(obj...)) l.log(INFO, fmt.Sprint(obj...))
} }
} }
// Warn outputs message, Arguments are handled by fmt.Sprint
func (l *Logger) Warn(obj ...interface{}) { func (l *Logger) Warn(obj ...interface{}) {
if l.Level >= WARN { if l.Level >= WARN {
l.log(WARN, fmt.Sprint(obj...)) l.log(WARN, fmt.Sprint(obj...))
} }
} }
// Error outputs message, Arguments are handled by fmt.Sprint
func (l *Logger) Error(obj ...interface{}) { func (l *Logger) Error(obj ...interface{}) {
if l.Level >= ERROR { if l.Level >= ERROR {
l.log(ERROR, fmt.Sprint(obj...)) l.log(ERROR, fmt.Sprint(obj...))
} }
} }
// Panic outputs message, and followed by a call to panic() Arguments are handled by fmt.Sprint
func (l *Logger) Panic(obj ...interface{}) { func (l *Logger) Panic(obj ...interface{}) {
if l.Level >= PANIC { if l.Level >= PANIC {
l.log(PANIC, fmt.Sprint(obj...)) l.log(PANIC, fmt.Sprint(obj...))
@ -93,6 +110,7 @@ func (l *Logger) Panic(obj ...interface{}) {
panic(fmt.Sprint(obj...)) panic(fmt.Sprint(obj...))
} }
// Fatal outputs message and followed by a call to os.Exit(1), Arguments are handled by fmt.Sprint
func (l *Logger) Fatal(obj ...interface{}) { func (l *Logger) Fatal(obj ...interface{}) {
if l.Level >= FATAL { if l.Level >= FATAL {
l.log(FATAL, fmt.Sprint(obj...)) l.log(FATAL, fmt.Sprint(obj...))
@ -100,36 +118,42 @@ func (l *Logger) Fatal(obj ...interface{}) {
Exit(1) Exit(1)
} }
// Debugln outputs message, Arguments are handled by fmt.Sprintln
func (l *Logger) Debugln(obj ...interface{}) { func (l *Logger) Debugln(obj ...interface{}) {
if l.Level >= DEBUG { if l.Level >= DEBUG {
l.log(DEBUG, vsprintln(obj...)) l.log(DEBUG, vsprintln(obj...))
} }
} }
// Infoln outputs message, Arguments are handled by fmt.Sprintln
func (l *Logger) Infoln(obj ...interface{}) { func (l *Logger) Infoln(obj ...interface{}) {
if l.Level >= INFO { if l.Level >= INFO {
l.log(INFO, vsprintln(obj...)) l.log(INFO, vsprintln(obj...))
} }
} }
// Println outputs message, Arguments are handled by fmt.Sprintln
func (l *Logger) Println(obj ...interface{}) { func (l *Logger) Println(obj ...interface{}) {
if l.Level != OFF { if l.Level != OFF {
l.log(INFO, vsprintln(obj...)) l.log(INFO, vsprintln(obj...))
} }
} }
// Warnln outputs message, Arguments are handled by fmt.Sprintln
func (l *Logger) Warnln(obj ...interface{}) { func (l *Logger) Warnln(obj ...interface{}) {
if l.Level >= WARN { if l.Level >= WARN {
l.log(WARN, vsprintln(obj...)) l.log(WARN, vsprintln(obj...))
} }
} }
// Errorln outputs message, Arguments are handled by fmt.Sprintln
func (l *Logger) Errorln(obj ...interface{}) { func (l *Logger) Errorln(obj ...interface{}) {
if l.Level >= ERROR { if l.Level >= ERROR {
l.log(ERROR, vsprintln(obj...)) l.log(ERROR, vsprintln(obj...))
} }
} }
// Panicln outputs message and followed by a call to panic(), Arguments are handled by fmt.Sprintln
func (l *Logger) Panicln(obj ...interface{}) { func (l *Logger) Panicln(obj ...interface{}) {
if l.Level >= PANIC { if l.Level >= PANIC {
l.log(PANIC, vsprintln(obj...)) l.log(PANIC, vsprintln(obj...))
@ -137,6 +161,7 @@ func (l *Logger) Panicln(obj ...interface{}) {
panic(vsprintln(obj...)) panic(vsprintln(obj...))
} }
// Fatalln outputs message and followed by a call to os.Exit(1), Arguments are handled by fmt.Sprintln
func (l *Logger) Fatalln(obj ...interface{}) { func (l *Logger) Fatalln(obj ...interface{}) {
if l.Level >= FATAL { if l.Level >= FATAL {
l.log(FATAL, vsprintln(obj...)) l.log(FATAL, vsprintln(obj...))
@ -144,36 +169,42 @@ func (l *Logger) Fatalln(obj ...interface{}) {
Exit(1) Exit(1)
} }
// Debugf outputs message, Arguments are handles by fmt.Sprintf
func (l *Logger) Debugf(msg string, args ...interface{}) { func (l *Logger) Debugf(msg string, args ...interface{}) {
if l.Level >= DEBUG { if l.Level >= DEBUG {
l.log(DEBUG, fmt.Sprintf(msg, args...)) l.log(DEBUG, fmt.Sprintf(msg, args...))
} }
} }
// Infof outputs message, Arguments are handles by fmt.Sprintf
func (l *Logger) Infof(msg string, args ...interface{}) { func (l *Logger) Infof(msg string, args ...interface{}) {
if l.Level >= INFO { if l.Level >= INFO {
l.log(INFO, fmt.Sprintf(msg, args...)) l.log(INFO, fmt.Sprintf(msg, args...))
} }
} }
// Printf outputs message, Arguments are handles by fmt.Sprintf
func (l *Logger) Printf(msg string, args ...interface{}) { func (l *Logger) Printf(msg string, args ...interface{}) {
if l.Level != OFF { if l.Level != OFF {
l.log(INFO, fmt.Sprintf(msg, args...)) l.log(INFO, fmt.Sprintf(msg, args...))
} }
} }
// Warnf outputs message, Arguments are handles by fmt.Sprintf
func (l *Logger) Warnf(msg string, args ...interface{}) { func (l *Logger) Warnf(msg string, args ...interface{}) {
if l.Level >= WARN { if l.Level >= WARN {
l.log(WARN, fmt.Sprintf(msg, args...)) l.log(WARN, fmt.Sprintf(msg, args...))
} }
} }
// Errorf outputs message, Arguments are handles by fmt.Sprintf
func (l *Logger) Errorf(msg string, args ...interface{}) { func (l *Logger) Errorf(msg string, args ...interface{}) {
if l.Level >= ERROR { if l.Level >= ERROR {
l.log(ERROR, fmt.Sprintf(msg, args...)) l.log(ERROR, fmt.Sprintf(msg, args...))
} }
} }
// Panicf outputs message and followed by a call to panic(), Arguments are handles by fmt.Sprintf
func (l *Logger) Panicf(msg string, args ...interface{}) { func (l *Logger) Panicf(msg string, args ...interface{}) {
if l.Level >= PANIC { if l.Level >= PANIC {
l.log(PANIC, fmt.Sprintf(msg, args...)) l.log(PANIC, fmt.Sprintf(msg, args...))
@ -181,6 +212,7 @@ func (l *Logger) Panicf(msg string, args ...interface{}) {
panic(fmt.Sprintf(msg, args...)) panic(fmt.Sprintf(msg, args...))
} }
// Fatalf outputs message and followed by a call to os.Exit(1), Arguments are handles by fmt.Sprintf
func (l *Logger) Fatalf(msg string, args ...interface{}) { func (l *Logger) Fatalf(msg string, args ...interface{}) {
if l.Level >= FATAL { if l.Level >= FATAL {
l.log(FATAL, fmt.Sprintf(msg, args...)) l.log(FATAL, fmt.Sprintf(msg, args...))

@ -19,6 +19,7 @@ type AlwaysNewFileWriter struct {
file *os.File file *os.File
} }
// Write implements io.Writer
func (w *AlwaysNewFileWriter) Write(p []byte) (n int, err error) { func (w *AlwaysNewFileWriter) Write(p []byte) (n int, err error) {
if w.file == nil { if w.file == nil {
w.openFile() w.openFile()

@ -20,6 +20,7 @@ type DailyFileWriter struct {
nextDayTime int64 nextDayTime int64
} }
// Write implements io.Writer
func (w *DailyFileWriter) Write(p []byte) (n int, err error) { func (w *DailyFileWriter) Write(p []byte) (n int, err error) {
now := time.Now() now := time.Now()

@ -17,6 +17,7 @@ type FixedSizeFileWriter struct {
currentSize int64 currentSize int64
} }
// Write implements io.Writer
func (w *FixedSizeFileWriter) Write(p []byte) (n int, err error) { func (w *FixedSizeFileWriter) Write(p []byte) (n int, err error) {
if w.file == nil { if w.file == nil {
w.openCurrentFile() w.openCurrentFile()

Loading…
Cancel
Save