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
f61038e6
Commit
f61038e6
authored
Aug 06, 2017
by
astaxie
Committed by
GitHub
Aug 06, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2803 from iamzhout/log_add_milliseconds
add millisecond to timestamp in log output
parents
e14113aa
b9117e2f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
5 deletions
+12
-5
logger.go
logs/logger.go
+10
-3
logger_test.go
logs/logger_test.go
+2
-2
No files found.
logs/logger.go
View file @
f61038e6
...
...
@@ -87,13 +87,15 @@ const (
mi2
=
`012345678901234567890123456789012345678901234567890123456789`
s1
=
`000000000011111111112222222222333333333344444444445555555555`
s2
=
`012345678901234567890123456789012345678901234567890123456789`
ns1
=
`0123456789`
)
func
formatTimeHeader
(
when
time
.
Time
)
([]
byte
,
int
)
{
y
,
mo
,
d
:=
when
.
Date
()
h
,
mi
,
s
:=
when
.
Clock
()
//len("2006/01/02 15:04:05 ")==20
var
buf
[
20
]
byte
ns
:=
when
.
Nanosecond
()
/
1000000
//len("2006/01/02 15:04:05.123 ")==24
var
buf
[
24
]
byte
buf
[
0
]
=
y1
[
y
/
1000
%
10
]
buf
[
1
]
=
y2
[
y
/
100
]
...
...
@@ -114,7 +116,12 @@ func formatTimeHeader(when time.Time) ([]byte, int) {
buf
[
16
]
=
':'
buf
[
17
]
=
s1
[
s
]
buf
[
18
]
=
s2
[
s
]
buf
[
19
]
=
' '
buf
[
19
]
=
'.'
buf
[
20
]
=
ns1
[
ns
/
100
]
buf
[
21
]
=
ns1
[
ns
%
100
/
10
]
buf
[
22
]
=
ns1
[
ns
%
10
]
buf
[
23
]
=
' '
return
buf
[
0
:
],
d
}
...
...
logs/logger_test.go
View file @
f61038e6
...
...
@@ -31,7 +31,7 @@ func TestFormatHeader_0(t *testing.T) {
break
}
h
,
_
:=
formatTimeHeader
(
tm
)
if
tm
.
Format
(
"2006/01/02 15:04:05 "
)
!=
string
(
h
)
{
if
tm
.
Format
(
"2006/01/02 15:04:05
.999
"
)
!=
string
(
h
)
{
t
.
Log
(
tm
)
t
.
FailNow
()
}
...
...
@@ -49,7 +49,7 @@ func TestFormatHeader_1(t *testing.T) {
break
}
h
,
_
:=
formatTimeHeader
(
tm
)
if
tm
.
Format
(
"2006/01/02 15:04:05 "
)
!=
string
(
h
)
{
if
tm
.
Format
(
"2006/01/02 15:04:05
.999
"
)
!=
string
(
h
)
{
t
.
Log
(
tm
)
t
.
FailNow
()
}
...
...
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