Skip to content

Commit

Permalink
- added --log-level=NOLOG option to supress all logging.
Browse files Browse the repository at this point in the history
  • Loading branch information
MatrixCrawler committed Jun 4, 2024
1 parent d59ef38 commit 4e50312
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions lib/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ var (
loggingTemplateDebug = "{{datetime}} {{level}} [{{caller}}] {{message}} {{data}} {{extra}}\n"
loggingTemplate = "{{datetime}} {{level}} {{message}} {{data}} {{extra}}\n"
logger *slog.Logger
ErrorLogging = slog.Levels{slog.PanicLevel, slog.FatalLevel, slog.ErrorLevel}
NormalLogging = slog.Levels{slog.PanicLevel, slog.FatalLevel, slog.ErrorLevel, slog.WarnLevel, slog.InfoLevel}
NoticeLogging = slog.Levels{slog.PanicLevel, slog.FatalLevel, slog.ErrorLevel, slog.WarnLevel, slog.InfoLevel, slog.NoticeLevel}
DebugLogging = slog.Levels{slog.PanicLevel, slog.FatalLevel, slog.ErrorLevel, slog.WarnLevel, slog.InfoLevel, slog.NoticeLevel, slog.DebugLevel}
Expand All @@ -24,6 +25,10 @@ func InitLogger(logLevel string) *slog.Logger {

var h *handler.ConsoleHandler
switch logLevel {
case "ERROR":
h = handler.NewConsoleHandler(ErrorLogging)
formatter.SetTemplate(loggingTemplateDebug)
break
case "TRACE":
h = handler.NewConsoleHandler(TraceLogging)
formatter.SetTemplate(loggingTemplateDebug)
Expand Down
2 changes: 1 addition & 1 deletion lib/param_parsing/parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func GetParameters() Params {
getopt.StringVarLong(&params.LatestPre, "latest-pre", 'p', "Latest pre-release implicit version. Ex: tfswitch --latest-pre 0.13 downloads 0.13.0-rc1 (latest)")
getopt.StringVarLong(&params.LatestStable, "latest-stable", 's', "Latest implicit version based on a constraint. Ex: tfswitch --latest-stable 0.13.0 downloads 0.13.7 and 0.13 downloads 0.15.5 (latest)")
getopt.BoolVarLong(&params.ListAllFlag, "list-all", 'l', "List all versions of terraform - including beta and rc")
getopt.StringVarLong(&params.LogLevel, "log-level", 'g', "Set loglevel for tfswitch. One of (INFO, NOTICE, DEBUG, TRACE)")
getopt.StringVarLong(&params.LogLevel, "log-level", 'g', "Set loglevel for tfswitch. One of (ERROR, INFO, NOTICE, DEBUG, TRACE)")
getopt.StringVarLong(&params.MirrorURL, "mirror", 'm', "install from a remote API other than the default. Default: "+lib.DefaultMirror)
getopt.BoolVarLong(&params.ShowLatestFlag, "show-latest", 'U', "Show latest stable version")
getopt.StringVarLong(&params.ShowLatestPre, "show-latest-pre", 'P', "Show latest pre-release implicit version. Ex: tfswitch --show-latest-pre 0.13 prints 0.13.0-rc1 (latest)")
Expand Down

0 comments on commit 4e50312

Please sign in to comment.