Defering such things is more gopher way.
This commit is contained in:
parent
5f8b6d2b09
commit
2c567fd1e5
@ -30,6 +30,7 @@ func NewLogger(path string, toStdout bool) (*Logger, error) {
|
|||||||
|
|
||||||
func (l *Logger) Println(v ...interface{}) {
|
func (l *Logger) Println(v ...interface{}) {
|
||||||
l.mut.Lock()
|
l.mut.Lock()
|
||||||
|
defer l.mut.Unlock()
|
||||||
|
|
||||||
nowStr := time.Now().UTC().Format(time.RFC3339)
|
nowStr := time.Now().UTC().Format(time.RFC3339)
|
||||||
|
|
||||||
@ -38,12 +39,11 @@ func (l *Logger) Println(v ...interface{}) {
|
|||||||
if l.toStdout {
|
if l.toStdout {
|
||||||
fmt.Println(nowStr, v)
|
fmt.Println(nowStr, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
l.mut.Unlock()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *Logger) Printf(format string, v ...interface{}) {
|
func (l *Logger) Printf(format string, v ...interface{}) {
|
||||||
l.mut.Lock()
|
l.mut.Lock()
|
||||||
|
defer l.mut.Unlock()
|
||||||
|
|
||||||
// Ensure a new line will be written
|
// Ensure a new line will be written
|
||||||
if !strings.HasSuffix(format, "\n") {
|
if !strings.HasSuffix(format, "\n") {
|
||||||
@ -57,8 +57,6 @@ func (l *Logger) Printf(format string, v ...interface{}) {
|
|||||||
if l.toStdout {
|
if l.toStdout {
|
||||||
fmt.Printf(nowStr+" "+format, v...)
|
fmt.Printf(nowStr+" "+format, v...)
|
||||||
}
|
}
|
||||||
|
|
||||||
l.mut.Unlock()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *Logger) Fatalln(v ...interface{}) {
|
func (l *Logger) Fatalln(v ...interface{}) {
|
||||||
|
Loading…
Reference in New Issue
Block a user