Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于日志的输出信息 #1

Closed
imlonghao opened this issue Apr 19, 2020 · 3 comments
Closed

关于日志的输出信息 #1

imlonghao opened this issue Apr 19, 2020 · 3 comments

Comments

@imlonghao
Copy link

现在的日志输出信息:

[ INFO ] - Date: 2020-22-22 11:22:33.1234 AM - Position: main.go|main.main|22 - Message: custom message

能不能提供一个选项,可以去掉 Date:Position: 以及 Message: 这几个文本,因为很显而易见这栏就是时间,这栏就是代码位置,感觉没有必要,加上也增大了日志每行的长度

最终的效果就是

[ INFO ] - 2020-22-22 11:22:33.1234 AM - main.go|main.main|22 - custom message

另外这个 AM / PM 是否有必要存在呢,既然都已经是 24 小时制了?

@auula
Copy link
Owner

auula commented Apr 19, 2020

ok.看了一下你的问题,时间这个我在写的时候我自己都发现了只是后面赶着写完就push上去了然后也没有看2333,OK至于消息标签我后续可能改成可以自定义配置的。

auula added a commit that referenced this issue Apr 19, 2020
auula added a commit that referenced this issue Apr 19, 2020
auula added a commit that referenced this issue Apr 19, 2020
auula added a commit that referenced this issue Apr 19, 2020
auula added a commit that referenced this issue Apr 19, 2020
auula added a commit that referenced this issue Apr 19, 2020
auula added a commit that referenced this issue Apr 19, 2020
auula added a commit that referenced this issue Apr 19, 2020
auula added a commit that referenced this issue Apr 19, 2020
@auula
Copy link
Owner

auula commented Apr 19, 2020

func main() {
	var log logker.Logger
	format := "{level} - Date: {time}  - 位置{position} - Message: {message}" //This version was modified from v 1.1.0
	log = logker.NewClog(logker.INFO, logker.Shanghai, format)
	log.Info("%v", log)
	log.Warning("%v", logker.Shanghai)
}

自定义格式化formatting : //ormat := "{level} - {time} - {position} - {message}

但是必须是👆的标签名字 {level} {time} {position} {message}是这样的,{}号的!!!程序就会根据你自定义的格式

auula added a commit that referenced this issue Apr 20, 2020
auula added a commit that referenced this issue Apr 20, 2020
auula added a commit that referenced this issue Apr 20, 2020
auula added a commit that referenced this issue Apr 20, 2020
@auula
Copy link
Owner

auula commented Apr 20, 2020

现在的日志输出信息:

[ INFO ] - Date: 2020-22-22 11:22:33.1234 AM - Position: main.go|main.main|22 - Message: custom message

能不能提供一个选项,可以去掉 Date:Position: 以及 Message: 这几个文本,因为很显而易见这栏就是时间,这栏就是代码位置,感觉没有必要,加上也增大了日志每行的长度

最终的效果就是

[ INFO ] - 2020-22-22 11:22:33.1234 AM - main.go|main.main|22 - custom message

另外这个 AM / PM 是否有必要存在呢,既然都已经是 24 小时制了?

现在upgrade到v1.1.5版本即可自定义消息输出格式~
自定义标签名字必须是{level} {time} {position} {message}
自定义标签的位置就是程序运行时输出对应的日志消息的位置!!!!
例如下面我自定义的

package main

import (
	"github.com/higker/logker"
	"strings"
)

//type Formatting string

// logKer library Test
func main() {
	//现在upgrade到v1.1.5版本即可自定义消息输出格式~
	//format := "{level} - {time} - {position} - {message}"
	var log logker.Logger
	format := "{level} - 时间 {time}  - 位置 {position} - 消息 {message}" //This version was modified from v 1.1.5
	log = logker.NewClog(logker.DEBUG, logker.Shanghai, format)
	log.Debug("DEBUG %s","自定义日志消息匹配符测试")
	log.Info("%v", log)
	log.Warning("%v", logker.Shanghai)
	log.Error("ERROR")
}

OutPut

[ DEBUG ] - 时间 2020-04-20 11:57:23.8927  - 位置 main.go|main.main:23 - 消息 DEBUG 自定义日志消息匹配符测试
[  INFO ] - 时间 2020-04-20 11:57:23.8928  - 位置 main.go|main.main:24 - 消息 &{0 Asia/Shanghai 0xc00008e220 {level} - 时间 {t位置 {position} - 消息 {message}}
[WARNING] - 时间 2020-04-20 11:57:23.8928  - 位置 main.go|main.main:25 - 消息 Asia/Shanghai
[ ERROR ] - 时间 2020-04-20 11:57:23.8929  - 位置 main.go|main.main:26 - 消息 ERROR

@auula auula closed this as completed Apr 20, 2020
@auula auula reopened this Apr 20, 2020
@auula auula closed this as completed Apr 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants