mirror of
https://github.com/astaxie/beego.git
synced 2024-11-26 07:01:28 +00:00
camel name fixed
This commit is contained in:
parent
2479e61db9
commit
9507e59c2f
56
logs/file.go
56
logs/file.go
@ -36,17 +36,17 @@ type fileLogWriter struct {
|
|||||||
// The opened file
|
// The opened file
|
||||||
Filename string `json:"filename"`
|
Filename string `json:"filename"`
|
||||||
|
|
||||||
Maxlines int `json:"maxlines"`
|
MaxLines int `json:"maxlines"`
|
||||||
maxlinesCurlines int
|
maxLinesCurLines int
|
||||||
|
|
||||||
// Rotate at size
|
// Rotate at size
|
||||||
Maxsize int `json:"maxsize"`
|
MaxSize int `json:"maxsize"`
|
||||||
maxsizeCursize int
|
maxSizeCurSize int
|
||||||
|
|
||||||
// Rotate daily
|
// Rotate daily
|
||||||
Daily bool `json:"daily"`
|
Daily bool `json:"daily"`
|
||||||
Maxdays int64 `json:"maxdays"`
|
MaxDays int64 `json:"maxdays"`
|
||||||
dailyOpendate int
|
dailyOpenDate int
|
||||||
|
|
||||||
Rotate bool `json:"rotate"`
|
Rotate bool `json:"rotate"`
|
||||||
|
|
||||||
@ -63,7 +63,7 @@ type MuxWriter struct {
|
|||||||
fd *os.File
|
fd *os.File
|
||||||
}
|
}
|
||||||
|
|
||||||
// write to os.File.
|
// Write to os.File.
|
||||||
func (l *MuxWriter) Write(b []byte) (int, error) {
|
func (l *MuxWriter) Write(b []byte) (int, error) {
|
||||||
l.Lock()
|
l.Lock()
|
||||||
defer l.Unlock()
|
defer l.Unlock()
|
||||||
@ -82,10 +82,10 @@ func (l *MuxWriter) SetFd(fd *os.File) {
|
|||||||
func newFileWriter() Logger {
|
func newFileWriter() Logger {
|
||||||
w := &fileLogWriter{
|
w := &fileLogWriter{
|
||||||
Filename: "",
|
Filename: "",
|
||||||
Maxlines: 1000000,
|
MaxLines: 1000000,
|
||||||
Maxsize: 1 << 28, //256 MB
|
MaxSize: 1 << 28, //256 MB
|
||||||
Daily: true,
|
Daily: true,
|
||||||
Maxdays: 7,
|
MaxDays: 7,
|
||||||
Rotate: true,
|
Rotate: true,
|
||||||
Level: LevelTrace,
|
Level: LevelTrace,
|
||||||
Perm: 0660,
|
Perm: 0660,
|
||||||
@ -98,18 +98,18 @@ func newFileWriter() Logger {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Init file logger with json config.
|
// Init file logger with json config.
|
||||||
// jsonconfig like:
|
// jsonConfig like:
|
||||||
// {
|
// {
|
||||||
// "filename":"logs/beego.log",
|
// "filename":"logs/beego.log",
|
||||||
// "maxlines":10000,
|
// "maxLines":10000,
|
||||||
// "maxsize":1<<30,
|
// "maxsize":1<<30,
|
||||||
// "daily":true,
|
// "daily":true,
|
||||||
// "maxdays":15,
|
// "maxDays":15,
|
||||||
// "rotate":true,
|
// "rotate":true,
|
||||||
// "perm":0600
|
// "perm":0600
|
||||||
// }
|
// }
|
||||||
func (w *fileLogWriter) Init(jsonconfig string) error {
|
func (w *fileLogWriter) Init(jsonConfig string) error {
|
||||||
err := json.Unmarshal([]byte(jsonconfig), w)
|
err := json.Unmarshal([]byte(jsonConfig), w)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -130,19 +130,19 @@ func (w *fileLogWriter) startLogger() error {
|
|||||||
return w.initFd()
|
return w.initFd()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *fileLogWriter) docheck(size int) {
|
func (w *fileLogWriter) doCheck(size int) {
|
||||||
w.startLock.Lock()
|
w.startLock.Lock()
|
||||||
defer w.startLock.Unlock()
|
defer w.startLock.Unlock()
|
||||||
if w.Rotate && ((w.Maxlines > 0 && w.maxlinesCurlines >= w.Maxlines) ||
|
if w.Rotate && ((w.MaxLines > 0 && w.maxLinesCurLines >= w.MaxLines) ||
|
||||||
(w.Maxsize > 0 && w.maxsizeCursize >= w.Maxsize) ||
|
(w.MaxSize > 0 && w.maxSizeCurSize >= w.MaxSize) ||
|
||||||
(w.Daily && time.Now().Day() != w.dailyOpendate)) {
|
(w.Daily && time.Now().Day() != w.dailyOpenDate)) {
|
||||||
if err := w.DoRotate(); err != nil {
|
if err := w.DoRotate(); err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "FileLogWriter(%q): %s\n", w.Filename, err)
|
fmt.Fprintf(os.Stderr, "FileLogWriter(%q): %s\n", w.Filename, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
w.maxlinesCurlines++
|
w.maxLinesCurLines++
|
||||||
w.maxsizeCursize += size
|
w.maxSizeCurSize += size
|
||||||
}
|
}
|
||||||
|
|
||||||
// WriteMsg write logger message into file.
|
// WriteMsg write logger message into file.
|
||||||
@ -151,7 +151,7 @@ func (w *fileLogWriter) WriteMsg(msg string, level int) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
n := 24 + len(msg) // 24 stand for the length "2013/06/23 21:00:22 [T] "
|
n := 24 + len(msg) // 24 stand for the length "2013/06/23 21:00:22 [T] "
|
||||||
w.docheck(n)
|
w.doCheck(n)
|
||||||
w.Logger.Println(msg)
|
w.Logger.Println(msg)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -168,15 +168,15 @@ func (w *fileLogWriter) initFd() error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("get stat err: %s\n", err)
|
return fmt.Errorf("get stat err: %s\n", err)
|
||||||
}
|
}
|
||||||
w.maxsizeCursize = int(finfo.Size())
|
w.maxSizeCurSize = int(finfo.Size())
|
||||||
w.dailyOpendate = time.Now().Day()
|
w.dailyOpenDate = time.Now().Day()
|
||||||
w.maxlinesCurlines = 0
|
w.maxLinesCurLines = 0
|
||||||
if finfo.Size() > 0 {
|
if finfo.Size() > 0 {
|
||||||
count, err := w.lines()
|
count, err := w.lines()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
w.maxlinesCurlines = count
|
w.maxLinesCurLines = count
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -266,7 +266,7 @@ func (w *fileLogWriter) deleteOldLog() {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
if !info.IsDir() && info.ModTime().Unix() < (time.Now().Unix()-60*60*24*w.Maxdays) {
|
if !info.IsDir() && info.ModTime().Unix() < (time.Now().Unix()-60*60*24*w.MaxDays) {
|
||||||
if strings.HasPrefix(filepath.Base(path), filepath.Base(w.Filename)) {
|
if strings.HasPrefix(filepath.Base(path), filepath.Base(w.Filename)) {
|
||||||
os.Remove(path)
|
os.Remove(path)
|
||||||
}
|
}
|
||||||
@ -275,7 +275,7 @@ func (w *fileLogWriter) deleteOldLog() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destroy close the file desciption, close file writer.
|
// Destroy close the file description, close file writer.
|
||||||
func (w *fileLogWriter) Destroy() {
|
func (w *fileLogWriter) Destroy() {
|
||||||
w.mw.fd.Close()
|
w.mw.fd.Close()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user