forked from jriou/coller
feat: Add JSON logging format
Fixes #40. Signed-off-by: Julien Riou <julien@riou.xyz>
This commit is contained in:
parent
acfad88cb8
commit
2d8d7efbcb
3 changed files with 24 additions and 3 deletions
|
@ -61,6 +61,7 @@ func handleMain() int {
|
|||
quiet := flag.Bool("quiet", false, "Log errors only")
|
||||
verbose := flag.Bool("verbose", false, "Print more logs")
|
||||
debug := flag.Bool("debug", false, "Print even more logs")
|
||||
jsonFormat := flag.Bool("json", false, "Print logs in JSON format")
|
||||
configFile := flag.String("config", filepath.Join(homeDir, ".config", AppName+".json"), "Configuration file")
|
||||
reconfigure := flag.Bool("reconfigure", false, "Re-create configuration file")
|
||||
url := flag.String("url", "", "URL of the coller API")
|
||||
|
@ -102,7 +103,13 @@ func handleMain() int {
|
|||
if *quiet {
|
||||
level = slog.LevelError
|
||||
}
|
||||
logger := slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{Level: level}))
|
||||
|
||||
var logger *slog.Logger
|
||||
if *jsonFormat {
|
||||
logger = slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{Level: level}))
|
||||
} else {
|
||||
logger = slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{Level: level}))
|
||||
}
|
||||
|
||||
if *url == "" {
|
||||
if _, err = os.Stat(*configFile); errors.Is(err, os.ErrNotExist) || *reconfigure {
|
||||
|
|
|
@ -27,6 +27,7 @@ func handleMain() int {
|
|||
quiet := flag.Bool("quiet", false, "Log errors only")
|
||||
verbose := flag.Bool("verbose", false, "Print more logs")
|
||||
debug := flag.Bool("debug", false, "Print even more logs")
|
||||
jsonFormat := flag.Bool("json", false, "Print logs in JSON format")
|
||||
configFileName := flag.String("config", "", "Configuration file name")
|
||||
|
||||
flag.Parse()
|
||||
|
@ -46,7 +47,13 @@ func handleMain() int {
|
|||
if *quiet {
|
||||
level = slog.LevelError
|
||||
}
|
||||
logger := slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{Level: level}))
|
||||
|
||||
var logger *slog.Logger
|
||||
if *jsonFormat {
|
||||
logger = slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{Level: level}))
|
||||
} else {
|
||||
logger = slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{Level: level}))
|
||||
}
|
||||
|
||||
if *configFileName != "" {
|
||||
err = internal.ReadConfig(*configFileName, config)
|
||||
|
|
|
@ -41,6 +41,7 @@ func handleMain() int {
|
|||
quiet := flag.Bool("quiet", false, "Log errors only")
|
||||
verbose := flag.Bool("verbose", false, "Print more logs")
|
||||
debug := flag.Bool("debug", false, "Print even more logs")
|
||||
jsonFormat := flag.Bool("json", false, "Print logs in JSON format")
|
||||
encryptionKey := flag.String("encryption-key", os.Getenv("COLLER_ENCRYPTION_KEY"), "Key to decrypt the note")
|
||||
askEncryptionKey := flag.Bool("ask-encryption-key", false, "Read encryption key from input")
|
||||
fileName := flag.String("file", "", "Write content of the note to a file")
|
||||
|
@ -72,7 +73,13 @@ func handleMain() int {
|
|||
if *quiet {
|
||||
level = slog.LevelError
|
||||
}
|
||||
logger := slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{Level: level}))
|
||||
|
||||
var logger *slog.Logger
|
||||
if *jsonFormat {
|
||||
logger = slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{Level: level}))
|
||||
} else {
|
||||
logger = slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{Level: level}))
|
||||
}
|
||||
|
||||
if *askEncryptionKey {
|
||||
fmt.Print("Encryption key: ")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue