Browse Source

Add log config panel in admin

pull/33/head
Unknown 11 years ago
parent
commit
f219ddcf4e
  1. 3
      .gopmfile
  2. 26
      modules/base/conf.go
  3. 3
      routers/admin/admin.go
  4. 16
      templates/admin/config.tmpl

3
.gopmfile

@ -9,13 +9,12 @@ github.com/Unknwon/com=
github.com/Unknwon/cae= github.com/Unknwon/cae=
github.com/Unknwon/goconfig= github.com/Unknwon/goconfig=
github.com/dchest/scrypt= github.com/dchest/scrypt=
github.com/go-sql-driver/mysql=
github.com/lib/pq=
github.com/lunny/xorm= github.com/lunny/xorm=
github.com/gogits/logs= github.com/gogits/logs=
github.com/gogits/binding= github.com/gogits/binding=
github.com/gogits/git= github.com/gogits/git=
github.com/gogits/gfm= github.com/gogits/gfm=
github.com/gogits/cache=
[res] [res]
include=templates|public|conf include=templates|public|conf

26
modules/base/conf.go

@ -43,6 +43,9 @@ var (
Cache cache.Cache Cache cache.Cache
CacheAdapter string CacheAdapter string
CacheConfig string CacheConfig string
LogMode string
LogConfig string
) )
var Service struct { var Service struct {
@ -83,15 +86,15 @@ func newService() {
func newLogService() { func newLogService() {
// Get and check log mode. // Get and check log mode.
mode := Cfg.MustValue("log", "MODE", "console") LogMode = Cfg.MustValue("log", "MODE", "console")
modeSec := "log." + mode modeSec := "log." + LogMode
if _, err := Cfg.GetSection(modeSec); err != nil { if _, err := Cfg.GetSection(modeSec); err != nil {
fmt.Printf("Unknown log mode: %s\n", mode) fmt.Printf("Unknown log mode: %s\n", LogMode)
os.Exit(2) os.Exit(2)
} }
// Log level. // Log level.
levelName := Cfg.MustValue("log."+mode, "LEVEL", "Trace") levelName := Cfg.MustValue("log."+LogMode, "LEVEL", "Trace")
level, ok := logLevels[levelName] level, ok := logLevels[levelName]
if !ok { if !ok {
fmt.Printf("Unknown log level: %s\n", levelName) fmt.Printf("Unknown log level: %s\n", levelName)
@ -99,14 +102,13 @@ func newLogService() {
} }
// Generate log configuration. // Generate log configuration.
var config string switch LogMode {
switch mode {
case "console": case "console":
config = fmt.Sprintf(`{"level":%s}`, level) LogConfig = fmt.Sprintf(`{"level":%s}`, level)
case "file": case "file":
logPath := Cfg.MustValue(modeSec, "FILE_NAME", "log/gogs.log") logPath := Cfg.MustValue(modeSec, "FILE_NAME", "log/gogs.log")
os.MkdirAll(path.Dir(logPath), os.ModePerm) os.MkdirAll(path.Dir(logPath), os.ModePerm)
config = fmt.Sprintf( LogConfig = fmt.Sprintf(
`{"level":%s,"filename":%s,"rotate":%v,"maxlines":%d,"maxsize",%d,"daily":%v,"maxdays":%d}`, level, `{"level":%s,"filename":%s,"rotate":%v,"maxlines":%d,"maxsize",%d,"daily":%v,"maxdays":%d}`, level,
logPath, logPath,
Cfg.MustBool(modeSec, "LOG_ROTATE", true), Cfg.MustBool(modeSec, "LOG_ROTATE", true),
@ -115,13 +117,13 @@ func newLogService() {
Cfg.MustBool(modeSec, "DAILY_ROTATE", true), Cfg.MustBool(modeSec, "DAILY_ROTATE", true),
Cfg.MustInt(modeSec, "MAX_DAYS", 7)) Cfg.MustInt(modeSec, "MAX_DAYS", 7))
case "conn": case "conn":
config = fmt.Sprintf(`{"level":%s,"reconnectOnMsg":%v,"reconnect":%v,"net":%s,"addr":%s}`, level, LogConfig = fmt.Sprintf(`{"level":%s,"reconnectOnMsg":%v,"reconnect":%v,"net":%s,"addr":%s}`, level,
Cfg.MustBool(modeSec, "RECONNECT_ON_MSG", false), Cfg.MustBool(modeSec, "RECONNECT_ON_MSG", false),
Cfg.MustBool(modeSec, "RECONNECT", false), Cfg.MustBool(modeSec, "RECONNECT", false),
Cfg.MustValue(modeSec, "PROTOCOL", "tcp"), Cfg.MustValue(modeSec, "PROTOCOL", "tcp"),
Cfg.MustValue(modeSec, "ADDR", ":7020")) Cfg.MustValue(modeSec, "ADDR", ":7020"))
case "smtp": case "smtp":
config = fmt.Sprintf(`{"level":%s,"username":%s,"password":%s,"host":%s,"sendTos":%s,"subject":%s}`, level, LogConfig = fmt.Sprintf(`{"level":%s,"username":%s,"password":%s,"host":%s,"sendTos":%s,"subject":%s}`, level,
Cfg.MustValue(modeSec, "USER", "example@example.com"), Cfg.MustValue(modeSec, "USER", "example@example.com"),
Cfg.MustValue(modeSec, "PASSWD", "******"), Cfg.MustValue(modeSec, "PASSWD", "******"),
Cfg.MustValue(modeSec, "HOST", "127.0.0.1:25"), Cfg.MustValue(modeSec, "HOST", "127.0.0.1:25"),
@ -129,8 +131,8 @@ func newLogService() {
Cfg.MustValue(modeSec, "SUBJECT", "Diagnostic message from serve")) Cfg.MustValue(modeSec, "SUBJECT", "Diagnostic message from serve"))
} }
log.NewLogger(Cfg.MustInt64("log", "BUFFER_LEN", 10000), mode, config) log.NewLogger(Cfg.MustInt64("log", "BUFFER_LEN", 10000), LogMode, LogConfig)
log.Info("Log Mode: %s(%s)", strings.Title(mode), levelName) log.Info("Log Mode: %s(%s)", strings.Title(LogMode), levelName)
} }
func newCacheService() { func newCacheService() {

3
routers/admin/admin.go

@ -70,5 +70,8 @@ func Config(ctx *middleware.Context) {
ctx.Data["CacheAdapter"] = base.CacheAdapter ctx.Data["CacheAdapter"] = base.CacheAdapter
ctx.Data["CacheConfig"] = base.CacheConfig ctx.Data["CacheConfig"] = base.CacheConfig
ctx.Data["LogMode"] = base.LogMode
ctx.Data["LogConfig"] = base.LogConfig
ctx.HTML(200, "admin/config") ctx.HTML(200, "admin/config")
} }

16
templates/admin/config.tmpl

@ -71,7 +71,21 @@
<div class="panel-body"> <div class="panel-body">
<div><b>Cache Adapter:</b> {{.CacheAdapter}}</div> <div><b>Cache Adapter:</b> {{.CacheAdapter}}</div>
<div><b>Cache Config:</b> <code>{{.CacheConfig}}</code></div> <div><b>Cache Config:</b></div>
<div style="padding-top: 5px;"><pre>{{.CacheConfig}}</pre></div>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading">
Log Configuration
</div>
<div class="panel-body">
<div><b>Log Mode:</b> {{.LogMode}}</div>
<div><b>Log Config:</b></div>
<div style="padding-top: 5px;"><pre>{{.LogConfig}}</pre></div>
</div> </div>
</div> </div>
</div> </div>

Loading…
Cancel
Save