|
|
@ -21,6 +21,7 @@ import ( |
|
|
|
"github.com/go-xorm/core" |
|
|
|
"github.com/go-xorm/core" |
|
|
|
"github.com/go-xorm/xorm" |
|
|
|
"github.com/go-xorm/xorm" |
|
|
|
_ "github.com/lib/pq" |
|
|
|
_ "github.com/lib/pq" |
|
|
|
|
|
|
|
log "gopkg.in/clog.v1" |
|
|
|
|
|
|
|
|
|
|
|
"github.com/gogits/gogs/models/migrations" |
|
|
|
"github.com/gogits/gogs/models/migrations" |
|
|
|
"github.com/gogits/gogs/modules/setting" |
|
|
|
"github.com/gogits/gogs/modules/setting" |
|
|
@ -192,18 +193,23 @@ func SetEngine() (err error) { |
|
|
|
|
|
|
|
|
|
|
|
// WARNING: for serv command, MUST remove the output to os.stdout,
|
|
|
|
// WARNING: for serv command, MUST remove the output to os.stdout,
|
|
|
|
// so use log file to instead print to stdout.
|
|
|
|
// so use log file to instead print to stdout.
|
|
|
|
logPath := path.Join(setting.LogRootPath, "xorm.log") |
|
|
|
sec := setting.Cfg.Section("log.xorm") |
|
|
|
os.MkdirAll(path.Dir(logPath), os.ModePerm) |
|
|
|
fmt.Println(sec.Key("ROTATE_DAILY").MustBool(true)) |
|
|
|
|
|
|
|
logger, err := log.NewFileWriter(path.Join(setting.LogRootPath, "xorm.log"), |
|
|
|
f, err := os.Create(logPath) |
|
|
|
log.FileRotationConfig{ |
|
|
|
|
|
|
|
Rotate: sec.Key("ROTATE").MustBool(true), |
|
|
|
|
|
|
|
Daily: sec.Key("ROTATE_DAILY").MustBool(true), |
|
|
|
|
|
|
|
MaxSize: sec.Key("MAX_SIZE").MustInt64(100) * 1024 * 1024, |
|
|
|
|
|
|
|
MaxDays: sec.Key("MAX_DAYS").MustInt64(3), |
|
|
|
|
|
|
|
}) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return fmt.Errorf("Fail to create xorm.log: %v", err) |
|
|
|
return fmt.Errorf("Fail to create 'xorm.log': %v", err) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if setting.ProdMode { |
|
|
|
if setting.ProdMode { |
|
|
|
x.SetLogger(xorm.NewSimpleLogger3(f, xorm.DEFAULT_LOG_PREFIX, xorm.DEFAULT_LOG_FLAG, core.LOG_WARNING)) |
|
|
|
x.SetLogger(xorm.NewSimpleLogger3(logger, xorm.DEFAULT_LOG_PREFIX, xorm.DEFAULT_LOG_FLAG, core.LOG_WARNING)) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
x.SetLogger(xorm.NewSimpleLogger(f)) |
|
|
|
x.SetLogger(xorm.NewSimpleLogger(logger)) |
|
|
|
} |
|
|
|
} |
|
|
|
x.ShowSQL(true) |
|
|
|
x.ShowSQL(true) |
|
|
|
return nil |
|
|
|
return nil |
|
|
|