Skip to content

Commit 580ce5d

Browse files
committed
xlog: format the log to left align
1 parent 5e6e5b7 commit 580ce5d

2 files changed

Lines changed: 9 additions & 8 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Protocol is based on [mysqlproto-go](https://github.com/pubnative/mysqlproto-go)
1212
$ mkdir src
1313
$ export GOPATH=`pwd`
1414
$ go get -u github.com/xelabs/go-mysqlstack/driver
15-
$ cd github.com/xelabs/go-mysqlstack/
15+
$ cd src/github.com/xelabs/go-mysqlstack/
1616
$ make test
1717
```
1818

xlog/xlog.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"log"
1616
"log/syslog"
1717
"os"
18+
"strings"
1819
)
1920

2021
var (
@@ -117,39 +118,39 @@ func (t *Log) Debug(format string, v ...interface{}) {
117118
if DEBUG < t.opts.Level {
118119
return
119120
}
120-
t.log("\t [DEBUG] \t%s", fmt.Sprintf(format, v...))
121+
t.log("\t [DEBUG] \t%s", fmt.Sprintf(format, v...))
121122
}
122123

123124
// Info used to log info msg.
124125
func (t *Log) Info(format string, v ...interface{}) {
125126
if INFO < t.opts.Level {
126127
return
127128
}
128-
t.log("\t [INFO] \t%s", fmt.Sprintf(format, v...))
129+
t.log("\t [INFO] \t%s", fmt.Sprintf(format, v...))
129130
}
130131

131132
// Warning used to log warning msg.
132133
func (t *Log) Warning(format string, v ...interface{}) {
133134
if WARNING < t.opts.Level {
134135
return
135136
}
136-
t.log("\t [WARNING] \t%s", fmt.Sprintf(format, v...))
137+
t.log("\t [WARNING] \t%s", fmt.Sprintf(format, v...))
137138
}
138139

139140
// Error used to log error msg.
140141
func (t *Log) Error(format string, v ...interface{}) {
141142
if ERROR < t.opts.Level {
142143
return
143144
}
144-
t.log("\t [ERROR] \t%s", fmt.Sprintf(format, v...))
145+
t.log("\t [ERROR] \t%s", fmt.Sprintf(format, v...))
145146
}
146147

147148
// Fatal used to log faltal msg.
148149
func (t *Log) Fatal(format string, v ...interface{}) {
149150
if FATAL < t.opts.Level {
150151
return
151152
}
152-
t.log("\t [FATAL+EXIT] \t%s", fmt.Sprintf(format, v...))
153+
t.log("\t [FATAL+EXIT] \t%s", fmt.Sprintf(format, v...))
153154
os.Exit(1)
154155
}
155156

@@ -158,7 +159,7 @@ func (t *Log) Panic(format string, v ...interface{}) {
158159
if PANIC < t.opts.Level {
159160
return
160161
}
161-
msg := fmt.Sprintf("\t [PANIC] \t %s", fmt.Sprintf(format, v...))
162+
msg := fmt.Sprintf("\t [PANIC] \t%s", fmt.Sprintf(format, v...))
162163
t.log(msg)
163164
panic(msg)
164165
}
@@ -169,5 +170,5 @@ func (t *Log) Close() {
169170
}
170171

171172
func (t *Log) log(format string, v ...interface{}) {
172-
t.Output(3, fmt.Sprintf(format, v...)+"\n")
173+
t.Output(3, strings.Repeat(" ", 3)+fmt.Sprintf(format, v...)+"\n")
173174
}

0 commit comments

Comments
 (0)