diff --git a/README.md b/README.md index 6033d53..2efaaaf 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,7 @@ logger.Alert("msg", "key", "value") Additionally, there are options to choose the API style of the arguments (`...any` or `...slog.Attr`) and to add/remove `context.Context` as the first parameter. This allows you to adjust the logging API to your own code style without sacrificing convenience. -> [!TIP] +> [!tip] > Various API rules for `log/slog` can be enforced by the [`sloglint`][1] linter. Give it a try too! ## 🚀 Features @@ -166,17 +166,17 @@ slog.New(logger.Handler()) Usage: sloggen [flags] Flags: - -config read config from the file instead of flags - -dir change the working directory before generating files - -pkg the name for the generated package (default: slogx) - -i add import - -l add level - -c add constant - -a add attribute - -logger generate a custom Logger type - -api the API style for the Logger's methods (default: any) - -ctx add context.Context to the Logger's methods - -h, -help print this message and quit + -config read config from the file instead of flags + -dir change the working directory before generating files + -pkg the name for the generated package (default: slogx) + -i add import + -l add level + -c add constant + -a add attribute + -logger generate a custom Logger type + -api the API style for the Logger's methods (default: any) + -ctx add context.Context to the Logger's methods + -h, -help print this message and quit ``` For the description of the config file fields, see [`.slog.example.yml`](.slog.example.yml). diff --git a/sloggen.go b/sloggen.go index 102b107..5c92bf7 100644 --- a/sloggen.go +++ b/sloggen.go @@ -62,6 +62,9 @@ type ( ) func (c *config) prepare() { + if c.Pkg == "" { + c.Pkg = "slogx" + } if len(c.Levels) > 0 { c.Imports = append(c.Imports, "log/slog", "fmt", "strings") } @@ -97,22 +100,22 @@ func readFlags(args []string) (*config, error) { fmt.Println(`Usage: sloggen [flags] Flags: - -config read config from the file instead of flags - -dir change the working directory before generating files - -pkg the name for the generated package (default: slogx) - -i add import - -l add level - -c add constant - -a add attribute - -logger generate a custom Logger type - -api the API style for the Logger's methods (default: any) - -ctx add context.Context to the Logger's methods - -h, -help print this message and quit`) + -config read config from the file instead of flags + -dir change the working directory before generating files + -pkg the name for the generated package (default: slogx) + -i add import + -l add level + -c add constant + -a add attribute + -logger generate a custom Logger type + -api the API style for the Logger's methods (default: any) + -ctx add context.Context to the Logger's methods + -h, -help print this message and quit`) } fs.StringVar(&cfg.path, "config", "", "") fs.StringVar(&cfg.dir, "dir", "", "") - fs.StringVar(&cfg.Pkg, "pkg", "slogx", "") + fs.StringVar(&cfg.Pkg, "pkg", "", "") fs.Func("i", "", func(s string) error { cfg.Imports = append(cfg.Imports, s)