Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
B
beego
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
beego
Commits
f73eaf63
Commit
f73eaf63
authored
Jan 26, 2016
by
astaxie
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1626 from JessonChan/develop
log file name bug fixed
parents
01ccc75d
e11d150e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
20 deletions
+17
-20
console.go
logs/console.go
+13
-13
file.go
logs/file.go
+4
-7
No files found.
logs/console.go
View file @
f73eaf63
...
@@ -35,14 +35,14 @@ func newBrush(color string) brush {
...
@@ -35,14 +35,14 @@ func newBrush(color string) brush {
}
}
var
colors
=
[]
brush
{
var
colors
=
[]
brush
{
newBrush
(
"1;37"
),
// Emergency
white
newBrush
(
"1;37"
),
// Emergency
white
newBrush
(
"1;36"
),
// Alert
cyan
newBrush
(
"1;36"
),
// Alert
cyan
newBrush
(
"1;35"
),
// Critical magenta
newBrush
(
"1;35"
),
// Critical
magenta
newBrush
(
"1;31"
),
// Error red
newBrush
(
"1;31"
),
// Error
red
newBrush
(
"1;33"
),
// Warning yellow
newBrush
(
"1;33"
),
// Warning
yellow
newBrush
(
"1;32"
),
// Notice
green
newBrush
(
"1;32"
),
// Notice
green
newBrush
(
"1;34"
),
// Informational
blue
newBrush
(
"1;34"
),
// Informational
blue
newBrush
(
"1;34"
),
// Debug blue
newBrush
(
"1;34"
),
// Debug
blue
}
}
// consoleWriter implements LoggerInterface and writes messages to terminal.
// consoleWriter implements LoggerInterface and writes messages to terminal.
...
@@ -61,12 +61,12 @@ func NewConsole() Logger {
...
@@ -61,12 +61,12 @@ func NewConsole() Logger {
}
}
// Init init console logger.
// Init init console logger.
// json
c
onfig like '{"level":LevelTrace}'.
// json
C
onfig like '{"level":LevelTrace}'.
func
(
c
*
consoleWriter
)
Init
(
json
c
onfig
string
)
error
{
func
(
c
*
consoleWriter
)
Init
(
json
C
onfig
string
)
error
{
if
len
(
json
c
onfig
)
==
0
{
if
len
(
json
C
onfig
)
==
0
{
return
nil
return
nil
}
}
return
json
.
Unmarshal
([]
byte
(
json
c
onfig
),
c
)
return
json
.
Unmarshal
([]
byte
(
json
C
onfig
),
c
)
}
}
// WriteMsg write message in console.
// WriteMsg write message in console.
...
@@ -75,7 +75,7 @@ func (c *consoleWriter) WriteMsg(when time.Time, msg string, level int) error {
...
@@ -75,7 +75,7 @@ func (c *consoleWriter) WriteMsg(when time.Time, msg string, level int) error {
return
nil
return
nil
}
}
msg
=
formatLogTime
(
when
)
+
msg
msg
=
formatLogTime
(
when
)
+
msg
if
goos
:=
runtime
.
GOOS
;
goos
==
"windows"
{
if
runtime
.
GOOS
==
"windows"
{
c
.
lg
.
Println
(
msg
)
c
.
lg
.
Println
(
msg
)
return
nil
return
nil
}
}
...
...
logs/file.go
View file @
f73eaf63
...
@@ -118,19 +118,16 @@ func (w *fileLogWriter) WriteMsg(when time.Time, msg string, level int) error {
...
@@ -118,19 +118,16 @@ func (w *fileLogWriter) WriteMsg(when time.Time, msg string, level int) error {
if
level
>
w
.
Level
{
if
level
>
w
.
Level
{
return
nil
return
nil
}
}
//2016/01/12 21:34:33
// now := time.Now()
d
:=
when
.
Day
()
msg
=
formatLogTime
(
when
)
+
msg
+
"
\n
"
msg
=
formatLogTime
(
when
)
+
msg
+
"
\n
"
if
w
.
Rotate
{
if
w
.
Rotate
{
d
:=
when
.
Day
()
if
w
.
needRotate
(
len
(
msg
),
d
)
{
if
w
.
needRotate
(
len
(
msg
),
d
)
{
w
.
Lock
()
w
.
Lock
()
if
w
.
needRotate
(
len
(
msg
),
d
)
{
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
)
fmt
.
Fprintf
(
os
.
Stderr
,
"FileLogWriter(%q): %s
\n
"
,
w
.
Filename
,
err
)
}
}
}
}
w
.
Unlock
()
w
.
Unlock
()
}
}
...
@@ -200,7 +197,7 @@ func (w *fileLogWriter) lines() (int, error) {
...
@@ -200,7 +197,7 @@ func (w *fileLogWriter) lines() (int, error) {
// DoRotate means it need to write file in new file.
// DoRotate means it need to write file in new file.
// new file name like xx.2013-01-01.2.log
// 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
)
_
,
err
:=
os
.
Lstat
(
w
.
Filename
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
...
@@ -215,7 +212,7 @@ func (w *fileLogWriter) doRotate() error {
...
@@ -215,7 +212,7 @@ func (w *fileLogWriter) doRotate() error {
suffix
=
".log"
suffix
=
".log"
}
}
for
;
err
==
nil
&&
num
<=
999
;
num
++
{
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
)
_
,
err
=
os
.
Lstat
(
fName
)
}
}
// return error if the last file checked still existed
// return error if the last file checked still existed
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment