Skip to content

Commit

Permalink
logger: Write logs to debug.log file
Browse files Browse the repository at this point in the history
  • Loading branch information
const-subject committed Sep 3, 2018
1 parent d7b0272 commit f9c669f
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion logger/logger.go
Expand Up @@ -10,6 +10,7 @@ package logger

import (
"fmt"
"os"
"time"
)

Expand All @@ -24,6 +25,7 @@ const (
)

var logLevel = logDebug
var f, _ = os.OpenFile("debug.log", os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0600)

// Init initializes a logger with the required type.
func Init(level string) {
Expand Down Expand Up @@ -71,7 +73,11 @@ func Fatal(text ...interface{}) {
}

func print(prefix interface{}, text ...interface{}) {
tm := time.Now().Format("2006-01-02 15:04:05 ")

fmt.Print(fmt.Sprintf("%s%s%s %s%s ", styleYellow, prefix, styleGray, time.Now().Format("2006-01-02 15:04:05"), styleReset))
f.WriteString(tm)
f.WriteString(fmt.Sprintln(text...))

fmt.Print(fmt.Sprintf("%s%s%s %s%s ", styleYellow, prefix, styleGray, tm, styleReset))
fmt.Println(text...)
}

0 comments on commit f9c669f

Please sign in to comment.