Skip to content

Commit 2780299

Browse files
authored
fix: default package name (#33)
1 parent 6dd67f4 commit 2780299

File tree

2 files changed

+27
-24
lines changed

2 files changed

+27
-24
lines changed

README.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ logger.Alert("msg", "key", "value")
6060
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.
6161
This allows you to adjust the logging API to your own code style without sacrificing convenience.
6262

63-
> [!TIP]
63+
> [!tip]
6464
> Various API rules for `log/slog` can be enforced by the [`sloglint`][1] linter. Give it a try too!
6565
6666
## 🚀 Features
@@ -166,17 +166,17 @@ slog.New(logger.Handler())
166166
Usage: sloggen [flags]
167167

168168
Flags:
169-
-config <path> read config from the file instead of flags
170-
-dir <path> change the working directory before generating files
171-
-pkg <name> the name for the generated package (default: slogx)
172-
-i <import> add import
173-
-l <name:severity> add level
174-
-c <key> add constant
175-
-a <key:type> add attribute
176-
-logger generate a custom Logger type
177-
-api <any|attr> the API style for the Logger's methods (default: any)
178-
-ctx add context.Context to the Logger's methods
179-
-h, -help print this message and quit
169+
-config <path> read config from the file instead of flags
170+
-dir <path> change the working directory before generating files
171+
-pkg <name> the name for the generated package (default: slogx)
172+
-i <import> add import
173+
-l <name:severity> add level
174+
-c <key> add constant
175+
-a <key:type> add attribute
176+
-logger generate a custom Logger type
177+
-api <any|attr> the API style for the Logger's methods (default: any)
178+
-ctx add context.Context to the Logger's methods
179+
-h, -help print this message and quit
180180
```
181181

182182
For the description of the config file fields, see [`.slog.example.yml`](.slog.example.yml).

sloggen.go

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ type (
6262
)
6363

6464
func (c *config) prepare() {
65+
if c.Pkg == "" {
66+
c.Pkg = "slogx"
67+
}
6568
if len(c.Levels) > 0 {
6669
c.Imports = append(c.Imports, "log/slog", "fmt", "strings")
6770
}
@@ -97,22 +100,22 @@ func readFlags(args []string) (*config, error) {
97100
fmt.Println(`Usage: sloggen [flags]
98101
99102
Flags:
100-
-config <path> read config from the file instead of flags
101-
-dir <path> change the working directory before generating files
102-
-pkg <name> the name for the generated package (default: slogx)
103-
-i <import> add import
104-
-l <name:severity> add level
105-
-c <key> add constant
106-
-a <key:type> add attribute
107-
-logger generate a custom Logger type
108-
-api <any|attr> the API style for the Logger's methods (default: any)
109-
-ctx add context.Context to the Logger's methods
110-
-h, -help print this message and quit`)
103+
-config <path> read config from the file instead of flags
104+
-dir <path> change the working directory before generating files
105+
-pkg <name> the name for the generated package (default: slogx)
106+
-i <import> add import
107+
-l <name:severity> add level
108+
-c <key> add constant
109+
-a <key:type> add attribute
110+
-logger generate a custom Logger type
111+
-api <any|attr> the API style for the Logger's methods (default: any)
112+
-ctx add context.Context to the Logger's methods
113+
-h, -help print this message and quit`)
111114
}
112115

113116
fs.StringVar(&cfg.path, "config", "", "")
114117
fs.StringVar(&cfg.dir, "dir", "", "")
115-
fs.StringVar(&cfg.Pkg, "pkg", "slogx", "")
118+
fs.StringVar(&cfg.Pkg, "pkg", "", "")
116119

117120
fs.Func("i", "", func(s string) error {
118121
cfg.Imports = append(cfg.Imports, s)

0 commit comments

Comments
 (0)