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

初始化日志模块时应先重置beego默认的logger #823

Merged
merged 1 commit into from
Aug 23, 2023
Merged

初始化日志模块时应先重置beego默认的logger #823

merged 1 commit into from
Aug 23, 2023

Conversation

leilei3167
Copy link
Contributor

在引入beego时,框架已经预先创建了一个默认配置的logger:

func assignConfig(ac config.Configer) error {
	parseConfigForV1(ac)

	err := ac.Unmarshaler("", BConfig)
	if err != nil {
		_, _ = fmt.Fprintln(os.Stderr, fmt.Sprintf("Unmarshaler config file to BConfig failed. "+
			"And if you are working on v1.x config file, please ignore this, err: %s", err))
		return err
	}

	// init log
	logs.Reset()
	for adaptor, cfg := range BConfig.Log.Outputs {
		err := logs.SetLogger(adaptor, cfg)
		if err != nil {
			fmt.Fprintln(os.Stderr, fmt.Sprintf("%s with the config %q got err:%s", adaptor, cfg, err.Error()))
			return err
		}
	}
	logs.SetLogFuncCall(BConfig.Log.FileLineNum)
	return nil
}

该默认配置的logger为Debug级别,可能会输出较多冗余信息,并且目前的console初始化实际上于默认的console的日志输出是冲突的,此处应该返回的错误由于被忽略用户无法感知:_ = logs.SetLogger("console")

如果要在此显式的设置console的日志打印的话,应该先将默认的logger配置清除

@gsw945 gsw945 merged commit 18b6ead into mindoc-org:master Aug 23, 2023
pugwoo added a commit to pugwoo/mindoc that referenced this pull request Oct 31, 2023
初始化日志模块时应先重置beego默认的logger (mindoc-org#823)
pugwoo added a commit to pugwoo/mindoc that referenced this pull request Oct 31, 2023
初始化日志模块时应先重置beego默认的logger (mindoc-org#823)
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

Successfully merging this pull request may close these issues.

3 participants