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
8ce9f69b
Commit
8ce9f69b
authored
Mar 30, 2016
by
astaxie
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1843 from JessonChan/beelog_bug_fix
Beelog bug fix
parents
220cf911
96a5d09e
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
89 additions
and
29 deletions
+89
-29
log.go
logs/log.go
+1
-1
logger.go
logs/logger.go
+31
-28
logger_test.go
logs/logger_test.go
+57
-0
No files found.
logs/log.go
View file @
8ce9f69b
...
@@ -255,7 +255,7 @@ func (bl *BeeLogger) Write(p []byte) (n int, err error) {
...
@@ -255,7 +255,7 @@ func (bl *BeeLogger) Write(p []byte) (n int, err error) {
}
}
func
(
bl
*
BeeLogger
)
writeMsg
(
logLevel
int
,
msg
string
,
v
...
interface
{})
error
{
func
(
bl
*
BeeLogger
)
writeMsg
(
logLevel
int
,
msg
string
,
v
...
interface
{})
error
{
if
!
b
eeLogger
.
init
{
if
!
b
l
.
init
{
bl
.
lock
.
Lock
()
bl
.
lock
.
Lock
()
bl
.
setLogger
(
AdapterConsole
)
bl
.
setLogger
(
AdapterConsole
)
bl
.
lock
.
Unlock
()
bl
.
lock
.
Unlock
()
...
...
logs/logger.go
View file @
8ce9f69b
...
@@ -36,43 +36,46 @@ func (lg *logWriter) println(when time.Time, msg string) {
...
@@ -36,43 +36,46 @@ func (lg *logWriter) println(when time.Time, msg string) {
lg
.
Unlock
()
lg
.
Unlock
()
}
}
const
y1
=
`0000000000111111111122222222223333333333444444444455555555556666666666777777777788888888889999999999`
const
y2
=
`0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789`
const
mo1
=
`000000000111`
const
mo2
=
`123456789012`
const
d1
=
`0000000001111111111222222222233`
const
d2
=
`1234567890123456789012345678901`
const
h1
=
`000000000011111111112222`
const
h2
=
`012345678901234567890123`
const
mi1
=
`000000000011111111112222222222333333333344444444445555555555`
const
mi2
=
`012345678901234567890123456789012345678901234567890123456789`
const
s1
=
`000000000011111111112222222222333333333344444444445555555555`
const
s2
=
`012345678901234567890123456789012345678901234567890123456789`
func
formatTimeHeader
(
when
time
.
Time
)
([]
byte
,
int
)
{
func
formatTimeHeader
(
when
time
.
Time
)
([]
byte
,
int
)
{
y
,
mo
,
d
:=
when
.
Date
()
y
,
mo
,
d
:=
when
.
Date
()
h
,
mi
,
s
:=
when
.
Clock
()
h
,
mi
,
s
:=
when
.
Clock
()
//len(
2006/01/02 15:03:04)==19
//len(
"2006/01/02 15:04:05 ")==20
var
buf
[
20
]
byte
var
buf
[
20
]
byte
t
:=
3
for
y
>=
10
{
//change to '3' after 984 years, LOL
p
:=
y
/
10
buf
[
0
]
=
'2'
buf
[
t
]
=
byte
(
'0'
+
y
-
p
*
10
)
//change to '1' after 84 years, LOL
y
=
p
buf
[
1
]
=
'0'
t
--
buf
[
2
]
=
y1
[
y
-
2000
]
}
buf
[
3
]
=
y2
[
y
-
2000
]
buf
[
0
]
=
byte
(
'0'
+
y
)
buf
[
4
]
=
'/'
buf
[
4
]
=
'/'
if
mo
>
9
{
buf
[
5
]
=
mo1
[
mo
-
1
]
buf
[
5
]
=
'1'
buf
[
6
]
=
mo2
[
mo
-
1
]
buf
[
6
]
=
byte
(
'0'
+
mo
-
9
)
}
else
{
buf
[
5
]
=
'0'
buf
[
6
]
=
byte
(
'0'
+
mo
)
}
buf
[
7
]
=
'/'
buf
[
7
]
=
'/'
t
=
d
/
10
buf
[
8
]
=
d1
[
d
-
1
]
buf
[
8
]
=
byte
(
'0'
+
t
)
buf
[
9
]
=
d2
[
d
-
1
]
buf
[
9
]
=
byte
(
'0'
+
d
-
t
*
10
)
buf
[
10
]
=
' '
buf
[
10
]
=
' '
t
=
h
/
10
buf
[
11
]
=
h1
[
h
]
buf
[
11
]
=
byte
(
'0'
+
t
)
buf
[
12
]
=
h2
[
h
]
buf
[
12
]
=
byte
(
'0'
+
h
-
t
*
10
)
buf
[
13
]
=
':'
buf
[
13
]
=
':'
t
=
mi
/
10
buf
[
14
]
=
mi1
[
mi
]
buf
[
14
]
=
byte
(
'0'
+
t
)
buf
[
15
]
=
mi2
[
mi
]
buf
[
15
]
=
byte
(
'0'
+
mi
-
t
*
10
)
buf
[
16
]
=
':'
buf
[
16
]
=
':'
t
=
s
/
10
buf
[
17
]
=
s1
[
s
]
buf
[
17
]
=
byte
(
'0'
+
t
)
buf
[
18
]
=
s2
[
s
]
buf
[
18
]
=
byte
(
'0'
+
s
-
t
*
10
)
buf
[
19
]
=
' '
buf
[
19
]
=
' '
return
buf
[
0
:
],
d
return
buf
[
0
:
],
d
...
...
logs/logger_test.go
0 → 100644
View file @
8ce9f69b
// Copyright 2016 beego Author. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package
logs
import
(
"testing"
"time"
)
func
TestFormatHeader_0
(
t
*
testing
.
T
)
{
tm
:=
time
.
Now
()
if
tm
.
Year
()
>=
2100
{
t
.
FailNow
()
}
dur
:=
time
.
Second
for
{
if
tm
.
Year
()
>=
2100
{
break
}
h
,
_
:=
formatTimeHeader
(
tm
)
if
tm
.
Format
(
"2006/01/02 15:04:05 "
)
!=
string
(
h
)
{
t
.
Log
(
tm
)
t
.
FailNow
()
}
tm
=
tm
.
Add
(
dur
)
dur
*=
2
}
}
func
TestFormatHeader_1
(
t
*
testing
.
T
)
{
tm
:=
time
.
Now
()
year
:=
tm
.
Year
()
dur
:=
time
.
Second
for
{
if
tm
.
Year
()
>=
year
+
1
{
break
}
h
,
_
:=
formatTimeHeader
(
tm
)
if
tm
.
Format
(
"2006/01/02 15:04:05 "
)
!=
string
(
h
)
{
t
.
Log
(
tm
)
t
.
FailNow
()
}
tm
=
tm
.
Add
(
dur
)
}
}
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