parent
68938d5dc4
commit
464dcd1b66
2 changed files with 3 additions and 22 deletions
|
@ -8,7 +8,6 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
@ -25,9 +24,6 @@ type FileLogWriter struct {
|
||||||
// The opened file
|
// The opened file
|
||||||
Filename string `json:"filename"`
|
Filename string `json:"filename"`
|
||||||
|
|
||||||
Maxlines int `json:"maxlines"`
|
|
||||||
maxlinesCurlines int
|
|
||||||
|
|
||||||
// Rotate at size
|
// Rotate at size
|
||||||
Maxsize int `json:"maxsize"`
|
Maxsize int `json:"maxsize"`
|
||||||
maxsizeCursize int
|
maxsizeCursize int
|
||||||
|
@ -69,7 +65,6 @@ func (l *MuxWriter) SetFd(fd *os.File) {
|
||||||
func NewFileWriter() LoggerInterface {
|
func NewFileWriter() LoggerInterface {
|
||||||
w := &FileLogWriter{
|
w := &FileLogWriter{
|
||||||
Filename: "",
|
Filename: "",
|
||||||
Maxlines: 1000000,
|
|
||||||
Maxsize: 1 << 28, //256 MB
|
Maxsize: 1 << 28, //256 MB
|
||||||
Daily: true,
|
Daily: true,
|
||||||
Maxdays: 7,
|
Maxdays: 7,
|
||||||
|
@ -87,7 +82,6 @@ func NewFileWriter() LoggerInterface {
|
||||||
// config like:
|
// config like:
|
||||||
// {
|
// {
|
||||||
// "filename":"log/gogs.log",
|
// "filename":"log/gogs.log",
|
||||||
// "maxlines":10000,
|
|
||||||
// "maxsize":1<<30,
|
// "maxsize":1<<30,
|
||||||
// "daily":true,
|
// "daily":true,
|
||||||
// "maxdays":15,
|
// "maxdays":15,
|
||||||
|
@ -116,15 +110,13 @@ func (w *FileLogWriter) StartLogger() error {
|
||||||
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.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.maxsizeCursize += size
|
w.maxsizeCursize += size
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -152,15 +144,6 @@ func (w *FileLogWriter) initFd() error {
|
||||||
}
|
}
|
||||||
w.maxsizeCursize = int(finfo.Size())
|
w.maxsizeCursize = int(finfo.Size())
|
||||||
w.dailyOpenDate = time.Now().Day()
|
w.dailyOpenDate = time.Now().Day()
|
||||||
if finfo.Size() > 0 {
|
|
||||||
content, err := ioutil.ReadFile(w.Filename)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
w.maxlinesCurlines = len(strings.Split(string(content), "\n"))
|
|
||||||
} else {
|
|
||||||
w.maxlinesCurlines = 0
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1325,10 +1325,9 @@ func newLogService() {
|
||||||
}
|
}
|
||||||
|
|
||||||
LogConfigs[i] = fmt.Sprintf(
|
LogConfigs[i] = fmt.Sprintf(
|
||||||
`{"level":%s,"filename":"%s","rotate":%v,"maxlines":%d,"maxsize":%d,"daily":%v,"maxdays":%d}`, level,
|
`{"level":%s,"filename":"%s","rotate":%v,"maxsize":%d,"daily":%v,"maxdays":%d}`, level,
|
||||||
logPath,
|
logPath,
|
||||||
sec.Key("LOG_ROTATE").MustBool(true),
|
sec.Key("LOG_ROTATE").MustBool(true),
|
||||||
sec.Key("MAX_LINES").MustInt(1000000),
|
|
||||||
1<<uint(sec.Key("MAX_SIZE_SHIFT").MustInt(28)),
|
1<<uint(sec.Key("MAX_SIZE_SHIFT").MustInt(28)),
|
||||||
sec.Key("DAILY_ROTATE").MustBool(true),
|
sec.Key("DAILY_ROTATE").MustBool(true),
|
||||||
sec.Key("MAX_DAYS").MustInt(7))
|
sec.Key("MAX_DAYS").MustInt(7))
|
||||||
|
@ -1391,10 +1390,9 @@ func NewXORMLogService(disableConsole bool) {
|
||||||
logPath = path.Join(filepath.Dir(logPath), "xorm.log")
|
logPath = path.Join(filepath.Dir(logPath), "xorm.log")
|
||||||
|
|
||||||
logConfigs = fmt.Sprintf(
|
logConfigs = fmt.Sprintf(
|
||||||
`{"level":%s,"filename":"%s","rotate":%v,"maxlines":%d,"maxsize":%d,"daily":%v,"maxdays":%d}`, level,
|
`{"level":%s,"filename":"%s","rotate":%v,"maxsize":%d,"daily":%v,"maxdays":%d}`, level,
|
||||||
logPath,
|
logPath,
|
||||||
sec.Key("LOG_ROTATE").MustBool(true),
|
sec.Key("LOG_ROTATE").MustBool(true),
|
||||||
sec.Key("MAX_LINES").MustInt(1000000),
|
|
||||||
1<<uint(sec.Key("MAX_SIZE_SHIFT").MustInt(28)),
|
1<<uint(sec.Key("MAX_SIZE_SHIFT").MustInt(28)),
|
||||||
sec.Key("DAILY_ROTATE").MustBool(true),
|
sec.Key("DAILY_ROTATE").MustBool(true),
|
||||||
sec.Key("MAX_DAYS").MustInt(7))
|
sec.Key("MAX_DAYS").MustInt(7))
|
||||||
|
|
Reference in a new issue