pingcap / log

Apache License 2.0
17 stars 28 forks source link

panic on unknown log format #15

Closed dveeden closed 2 years ago

dveeden commented 3 years ago
  1. What did you do?

Use --log-format=xml.

  1. What did you expect to see?

Either an XML formatted log or an error saying only text and json are supported

  1. What did you see instead?
[dvaneeden@dve-carbon test_db]$ tiup br backup full -s local:///tmp/tidb_backup_003 --log-format=xml
Starting component `br`: /home/dvaneeden/.tiup/components/br/v5.0.1/br backup full -s local:///tmp/tidb_backup_003 --log-format=xml
Detail BR log in /tmp/br.log.2021-05-04T16.48.04+0200 
panic: unsupport log format: xml

goroutine 1 [running]:
github.com/pingcap/log.NewTextEncoder(0xc0008383c0, 0xc0008441e0, 0x4)
    github.com/pingcap/log@v0.0.0-20201112100606-8f1e84a3abc8/zap_text_encoder.go:168 +0x3fb
github.com/pingcap/log.newZapTextEncoder(...)
    github.com/pingcap/log@v0.0.0-20201112100606-8f1e84a3abc8/config.go:78
github.com/pingcap/log.InitLoggerWithWriteSyncer(0xc0008383c0, 0x3a4b860, 0xc00084e0b0, 0x0, 0x0, 0x0, 0xc0006bba30, 0x1, 0x1, 0x37)
    github.com/pingcap/log@v0.0.0-20201112100606-8f1e84a3abc8/log.go:63 +0xc0
github.com/pingcap/log.InitLogger(0xc0008383c0, 0x0, 0x0, 0x0, 0x1, 0xc0007b3380, 0x37, 0x0)
    github.com/pingcap/log@v0.0.0-20201112100606-8f1e84a3abc8/log.go:53 +0xa7
main.Init.func1()
    github.com/pingcap/br@/cmd/br/cmd.go:115 +0x260
sync.(*Once).doSlow(0x57d9a78, 0xc0006bbb80)
    sync/once.go:66 +0xe3
sync.(*Once).Do(...)
    sync/once.go:57
main.Init(0xc000840dc0, 0x0, 0x0)
    github.com/pingcap/br@/cmd/br/cmd.go:89 +0xbc
main.NewBackupCommand.func1(0xc000840dc0, 0xc00084a2d0, 0x0, 0x3, 0x0, 0x0)
    github.com/pingcap/br@/cmd/br/backup.go:74 +0x2f
github.com/spf13/cobra.(*Command).execute(0xc000840dc0, 0xc0000f2150, 0x3, 0x3, 0xc000840dc0, 0xc0000f2150)
    github.com/spf13/cobra@v1.0.0/command.go:821 +0x56b
github.com/spf13/cobra.(*Command).ExecuteC(0xc000205340, 0xc0006bbe38, 0x3, 0x3)
    github.com/spf13/cobra@v1.0.0/command.go:950 +0x349
github.com/spf13/cobra.(*Command).Execute(...)
    github.com/spf13/cobra@v1.0.0/command.go:887
main.main()
    github.com/pingcap/br@/cmd/br/main.go:56 +0x35c
Error: run `/home/dvaneeden/.tiup/components/br/v5.0.1/br` (wd:/home/dvaneeden/.tiup/data/SWSD09N) failed: exit status 2
  1. What version of BR and TiDB/TiKV/PD are you using?
    [dvaneeden@dve-carbon test_db]$ tiup br --version
    Starting component `br`: /home/dvaneeden/.tiup/components/br/v5.0.1/br --version
    Release Version: v5.0.1
    Git Commit Hash: b3bd5495369244cfb1d3f2c49763a7fdb55d4ecd
    Git Branch: heads/refs/tags/v5.0.1
    Go Version: go1.13
    UTC Build Time: 2021-04-23 06:02:57
    Race Enabled: false

Improvements:

kennytm commented 3 years ago

The panic comes from pingcap/log. This function involved in this line:

https://github.com/pingcap/log/blob/96f4fcab92a42ef1c7fa4927a22df4747693bee2/log.go#L66

should be allowed to return an error instead of panicking in this line:

https://github.com/pingcap/log/blob/96f4fcab92a42ef1c7fa4927a22df4747693bee2/zap_text_encoder.go#L168

I'm going to transfer this to the pingcap/log repository.