Skip to content

Wrong package level logger initialization timing #52883

@lance6716

Description

@lance6716

in #52645 I added a package level logger

litLogger = logutil.BgLogger().With(zap.String(logutil.LogFieldCategory, "ddl-ingest"))

But when the variable is set, logutil.BgLogger() is not initialized yet. It prints to stdout instead

$ k logs tc-tidb-0 | more
start tidb-server ...
/tidb-server --store=tikv --advertise-address=xxx --host=0.0.0.0 --path=tc-pd:2379 --config=/etc/tidb/tidb.toml

[2024/04/25 09:30:59.400 +08:00] [INFO] [env.go:103] ["the ingest sorted directory"] [category=ddl-ingest] ["data path"=/tmp/tidb/tmp_ddl-4000]
[2024/04/25 09:30:59.400 +08:00] [INFO] [env.go:76] ["init global ingest backend environment finished"] [category=ddl-ingest] ["memory limitation"=17179869184] ["disk usage info"="disk usage: 336493137920/467794132992, backend usage: 0"] ["max open file number"=1073741816] ["lightning is initialized"=true]
[2024/04/25 09:31:06.145 +08:00] [INFO] [local.go:682] ["multi ingest support"] [category=ddl-ingest]
[2024/04/25 09:31:06.146 +08:00] [INFO] [local.go:704] ["TiKV server side free space check is enabled, so lightning will turn it off"] [category=ddl-ingest]
[2024/04/25 09:42:06.984 +08:00] [INFO] [local.go:682] ["multi ingest support"] [category=ddl-ingest]

we should set them after

func setupLog() {
cfg := config.GetGlobalConfig()
err := logutil.InitLogger(cfg.Log.ToLogConfig(), keyspace.WrapZapcoreWithKeyspace())
terror.MustNil(err)
// trigger internal http(s) client init.
util.InternalHTTPClient()
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    affects-8.1This bug affects the 8.1.x(LTS) versions.component/ddlThis issue is related to DDL of TiDB.severity/moderatetype/bugThe issue is confirmed as a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions