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
2b9d7ff7
Commit
2b9d7ff7
authored
Jan 12, 2016
by
JessonChan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
remove log package
parent
bd0f3c29
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
10 deletions
+42
-10
file.go
logs/file.go
+42
-10
No files found.
logs/file.go
View file @
2b9d7ff7
...
...
@@ -20,7 +20,6 @@ import (
"errors"
"fmt"
"io"
"log"
"os"
"path/filepath"
"strings"
...
...
@@ -31,7 +30,6 @@ import (
// fileLogWriter implements LoggerInterface.
// It writes messages by lines limit, file size limit, or time frequency.
type
fileLogWriter
struct
{
*
log
.
Logger
*
MuxWriter
// The opened file
Filename
string
`json:"filename"`
...
...
@@ -91,8 +89,6 @@ func newFileWriter() Logger {
Perm
:
0660
,
MuxWriter
:
new
(
MuxWriter
),
}
// set MuxWriter as Logger's io.Writer
w
.
Logger
=
log
.
New
(
w
,
""
,
log
.
Ldate
|
log
.
Ltime
)
return
w
}
...
...
@@ -137,8 +133,6 @@ func (w *fileLogWriter) doCheck(size int) {
(
w
.
Daily
&&
time
.
Now
()
.
Day
()
!=
w
.
dailyOpenDate
)
{
if
err
:=
w
.
DoRotate
();
err
!=
nil
{
fmt
.
Fprintf
(
os
.
Stderr
,
"FileLogWriter(%q): %s
\n
"
,
w
.
Filename
,
err
)
w
.
startLock
.
Unlock
()
return
}
}
}
...
...
@@ -152,9 +146,47 @@ func (w *fileLogWriter) WriteMsg(msg string, level int) error {
if
level
>
w
.
Level
{
return
nil
}
n
:=
24
+
len
(
msg
)
// 24 stand for the length "2013/06/23 21:00:22 [T] "
w
.
doCheck
(
n
)
w
.
Logger
.
Println
(
msg
)
//2016/01/12 21:34:33
now
:=
time
.
Now
()
y
,
mo
,
d
:=
now
.
Date
()
h
,
mi
,
s
:=
now
.
Clock
()
//len(2006/01/02 15:03:04)==19
var
buf
[
19
]
byte
t
:=
3
for
y
>=
10
{
p
:=
y
/
10
buf
[
t
]
=
byte
(
'0'
+
y
-
p
*
10
)
y
=
p
t
--
}
buf
[
0
]
=
byte
(
'0'
+
y
)
buf
[
4
]
=
'/'
if
mo
>
9
{
buf
[
5
]
=
'1'
buf
[
6
]
=
byte
(
'0'
+
mo
-
9
)
}
else
{
buf
[
5
]
=
'0'
buf
[
6
]
=
byte
(
'0'
+
mo
)
}
buf
[
7
]
=
'/'
t
=
d
/
10
buf
[
8
]
=
byte
(
'0'
+
t
)
buf
[
9
]
=
byte
(
'0'
+
d
-
t
*
10
)
buf
[
10
]
=
' '
t
=
h
/
10
buf
[
11
]
=
byte
(
'0'
+
t
)
buf
[
12
]
=
byte
(
'0'
+
h
-
t
*
10
)
buf
[
13
]
=
':'
t
=
mi
/
10
buf
[
14
]
=
byte
(
'0'
+
t
)
buf
[
15
]
=
byte
(
'0'
+
mi
-
t
*
10
)
buf
[
16
]
=
':'
t
=
s
/
10
buf
[
17
]
=
byte
(
'0'
+
t
)
buf
[
18
]
=
byte
(
'0'
+
s
-
t
*
10
)
msg
=
string
(
buf
[
0
:
])
+
msg
+
"
\n
"
w
.
doCheck
(
len
(
msg
))
w
.
fd
.
Write
([]
byte
(
msg
))
return
nil
}
...
...
@@ -264,7 +296,7 @@ func (w *fileLogWriter) deleteOldLog() {
filepath
.
Walk
(
dir
,
func
(
path
string
,
info
os
.
FileInfo
,
err
error
)
(
returnErr
error
)
{
defer
func
()
{
if
r
:=
recover
();
r
!=
nil
{
fmt
.
Fprintf
(
os
.
Stderr
,
"Unable to delete old log '%s', error: %
+v
"
,
path
,
r
)
fmt
.
Fprintf
(
os
.
Stderr
,
"Unable to delete old log '%s', error: %
v
\n
"
,
path
,
r
)
}
}()
...
...
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