|
@@ -0,0 +1,123 @@
|
|
|
+package xlog
|
|
|
+
|
|
|
+import (
|
|
|
+ "io"
|
|
|
+ "log"
|
|
|
+)
|
|
|
+
|
|
|
+// Logger logger
|
|
|
+type Logger struct {
|
|
|
+ logger *log.Logger
|
|
|
+}
|
|
|
+
|
|
|
+var (
|
|
|
+ defLog *Logger
|
|
|
+)
|
|
|
+
|
|
|
+// New new logger
|
|
|
+func New(w io.Writer) *Logger {
|
|
|
+ logger := log.New(w, "[INFO]", log.Ldate|log.Ltime)
|
|
|
+ return &Logger{logger: logger}
|
|
|
+}
|
|
|
+
|
|
|
+// DefaultLogger defult logger
|
|
|
+func DefaultLogger(w io.Writer) *Logger {
|
|
|
+ return New(w)
|
|
|
+}
|
|
|
+
|
|
|
+// Writer returns the output destination for the standard logger.
|
|
|
+func (l *Logger) Writer() io.Writer {
|
|
|
+ return l.logger.Writer()
|
|
|
+}
|
|
|
+
|
|
|
+// SetOutput sets the output destination for the standard logger.
|
|
|
+func (l *Logger) SetOutput(w io.Writer) {
|
|
|
+ l.logger.SetOutput(w)
|
|
|
+}
|
|
|
+
|
|
|
+// Info log info
|
|
|
+func (l *Logger) Info(v ...interface{}) {
|
|
|
+ l.logger.SetPrefix("[INFO]")
|
|
|
+ l.logger.Println(v...)
|
|
|
+}
|
|
|
+
|
|
|
+// Debug log debug
|
|
|
+func (l *Logger) Debug(v ...interface{}) {
|
|
|
+ l.logger.SetPrefix("[DEBUG]")
|
|
|
+ l.logger.Println(v...)
|
|
|
+}
|
|
|
+
|
|
|
+// Warn log Warn
|
|
|
+func (l *Logger) Warn(v ...interface{}) {
|
|
|
+ l.logger.SetPrefix("[Warn]")
|
|
|
+ l.logger.Println(v...)
|
|
|
+}
|
|
|
+
|
|
|
+// Err log Err
|
|
|
+func (l *Logger) Err(v ...interface{}) {
|
|
|
+ l.logger.SetPrefix("[Err]")
|
|
|
+ l.logger.Println(v...)
|
|
|
+}
|
|
|
+
|
|
|
+// Alert log Alert
|
|
|
+func (l *Logger) Alert(v ...interface{}) {
|
|
|
+ l.logger.SetPrefix("[Alert]")
|
|
|
+ l.logger.Println(v...)
|
|
|
+}
|
|
|
+
|
|
|
+// Fatal log Fatal
|
|
|
+func (l *Logger) Fatal(v ...interface{}) {
|
|
|
+ l.logger.SetPrefix("[Fatal]")
|
|
|
+ l.logger.Println(v...)
|
|
|
+}
|
|
|
+
|
|
|
+// Panic log Panic
|
|
|
+func (l *Logger) Panic(v ...interface{}) {
|
|
|
+ l.logger.SetPrefix("[Panic]")
|
|
|
+ l.logger.Println(v...)
|
|
|
+}
|
|
|
+
|
|
|
+// Writer returns the output destination for the standard logger.
|
|
|
+func Writer() io.Writer {
|
|
|
+ return defLog.Writer()
|
|
|
+}
|
|
|
+
|
|
|
+// SetOutput sets the output destination for the standard logger.
|
|
|
+func SetOutput(w io.Writer) {
|
|
|
+ defLog.SetOutput(w)
|
|
|
+}
|
|
|
+
|
|
|
+// Info info
|
|
|
+func Info(v ...interface{}) {
|
|
|
+ defLog.Info(v...)
|
|
|
+}
|
|
|
+
|
|
|
+// Debug debug
|
|
|
+func Debug(v ...interface{}) {
|
|
|
+ defLog.Debug(v...)
|
|
|
+}
|
|
|
+
|
|
|
+// Warn warn
|
|
|
+func Warn(v ...interface{}) {
|
|
|
+ defLog.Warn(v...)
|
|
|
+}
|
|
|
+
|
|
|
+// Err err
|
|
|
+func Err(v ...interface{}) {
|
|
|
+ defLog.Err(v...)
|
|
|
+}
|
|
|
+
|
|
|
+// Alert alert
|
|
|
+func Alert(v ...interface{}) {
|
|
|
+ defLog.Alert(v...)
|
|
|
+}
|
|
|
+
|
|
|
+// Fatal fatal
|
|
|
+func Fatal(v ...interface{}) {
|
|
|
+ defLog.Fatal(v...)
|
|
|
+}
|
|
|
+
|
|
|
+// Panic panic
|
|
|
+func Panic(v ...interface{}) {
|
|
|
+ defLog.Panic(v...)
|
|
|
+}
|