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
b80cdef2
Commit
b80cdef2
authored
Nov 23, 2014
by
astaxie
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #932 from DeanThompson/master
count log file lines
parents
98dcee06
6a9d04c2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
3 deletions
+31
-3
file.go
logs/file.go
+31
-3
No files found.
logs/file.go
View file @
b80cdef2
...
...
@@ -15,10 +15,11 @@
package
logs
import
(
"bytes"
"encoding/json"
"errors"
"fmt"
"io
/ioutil
"
"io"
"log"
"os"
"path/filepath"
...
...
@@ -170,17 +171,44 @@ func (w *FileLogWriter) initFd() error {
w
.
maxsize_cursize
=
int
(
finfo
.
Size
())
w
.
daily_opendate
=
time
.
Now
()
.
Day
()
if
finfo
.
Size
()
>
0
{
co
ntent
,
err
:=
ioutil
.
ReadFile
(
w
.
Filename
)
co
unt
,
err
:=
w
.
lines
(
)
if
err
!=
nil
{
return
err
}
w
.
maxlines_curlines
=
len
(
strings
.
Split
(
string
(
content
),
"
\n
"
))
w
.
maxlines_curlines
=
count
}
else
{
w
.
maxlines_curlines
=
0
}
return
nil
}
func
(
w
*
FileLogWriter
)
lines
()
(
int
,
error
)
{
fd
,
err
:=
os
.
Open
(
w
.
Filename
)
if
err
!=
nil
{
return
0
,
err
}
defer
fd
.
Close
()
buf
:=
make
([]
byte
,
32768
)
// 32k
count
:=
0
lineSep
:=
[]
byte
{
'\n'
}
for
{
c
,
err
:=
fd
.
Read
(
buf
)
if
err
!=
nil
&&
err
!=
io
.
EOF
{
return
count
,
err
}
count
+=
bytes
.
Count
(
buf
[
:
c
],
lineSep
)
if
err
==
io
.
EOF
{
break
}
}
return
count
,
nil
}
// DoRotate means it need to write file in new file.
// new file name like xx.log.2013-01-01.2
func
(
w
*
FileLogWriter
)
DoRotate
()
error
{
...
...
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