Skip to content

Commit 22f5fd8

Browse files
committed
fix: Default log level handling
1 parent a98a3b6 commit 22f5fd8

File tree

2 files changed

+4
-11
lines changed

2 files changed

+4
-11
lines changed

assets/pango/client.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ type LoggingInfo struct {
3030
SLogHandler slog.Handler `json:"-"`
3131
LogCategories LogCategory `json:"-"`
3232
LogSymbols []string `json:"log_symbols"`
33-
LogLevel slog.Leveler `json:"log_level"`
33+
LogLevel slog.Level `json:"log_level"`
3434
}
3535

3636
// Client is an XML API client connection. If provides wrapper functions
@@ -46,7 +46,7 @@ type Client struct {
4646
Target string `json:"target"`
4747
ApiKeyInRequest bool `json:"api_key_in_request"`
4848
Headers map[string]string `json:"headers"`
49-
Logging *LoggingInfo `json:"logging"`
49+
Logging LoggingInfo `json:"logging"`
5050

5151
// Set to true if you want to check environment variables
5252
// for auth and connection properties.
@@ -1003,15 +1003,15 @@ func (c *Client) GetTechSupportFile(ctx context.Context) (string, []byte, error)
10031003
// Internal functions.
10041004
//
10051005

1006-
func (c *Client) setupLogging(logging *LoggingInfo) error {
1006+
func (c *Client) setupLogging(logging LoggingInfo) error {
10071007
var logger *slog.Logger
10081008

10091009
if logging.SLogHandler == nil {
10101010
logger = slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{Level: logging.LogLevel}))
10111011
logger.Info("No slog handler provided, creating default os.Stderr handler.", "LogLevel", logging.LogLevel.Level())
10121012
} else {
10131013
logger = slog.New(logging.SLogHandler)
1014-
if logging.LogLevel != nil {
1014+
if logging.LogLevel != 0 {
10151015
logger.Warn("LogLevel is ignored when using custom SLog handler.")
10161016
}
10171017
}

assets/pango/example/main.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ import (
44
"context"
55
"encoding/xml"
66
"fmt"
7-
"io/ioutil"
87
"log"
9-
"log/slog"
108

119
"github.com/PaloAltoNetworks/pango"
1210
"github.com/PaloAltoNetworks/pango/device/services/dns"
@@ -38,11 +36,6 @@ func main() {
3836
CheckEnvironment: true,
3937
SkipVerifyCertificate: true,
4038
ApiKeyInRequest: true,
41-
Logging: &pango.LoggingInfo{
42-
LogCategories: pango.LogCategoryPango,
43-
SLogHandler: slog.NewTextHandler(ioutil.Discard, nil),
44-
LogLevel: slog.LevelDebug,
45-
},
4639
}
4740
if err = c.Setup(); err != nil {
4841
log.Printf("Failed to setup client: %s", err)

0 commit comments

Comments
 (0)