Skip to content

Commit

Permalink
feat(config): Add none log level
Browse files Browse the repository at this point in the history
Ref #119
  • Loading branch information
gabe565 committed Dec 15, 2024
1 parent e227216 commit 01e745b
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion docs/castsponsorskip.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ castsponsorskip [flags]
-h, --help help for castsponsorskip
--ignore-segment-duration duration Ignores the previous sponsored segment for a set amount of time. Useful if you want to to go back and watch a segment. (default 1m0s)
--log-format string Log format (one of: auto, color, plain, json) (default "auto")
--log-level string Log level (one of: debug, info, warn, error) (default "info")
--log-level string Log level (one of: debug, info, warn, error, none) (default "info")
--mute-ads Mutes the device while an ad is playing (default true)
-i, --network-interface string Network interface to use for multicast dns discovery. (default all interfaces)
--paused-interval duration Interval to scan paused devices (default 1m0s)
Expand Down
2 changes: 1 addition & 1 deletion docs/envs.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
| `CSS_DISCOVER_INTERVAL` | Interval to restart the DNS discovery client | `5m0s` |
| `CSS_IGNORE_SEGMENT_DURATION` | Ignores the previous sponsored segment for a set amount of time. Useful if you want to to go back and watch a segment. | `1m0s` |
| `CSS_LOG_FORMAT` | Log format (one of: auto, color, plain, json) | `auto` |
| `CSS_LOG_LEVEL` | Log level (one of: debug, info, warn, error) | `info` |
| `CSS_LOG_LEVEL` | Log level (one of: debug, info, warn, error, none) | `info` |
| `CSS_MUTE_ADS` | Mutes the device while an ad is playing | `true` |
| `CSS_NETWORK_INTERFACE` | Network interface to use for multicast dns discovery. (default all interfaces) | ` ` |
| `CSS_PAUSED_INTERVAL` | Interval to scan paused devices | `1m0s` |
Expand Down
2 changes: 1 addition & 1 deletion internal/config/completions.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
func RegisterCompletions(cmd *cobra.Command) {
if err := errors.Join(
cmd.RegisterFlagCompletionFunc(names.FlagLogLevel, func(_ *cobra.Command, _ []string, _ string) ([]string, cobra.ShellCompDirective) {
return []string{"debug", "info", "warn", "error"}, cobra.ShellCompDirectiveNoFileComp | cobra.ShellCompDirectiveKeepOrder
return []string{"debug", "info", "warn", "error", "none"}, cobra.ShellCompDirectiveNoFileComp | cobra.ShellCompDirectiveKeepOrder
}),
cmd.RegisterFlagCompletionFunc(names.FlagNetworkInterface, completeNetworkInterface),
cmd.RegisterFlagCompletionFunc(names.FlagDiscoverInterval, func(_ *cobra.Command, _ []string, _ string) ([]string, cobra.ShellCompDirective) {
Expand Down
2 changes: 1 addition & 1 deletion internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func RegisterFlags(cmd *cobra.Command) {
c := New()

fs.String(names.FlagConfig, "", "Config file path")
fs.String(names.FlagLogLevel, c.LogLevel, "Log level (one of: debug, info, warn, error)")
fs.String(names.FlagLogLevel, c.LogLevel, "Log level (one of: debug, info, warn, error, none)")
fs.String(names.FlagLogFormat, c.LogFormat, "Log format (one of: "+strings.Join(LogFormatStrings(), ", ")+")")

fs.StringSlice(names.FlagDevices, c.DeviceAddrStrs, "Comma-separated list of device addresses. This will disable discovery and is not recommended unless discovery fails")
Expand Down
4 changes: 3 additions & 1 deletion internal/config/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ const (

func (c *Config) InitLog(w io.Writer) {
var level slog.Level
if err := level.UnmarshalText([]byte(c.LogLevel)); err != nil {
if c.LogLevel == "none" {
level = slog.LevelError + 1
} else if err := level.UnmarshalText([]byte(c.LogLevel)); err != nil {
slog.Warn("Invalid log level. Defaulting to info.", "value", c.LogLevel)
level = slog.LevelInfo
c.LogLevel = level.String()
Expand Down

0 comments on commit 01e745b

Please sign in to comment.