mirror of
https://github.com/astaxie/beego.git
synced 2024-12-23 03:00:49 +00:00
Merge pull request #1626 from JessonChan/develop
log file name bug fixed
This commit is contained in:
commit
f73eaf6393
@ -35,14 +35,14 @@ func newBrush(color string) brush {
|
||||
}
|
||||
|
||||
var colors = []brush{
|
||||
newBrush("1;37"), // Emergency white
|
||||
newBrush("1;36"), // Alert cyan
|
||||
newBrush("1;35"), // Critical magenta
|
||||
newBrush("1;31"), // Error red
|
||||
newBrush("1;33"), // Warning yellow
|
||||
newBrush("1;32"), // Notice green
|
||||
newBrush("1;34"), // Informational blue
|
||||
newBrush("1;34"), // Debug blue
|
||||
newBrush("1;37"), // Emergency white
|
||||
newBrush("1;36"), // Alert cyan
|
||||
newBrush("1;35"), // Critical magenta
|
||||
newBrush("1;31"), // Error red
|
||||
newBrush("1;33"), // Warning yellow
|
||||
newBrush("1;32"), // Notice green
|
||||
newBrush("1;34"), // Informational blue
|
||||
newBrush("1;34"), // Debug blue
|
||||
}
|
||||
|
||||
// consoleWriter implements LoggerInterface and writes messages to terminal.
|
||||
@ -61,12 +61,12 @@ func NewConsole() Logger {
|
||||
}
|
||||
|
||||
// Init init console logger.
|
||||
// jsonconfig like '{"level":LevelTrace}'.
|
||||
func (c *consoleWriter) Init(jsonconfig string) error {
|
||||
if len(jsonconfig) == 0 {
|
||||
// jsonConfig like '{"level":LevelTrace}'.
|
||||
func (c *consoleWriter) Init(jsonConfig string) error {
|
||||
if len(jsonConfig) == 0 {
|
||||
return nil
|
||||
}
|
||||
return json.Unmarshal([]byte(jsonconfig), c)
|
||||
return json.Unmarshal([]byte(jsonConfig), c)
|
||||
}
|
||||
|
||||
// WriteMsg write message in console.
|
||||
@ -75,7 +75,7 @@ func (c *consoleWriter) WriteMsg(when time.Time, msg string, level int) error {
|
||||
return nil
|
||||
}
|
||||
msg = formatLogTime(when) + msg
|
||||
if goos := runtime.GOOS; goos == "windows" {
|
||||
if runtime.GOOS == "windows" {
|
||||
c.lg.Println(msg)
|
||||
return nil
|
||||
}
|
||||
|
11
logs/file.go
11
logs/file.go
@ -118,19 +118,16 @@ func (w *fileLogWriter) WriteMsg(when time.Time, msg string, level int) error {
|
||||
if level > w.Level {
|
||||
return nil
|
||||
}
|
||||
//2016/01/12 21:34:33
|
||||
// now := time.Now()
|
||||
d := when.Day()
|
||||
msg = formatLogTime(when) + msg + "\n"
|
||||
|
||||
if w.Rotate {
|
||||
d := when.Day()
|
||||
if w.needRotate(len(msg), d) {
|
||||
w.Lock()
|
||||
if w.needRotate(len(msg), d) {
|
||||
if err := w.doRotate(); err != nil {
|
||||
if err := w.doRotate(when); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "FileLogWriter(%q): %s\n", w.Filename, err)
|
||||
}
|
||||
|
||||
}
|
||||
w.Unlock()
|
||||
}
|
||||
@ -200,7 +197,7 @@ func (w *fileLogWriter) lines() (int, error) {
|
||||
|
||||
// DoRotate means it need to write file in new file.
|
||||
// new file name like xx.2013-01-01.2.log
|
||||
func (w *fileLogWriter) doRotate() error {
|
||||
func (w *fileLogWriter) doRotate(logTime time.Time) error {
|
||||
_, err := os.Lstat(w.Filename)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -215,7 +212,7 @@ func (w *fileLogWriter) doRotate() error {
|
||||
suffix = ".log"
|
||||
}
|
||||
for ; err == nil && num <= 999; num++ {
|
||||
fName = filenameOnly + fmt.Sprintf(".%s.%03d%s", time.Now().Format("2006-01-02"), num, suffix)
|
||||
fName = filenameOnly + fmt.Sprintf(".%s.%03d%s", logTime.Format("2006-01-02"), num, suffix)
|
||||
_, err = os.Lstat(fName)
|
||||
}
|
||||
// return error if the last file checked still existed
|
||||
|
Loading…
Reference in New Issue
Block a user