refactor logger #2

Merged
trle5 merged 27 commits from log into alpha 2025-07-04 01:26:44 +08:00
Owner

major changes:

use github.com/rs/zerolog as logger

misc

  • add Makefile build script for add build info into program
  • some plugin feature and changes
  • create log template and mult error package
  • separated functions into different packages
  • sub-handlers all need return a error
  • plugin need register initializer, initializers will run after bot initialized
  • signal channle is move into signals.go
  • small fix for utils.AnyContains, it needs to be split into different types
  • utils.PanicCatcher also use zerolog and with stack trace
  • utils package add some Get...Dict for zerolog

database

  • fix get chat info error when have more than one available database
  • add SaveDatabase and ReadDatabase func
  • add RecordData to count usage in single func
  • fix yaml database file protection logic

main

  • add log file writer
  • read config from yaml config file, .env file and environment
### major changes: use `github.com/rs/zerolog` as logger ### misc - add Makefile build script for add build info into program - some plugin feature and changes - create `log template` and `mult error` package - separated functions into different packages - sub-handlers all need return a error - plugin need register initializer, initializers will run after bot initialized - signal channle is move into `signals.go` - small fix for `utils.AnyContains`, it needs to be split into different types - `utils.PanicCatcher` also use `zerolog` and with stack trace - `utils` package add some `Get...Dict` for `zerolog` ### database - fix get chat info error when have more than one available database - add `SaveDatabase` and `ReadDatabase` func - add `RecordData` to count usage in single func - fix yaml database file protection logic ### main - add log file writer - read config from yaml config file, `.env` file and environment
trle5 added 5 commits 2025-06-07 21:53:30 +08:00
add `SaveDatabase` and `ReadDatabase` database operate function
import `github.com/rs/zerolog` use as logger
move most config into yaml config file
use `filepath.Join()` to combine file path
separate some function from `utils`
move signal channel to `signals` package
make exit code in `SignalsHandler()`
change debug script output directory to `${workspaceFolder}/__debug_bin`
fix some redis error
database SaveDatabase and ReadDatabase  can be nil
add a `IsFromBusinessBot` flag to `message_attribute` package
add `GetUserOrSenderChatDict()` func in some case to replace `GetUserDict()` func
trle5 changed title from refactor logger to WIP: refactor logger 2025-06-07 22:19:52 +08:00
trle5 added 1 commit 2025-06-08 03:21:45 +08:00
make error log use `Failed to` first
add full log to `plugin_sticker`
trle5 added 1 commit 2025-06-08 03:41:07 +08:00
trle5 added 1 commit 2025-06-08 21:06:59 +08:00
format redis database logs
only need single redis database
trle5 added 1 commit 2025-06-10 00:25:38 +08:00
add convert webm to gif use external ffmpeg
use `update_utils.GetUpdateType()` get update type then run handlers
remove `IsDebugMode` flag
trle5 added 1 commit 2025-06-11 01:58:24 +08:00
trle5 added 1 commit 2025-06-14 08:14:50 +08:00
use mult writer and filter to save different level log to log file
add makefile to build and inject version info
use `github.com/pkg/errors` and zerolog to print stack and save it
trle5 added 1 commit 2025-06-15 01:00:13 +08:00
update some log's level
show error when build without info
add commit tag to panic catcher
trle5 added 1 commit 2025-06-20 23:50:52 +08:00
trle5 added 1 commit 2025-06-23 09:24:35 +08:00
add log file level
adjust logger create and set level
use logger.Fatal() replace os.Exit(1)
trle5 added 1 commit 2025-06-24 04:17:41 +08:00
use path to run ffmpeg
auto convent webm to gif if have ffmpeg path
fix callback query just return
trle5 added 1 commit 2025-06-24 04:24:56 +08:00
trle5 added 1 commit 2025-06-24 04:50:02 +08:00
trle5 added 1 commit 2025-06-24 05:53:10 +08:00
trle5 added 2 commits 2025-06-25 07:20:27 +08:00
change /version command
not need delete /version message
allow select chat after add keyword
some user interface change
add send document template
trle5 added 1 commit 2025-06-26 03:24:38 +08:00
handlers.go:
    fix wrong var
utils/yaml/yaml.go
    remove fmt package
plugins/teamspeak:
    allow check online client failed 5 times before reinit
all and other:
    use err template
    plugin use yaml.Load() and yaml.Save() manage databases
    use mult error to recored all error
trle5 added 1 commit 2025-06-27 04:44:39 +08:00
show message delete notice on test mode (whatever delete or not)
add some icon in main menu
display 3 message type button in one line
trle5 added 1 commit 2025-06-27 05:07:07 +08:00
trle5 added 1 commit 2025-06-28 15:13:08 +08:00
trle5 added 1 commit 2025-06-28 16:09:50 +08:00
trle5 added 1 commit 2025-06-30 21:54:41 +08:00
show photo file id when get photo message
trle5 added 1 commit 2025-07-04 00:55:18 +08:00
plugin_sticker:
    add sticker collect to channel feature
    allow detected `addsticker` link and show download sticker set button
database:
    remove `IsInitialized` and `InitializedErr` in `DatabaseBackend` struct
    add `context.Context` params in `DatabaseBackend.Initializer`
yaml_db:
    using `yaml.LoadYAML()` and `yaml.SaveYAML()` to save database file
    using `zerolog` logger replace `log`
    fix database file protection logic
    remove `addToYamlDB()` func
    update `Database.UpdateTimestamp` when change some flag
handlers:
    fix `CustomSymbolCommand` trigger: use `strings.HasPrefix()` to replace `utils.CommandMaybeWithSuffixUsername()`, custom symbol command will not include robot username suffix
consts:
    rename `YAMLDataBasePath` to `YAMLDataBaseDir`
mess:
    remove `PrintLogAndSave()` func
trle5 changed title from WIP: refactor logger to refactor logger 2025-07-04 00:56:24 +08:00
trle5 merged commit c21de3fcb1 into alpha 2025-07-04 01:26:44 +08:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: trle5/trbot#2