revert Config.LogDir for ops log
rotate other req dump logs don't create the suspicious reqs log file when it is disabled
This commit is contained in:
parent
d47540391a
commit
faa8be12bb
|
@ -146,7 +146,7 @@ WriteTimeout - The number of seconds that a route is allowed to run for before t
|
||||||
|
|
||||||
IdleTimeout - The number of seconds that a Keep-Alive connection will be kept open before being closed. You might to tweak this, if you use Cloudflare or similar. Defaults to 120.
|
IdleTimeout - The number of seconds that a Keep-Alive connection will be kept open before being closed. You might to tweak this, if you use Cloudflare or similar. Defaults to 120.
|
||||||
|
|
||||||
LogDir - The directory in which logs are stored. Default: ./logs/
|
LogDir - The directory in which logs are stored, with the exception of ops log, until a related bug is resolved. Default: ./logs/
|
||||||
|
|
||||||
DisableSuspLog - Whether suspicious requests are logged in the suspicious request logs. Enabling this may make a site faster. Defaults to false.
|
DisableSuspLog - Whether suspicious requests are logged in the suspicious request logs. Enabling this may make a site faster. Defaults to false.
|
||||||
|
|
||||||
|
|
2
main.go
2
main.go
|
@ -357,7 +357,7 @@ func main() {
|
||||||
|
|
||||||
// TODO: Have a file for each run with the time/date the server started as the file name?
|
// TODO: Have a file for each run with the time/date the server started as the file name?
|
||||||
// TODO: Log panics with recover()
|
// TODO: Log panics with recover()
|
||||||
f, err := os.OpenFile(c.Config.LogDir+"ops-"+strconv.FormatInt(c.StartTime.Unix(), 10)+".log", os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0755)
|
f, err := os.OpenFile("./logs/ops-"+strconv.FormatInt(c.StartTime.Unix(), 10)+".log", os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0755)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
31
router.go
31
router.go
|
@ -37,7 +37,6 @@ type GenRouter struct {
|
||||||
extraRoutes map[string]func(http.ResponseWriter, *http.Request, *c.User) c.RouteError
|
extraRoutes map[string]func(http.ResponseWriter, *http.Request, *c.User) c.RouteError
|
||||||
|
|
||||||
reqLogger *log.Logger
|
reqLogger *log.Logger
|
||||||
//suspReqLogger *log.Logger
|
|
||||||
|
|
||||||
reqLog2 *RouterLog
|
reqLog2 *RouterLog
|
||||||
suspLog *RouterLog
|
suspLog *RouterLog
|
||||||
|
@ -57,10 +56,11 @@ type RouterLog struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *GenRouter) DailyTick() error {
|
func (r *GenRouter) DailyTick() error {
|
||||||
r.suspLog.Lock()
|
rotateLog := func(l *RouterLog, name string) error {
|
||||||
defer r.suspLog.Unlock()
|
l.Lock()
|
||||||
|
defer l.Unlock()
|
||||||
|
|
||||||
f := r.suspLog.FileVal.Load().(*os.File)
|
f := l.FileVal.Load().(*os.File)
|
||||||
stat, err := f.Stat()
|
stat, err := f.Stat()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil
|
return nil
|
||||||
|
@ -73,17 +73,25 @@ func (r *GenRouter) DailyTick() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
stimestr := strconv.FormatInt(c.StartTime.Unix(), 10)
|
stimestr := strconv.FormatInt(c.StartTime.Unix(), 10)
|
||||||
f, err = os.OpenFile(c.Config.LogDir+"reqs-susp-"+stimestr+".log", os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0755)
|
f, err = os.OpenFile(c.Config.LogDir+name+stimestr+".log", os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0755)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
l := log.New(f, "", log.LstdFlags)
|
lval := log.New(f, "", log.LstdFlags)
|
||||||
r.suspLog.FileVal.Store(f)
|
l.FileVal.Store(f)
|
||||||
r.suspLog.LogVal.Store(l)
|
l.LogVal.Store(lval)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !c.Config.DisableSuspLog {
|
||||||
|
err := rotateLog(r.suspLog, "reqs-susp-")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return rotateLog(r.reqLog2, "reqs-")
|
||||||
|
}
|
||||||
|
|
||||||
func NewGenRouter(uploads http.Handler) (*GenRouter, error) {
|
func NewGenRouter(uploads http.Handler) (*GenRouter, error) {
|
||||||
stimestr := strconv.FormatInt(c.StartTime.Unix(), 10)
|
stimestr := strconv.FormatInt(c.StartTime.Unix(), 10)
|
||||||
createLog := func(name, stimestr string) (*RouterLog, error) {
|
createLog := func(name, stimestr string) (*RouterLog, error) {
|
||||||
|
@ -102,10 +110,13 @@ func NewGenRouter(uploads http.Handler) (*GenRouter, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
suspReqLog, err := createLog("reqs-susp", stimestr)
|
var suspReqLog *RouterLog
|
||||||
|
if !c.Config.DisableSuspLog {
|
||||||
|
suspReqLog, err = createLog("reqs-susp", stimestr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
}
|
||||||
f3, err := os.OpenFile(c.Config.LogDir+"reqs-misc-"+stimestr+".log", os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0755)
|
f3, err := os.OpenFile(c.Config.LogDir+"reqs-misc-"+stimestr+".log", os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0755)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
Loading…
Reference in New Issue