From f575e0cb4610660bfa40f97b34726d5e382acec2 Mon Sep 17 00:00:00 2001 From: Adora Laura Kalb Date: Wed, 6 Nov 2024 11:16:12 +0100 Subject: [PATCH] add logging clolr flag and change default values --- CHANGELOG.md | 8 +++++++- cmd/root.go | 10 ++++++---- examples/config.yaml | 24 +++++++++++++++--------- log/logger.go | 10 +++++++--- 4 files changed, 35 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4eb3116..1ec4915 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,9 +9,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Added `list` alias to `queue show` - Added `delete` alias to `queue remove` +- config option to toggle colored output +- Docker build for armv7, arm64 and amd64 ### Changed - Changed table output style +- various default config values (see examples/config.yaml) + +### Fixed +- missing error handling ## [v0.2.1] - 2023-06-11 ### Changed @@ -68,4 +74,4 @@ instead of immediately posting one bundle [v0.2.0]: https://git.lauka.net/lauralani/humble-bot/compare/v0.1.2...v0.2.0 [v0.1.2]: https://git.lauka.net/lauralani/humble-bot/compare/v0.1.1...v0.1.2 [v0.1.1]: https://git.lauka.net/lauralani/humble-bot/compare/v0.1.0...v0.1.1 -[v0.1.0]: https://git.lauka.net/lauralani/humble-bot/releases/tag/v0.1.0 \ No newline at end of file +[v0.1.0]: https://git.lauka.net/lauralani/humble-bot/releases/tag/v0.1.0 diff --git a/cmd/root.go b/cmd/root.go index 48f2318..ed21804 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -7,12 +7,13 @@ package cmd import ( + log2 "log" + "os" + "codeberg.org/lauralani/humble-bot/constants" "codeberg.org/lauralani/humble-bot/db" "codeberg.org/lauralani/humble-bot/log" "codeberg.org/lauralani/humble-bot/misc" - log2 "log" - "os" "github.com/spf13/cobra" "github.com/spf13/viper" @@ -62,9 +63,10 @@ func initConfig() { viper.SetConfigName("config") } - viper.SetDefault("mastodon.postinterval", "5m") - viper.SetDefault("mastodon.visibility", "public") + viper.SetDefault("mastodon.postinterval", "1h") + viper.SetDefault("mastodon.visibility", "private") viper.SetDefault("humblebundle.pollinterval", "30m") + viper.SetDefault("logging.colored_output", false) if err := viper.ReadInConfig(); err == nil { log2.Printf("Starting humble-bot %v with config file: %v\n", constants.AppVersion, viper.ConfigFileUsed()) diff --git a/examples/config.yaml b/examples/config.yaml index d074771..c14c483 100644 --- a/examples/config.yaml +++ b/examples/config.yaml @@ -3,32 +3,38 @@ database: # PostgreSQL Database-URL # Format: postgresql://:@/ # you can add optional postgres parameters after the database part, e.g. ?sslmode=verify-full - url: "postgresql://:@/" + # see https://bun.uptrace.dev/postgres/#pgdriver for more database config options + url: "postgresql://humblebot:humblebot@db/humblebot?sslmode=disable" # Mastodon Instance settings mastodon: # URL of your Mastodon Instance # Format: https://mastodon.social (without trailing slash) - url: "https://" + url: "https:///mastodon.social" # Access token for your mastodon account # see $your_mastodon_url/settings/applications - token: "" + token: "a-secret-token" # Interval in which humble-bot tries to post bundles # format: "20s" or "15m" or "1h" - # default: 5m - postinterval: "5m" + # default: 1h + postinterval: "1h" # Post visibility of the bundles on mastodon # allowed values: ["public", "unlisted", "private"] - # default: public - visibility: "public" + # default: private + visibility: "private" + +# Humble Bot logging settings +logging: + # enable colored logging + # default: false + colored_output: false # Humble Bundle settings humblebundle: - # Interval in which humble-bot tries to query humblebundle.com # format: "20s" or "15m" or "1h" # default: 30m - pollinterval: "30m" \ No newline at end of file + pollinterval: "30m" diff --git a/log/logger.go b/log/logger.go index dcde84d..7618dfa 100644 --- a/log/logger.go +++ b/log/logger.go @@ -7,18 +7,22 @@ package log import ( - "github.com/rs/zerolog" - "github.com/rs/zerolog/log" "os" "time" + + "github.com/rs/zerolog" + "github.com/rs/zerolog/log" + "github.com/spf13/viper" ) var FlagDebug bool func InitializeLogger() { + _noColor := !viper.GetBool("logging.colored_output") + if os.Getenv("INVOCATION_ID") == "" { // detect systemd - log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stdout, TimeFormat: time.RFC3339}) + log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stdout, NoColor: _noColor, TimeFormat: time.RFC3339}) } else { log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stdout, NoColor: true, PartsExclude: []string{"time"}}) }