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
05e929ed
Commit
05e929ed
authored
May 22, 2016
by
astaxie
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1948 from nullne/develop
fix bug with file permission in log module
parents
e21b4259
2c123832
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
6 deletions
+32
-6
file.go
logs/file.go
+9
-4
file_test.go
logs/file_test.go
+23
-2
No files found.
logs/file.go
View file @
05e929ed
...
...
@@ -22,6 +22,7 @@ import (
"io"
"os"
"path/filepath"
"strconv"
"strings"
"sync"
"time"
...
...
@@ -53,7 +54,7 @@ type fileLogWriter struct {
Level
int
`json:"level"`
Perm
os
.
FileMode
`json:"perm"`
Perm
string
`json:"perm"`
fileNameOnly
,
suffix
string
// like "project.log", project is fileNameOnly and .log is suffix
}
...
...
@@ -65,7 +66,7 @@ func newFileWriter() Logger {
MaxDays
:
7
,
Rotate
:
true
,
Level
:
LevelTrace
,
Perm
:
0660
,
Perm
:
"0660"
,
}
return
w
}
...
...
@@ -79,7 +80,7 @@ func newFileWriter() Logger {
// "daily":true,
// "maxDays":15,
// "rotate":true,
// "perm":
0600
// "perm":
"0600"
// }
func
(
w
*
fileLogWriter
)
Init
(
jsonConfig
string
)
error
{
err
:=
json
.
Unmarshal
([]
byte
(
jsonConfig
),
w
)
...
...
@@ -153,7 +154,11 @@ func (w *fileLogWriter) WriteMsg(when time.Time, msg string, level int) error {
func
(
w
*
fileLogWriter
)
createLogFile
()
(
*
os
.
File
,
error
)
{
// Open the log file
fd
,
err
:=
os
.
OpenFile
(
w
.
Filename
,
os
.
O_WRONLY
|
os
.
O_APPEND
|
os
.
O_CREATE
,
w
.
Perm
)
perm
,
err
:=
strconv
.
ParseInt
(
w
.
Perm
,
8
,
64
)
if
err
!=
nil
{
return
nil
,
err
}
fd
,
err
:=
os
.
OpenFile
(
w
.
Filename
,
os
.
O_WRONLY
|
os
.
O_APPEND
|
os
.
O_CREATE
,
os
.
FileMode
(
perm
))
return
fd
,
err
}
...
...
logs/file_test.go
View file @
05e929ed
...
...
@@ -24,6 +24,27 @@ import (
"time"
)
func
TestFilePerm
(
t
*
testing
.
T
)
{
log
:=
NewLogger
(
10000
)
log
.
SetLogger
(
"file"
,
`{"filename":"test.log", "perm": "0600"}`
)
log
.
Debug
(
"debug"
)
log
.
Informational
(
"info"
)
log
.
Notice
(
"notice"
)
log
.
Warning
(
"warning"
)
log
.
Error
(
"error"
)
log
.
Alert
(
"alert"
)
log
.
Critical
(
"critical"
)
log
.
Emergency
(
"emergency"
)
file
,
err
:=
os
.
Stat
(
"test.log"
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
file
.
Mode
()
!=
0600
{
t
.
Fatal
(
"unexpected log file permission"
)
}
os
.
Remove
(
"test.log"
)
}
func
TestFile1
(
t
*
testing
.
T
)
{
log
:=
NewLogger
(
10000
)
log
.
SetLogger
(
"file"
,
`{"filename":"test.log"}`
)
...
...
@@ -147,7 +168,7 @@ func testFileRotate(t *testing.T, fn1, fn2 string) {
MaxDays
:
7
,
Rotate
:
true
,
Level
:
LevelTrace
,
Perm
:
0660
,
Perm
:
"0660"
,
}
fw
.
Init
(
fmt
.
Sprintf
(
`{"filename":"%v","maxdays":1}`
,
fn1
))
fw
.
dailyOpenTime
=
time
.
Now
()
.
Add
(
-
24
*
time
.
Hour
)
...
...
@@ -170,7 +191,7 @@ func testFileDailyRotate(t *testing.T, fn1, fn2 string) {
MaxDays
:
7
,
Rotate
:
true
,
Level
:
LevelTrace
,
Perm
:
0660
,
Perm
:
"0660"
,
}
fw
.
Init
(
fmt
.
Sprintf
(
`{"filename":"%v","maxdays":1}`
,
fn1
))
fw
.
dailyOpenTime
=
time
.
Now
()
.
Add
(
-
24
*
time
.
Hour
)
...
...
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