Skip to content

Commit 7b03d7b

Browse files
author
pzrr@qq.com
committed
深夜Art版
#### Version 1.2.1 * 启动日志增加dotweb ASCII art logo * 调整默认日志的时间毫秒段为4位 * 2017-10-05 22:00
1 parent d7de21a commit 7b03d7b

5 files changed

Lines changed: 34 additions & 3 deletions

File tree

‎dotweb.go‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ func New() *DotWeb {
6767

6868
//init logger
6969
logger.InitLog()
70+
71+
logDotLogo()
72+
73+
logger.Logger().Debug("Dotweb Start New AppServer", LogTarget_HttpServer)
7074
return app
7175
}
7276

@@ -454,3 +458,11 @@ func showQuery(ctx Context) error {
454458
}
455459
return nil
456460
}
461+
462+
func logDotLogo() {
463+
logger.Logger().DebugRaw(` ____ __ __`, LogTarget_HttpServer)
464+
logger.Logger().DebugRaw(` / __ \ ____ / /_ _ __ ___ / /_`, LogTarget_HttpServer)
465+
logger.Logger().DebugRaw(` / / / / / __ \ / __/| | /| / / / _ \ / __ \`, LogTarget_HttpServer)
466+
logger.Logger().DebugRaw(` / /_/ / / /_/ // /_ | |/ |/ / / __/ / /_/ /`, LogTarget_HttpServer)
467+
logger.Logger().DebugRaw(`/_____/ \____/ \__/ |__/|__/ \___/ /_.___/`, LogTarget_HttpServer)
468+
}

‎example/main.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func main() {
2929
app.SetEnabledLog(true)
3030

3131
//开启development模式
32-
app.SetProductionMode()
32+
app.SetDevelopmentMode()
3333

3434
//设置gzip开关
3535
//app.HttpServer.SetEnabledGzip(true)

‎logger/logger.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ type AppLog interface {
2020
SetEnabledConsole(enabled bool)
2121
SetEnabledLog(enabledLog bool)
2222
Debug(log string, logTarget string)
23+
DebugRaw(log string, logTarget string)
2324
Info(log string, logTarget string)
2425
Warn(log string, logTarget string)
2526
Error(log string, logTarget string)

‎logger/xlog.go‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ type chanLog struct {
1414
Content string
1515
LogTarget string
1616
LogLevel string
17+
isRaw bool
1718
logCtx *logContext
1819
}
1920

@@ -34,14 +35,18 @@ func NewXLog() *xLog {
3435
const (
3536
defaultDateFormatForFileName = "2006_01_02"
3637
defaultDateLayout = "2006-01-02"
37-
defaultFullTimeLayout = "2006-01-02 15:04:05.999999"
38+
defaultFullTimeLayout = "2006-01-02 15:04:05.9999"
3839
defaultTimeLayout = "2006-01-02 15:04:05"
3940
)
4041

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

46+
func (l *xLog) DebugRaw(log string, logTarget string) {
47+
l.log(log, logTarget, LogLevel_Debug, true)
48+
}
49+
4550
func (l *xLog) Info(log string, logTarget string) {
4651
l.Log(log, logTarget, LogLevel_Info)
4752
}
@@ -55,6 +60,10 @@ func (l *xLog) Error(log string, logTarget string) {
5560
}
5661

5762
func (l *xLog) Log(log string, logTarget string, logLevel string) {
63+
l.log(log, logTarget, logLevel, false)
64+
}
65+
66+
func (l *xLog) log(log string, logTarget string, logLevel string, isRaw bool) {
5867
if l.enabledLog {
5968
skip := 3
6069
logCtx, err := callerInfo(skip)
@@ -66,6 +75,7 @@ func (l *xLog) Log(log string, logTarget string, logLevel string) {
6675
LogTarget: logTarget + "_" + logLevel,
6776
Content: log,
6877
LogLevel: logLevel,
78+
isRaw: isRaw,
6979
logCtx: logCtx,
7080
}
7181
l.logChan_Custom <- chanLog
@@ -106,7 +116,10 @@ func (l *xLog) writeLog(chanLog chanLog, level string) {
106116
filePath = filePath + "_" + time.Now().Format(defaultDateFormatForFileName) + ".log"
107117
break
108118
}
109-
log := fmt.Sprintf(fmt.Sprintf("[%s] %s [%s:%v] %s", chanLog.LogLevel, time.Now().Format(defaultFullTimeLayout), chanLog.logCtx.fileName, chanLog.logCtx.line, chanLog.Content))
119+
log := chanLog.Content
120+
if !chanLog.isRaw {
121+
log = fmt.Sprintf(fmt.Sprintf("[%s] %s [%s:%v] %s", chanLog.LogLevel, time.Now().Format(defaultFullTimeLayout), chanLog.logCtx.fileName, chanLog.logCtx.line, chanLog.Content))
122+
}
110123
if l.enabledConsole {
111124
fmt.Println(log)
112125
}

‎version.MD‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
## dotweb版本记录:
22

3+
#### Version 1.2.1
4+
* 启动日志增加dotweb ASCII art logo
5+
* 调整默认日志的时间毫秒段为4位
6+
* 2017-10-05 22:00
7+
38
#### Version 1.2
49
* 国庆特别版 - 2017年的国庆,恰逢中秋双节,祝愿国家繁荣昌盛,祝愿代码艺术家们双节快乐!
510
* 主要新增HttpModule模块、新增ServerConfig:EnabledIgnoreFavicon、完善HttpContext、完善debug日志输出

0 commit comments

Comments
 (0)