37 lines
642 B
Go
37 lines
642 B
Go
package main
|
|
|
|
import (
|
|
"log"
|
|
"os"
|
|
"sync"
|
|
"time"
|
|
)
|
|
|
|
var (
|
|
accessLogger *log.Logger
|
|
accessLogDate string
|
|
accessLogMu sync.Mutex
|
|
)
|
|
|
|
func logAccess(format string, v ...interface{}) {
|
|
accessLogMu.Lock()
|
|
defer accessLogMu.Unlock()
|
|
|
|
today := time.Now().Format("2006-01-02")
|
|
if accessLogDate != today {
|
|
if accessLog != nil {
|
|
accessLog.Close()
|
|
}
|
|
f, err := os.OpenFile("/tank/inou/logs/access-"+today+".log", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
|
|
if err != nil {
|
|
return
|
|
}
|
|
accessLog = f
|
|
accessLogger = log.New(f, "", 0)
|
|
accessLogDate = today
|
|
}
|
|
if accessLogger != nil {
|
|
accessLogger.Printf(format, v...)
|
|
}
|
|
}
|