Skip to content

Commit

Permalink
深夜Art版
Browse files Browse the repository at this point in the history
#### Version 1.2.1
* 启动日志增加dotweb ASCII art logo
* 调整默认日志的时间毫秒段为4位
* 2017-10-05 22:00
  • Loading branch information
[email protected] committed Oct 5, 2017
1 parent d7de21a commit 7b03d7b
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 3 deletions.
12 changes: 12 additions & 0 deletions dotweb.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ func New() *DotWeb {

//init logger
logger.InitLog()

logDotLogo()

logger.Logger().Debug("Dotweb Start New AppServer", LogTarget_HttpServer)
return app
}

Expand Down Expand Up @@ -454,3 +458,11 @@ func showQuery(ctx Context) error {
}
return nil
}

func logDotLogo() {
logger.Logger().DebugRaw(` ____ __ __`, LogTarget_HttpServer)
logger.Logger().DebugRaw(` / __ \ ____ / /_ _ __ ___ / /_`, LogTarget_HttpServer)
logger.Logger().DebugRaw(` / / / / / __ \ / __/| | /| / / / _ \ / __ \`, LogTarget_HttpServer)
logger.Logger().DebugRaw(` / /_/ / / /_/ // /_ | |/ |/ / / __/ / /_/ /`, LogTarget_HttpServer)
logger.Logger().DebugRaw(`/_____/ \____/ \__/ |__/|__/ \___/ /_.___/`, LogTarget_HttpServer)
}
2 changes: 1 addition & 1 deletion example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func main() {
app.SetEnabledLog(true)

//开启development模式
app.SetProductionMode()
app.SetDevelopmentMode()

//设置gzip开关
//app.HttpServer.SetEnabledGzip(true)
Expand Down
1 change: 1 addition & 0 deletions logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type AppLog interface {
SetEnabledConsole(enabled bool)
SetEnabledLog(enabledLog bool)
Debug(log string, logTarget string)
DebugRaw(log string, logTarget string)
Info(log string, logTarget string)
Warn(log string, logTarget string)
Error(log string, logTarget string)
Expand Down
17 changes: 15 additions & 2 deletions logger/xlog.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type chanLog struct {
Content string
LogTarget string
LogLevel string
isRaw bool
logCtx *logContext
}

Expand All @@ -34,14 +35,18 @@ func NewXLog() *xLog {
const (
defaultDateFormatForFileName = "2006_01_02"
defaultDateLayout = "2006-01-02"
defaultFullTimeLayout = "2006-01-02 15:04:05.999999"
defaultFullTimeLayout = "2006-01-02 15:04:05.9999"
defaultTimeLayout = "2006-01-02 15:04:05"
)

func (l *xLog) Debug(log string, logTarget string) {
l.Log(log, logTarget, LogLevel_Debug)
}

func (l *xLog) DebugRaw(log string, logTarget string) {
l.log(log, logTarget, LogLevel_Debug, true)
}

func (l *xLog) Info(log string, logTarget string) {
l.Log(log, logTarget, LogLevel_Info)
}
Expand All @@ -55,6 +60,10 @@ func (l *xLog) Error(log string, logTarget string) {
}

func (l *xLog) Log(log string, logTarget string, logLevel string) {
l.log(log, logTarget, logLevel, false)
}

func (l *xLog) log(log string, logTarget string, logLevel string, isRaw bool) {
if l.enabledLog {
skip := 3
logCtx, err := callerInfo(skip)
Expand All @@ -66,6 +75,7 @@ func (l *xLog) Log(log string, logTarget string, logLevel string) {
LogTarget: logTarget + "_" + logLevel,
Content: log,
LogLevel: logLevel,
isRaw: isRaw,
logCtx: logCtx,
}
l.logChan_Custom <- chanLog
Expand Down Expand Up @@ -106,7 +116,10 @@ func (l *xLog) writeLog(chanLog chanLog, level string) {
filePath = filePath + "_" + time.Now().Format(defaultDateFormatForFileName) + ".log"
break
}
log := fmt.Sprintf(fmt.Sprintf("[%s] %s [%s:%v] %s", chanLog.LogLevel, time.Now().Format(defaultFullTimeLayout), chanLog.logCtx.fileName, chanLog.logCtx.line, chanLog.Content))
log := chanLog.Content
if !chanLog.isRaw {
log = fmt.Sprintf(fmt.Sprintf("[%s] %s [%s:%v] %s", chanLog.LogLevel, time.Now().Format(defaultFullTimeLayout), chanLog.logCtx.fileName, chanLog.logCtx.line, chanLog.Content))
}
if l.enabledConsole {
fmt.Println(log)
}
Expand Down
5 changes: 5 additions & 0 deletions version.MD
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
## dotweb版本记录:

#### Version 1.2.1
* 启动日志增加dotweb ASCII art logo
* 调整默认日志的时间毫秒段为4位
* 2017-10-05 22:00

#### Version 1.2
* 国庆特别版 - 2017年的国庆,恰逢中秋双节,祝愿国家繁荣昌盛,祝愿代码艺术家们双节快乐!
* 主要新增HttpModule模块、新增ServerConfig:EnabledIgnoreFavicon、完善HttpContext、完善debug日志输出
Expand Down

0 comments on commit 7b03d7b

Please sign in to comment.