Skip to content

Commit

Permalink
Add SDK logging configuration in the provider
Browse files Browse the repository at this point in the history
  • Loading branch information
kklimonda-cl committed Sep 23, 2024
1 parent 73cfe3f commit ee0bed9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
17 changes: 14 additions & 3 deletions assets/pango/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1006,8 +1006,19 @@ func (c *Client) GetTechSupportFile(ctx context.Context) (string, []byte, error)
func (c *Client) setupLogging(logging LoggingInfo) error {
var logger *slog.Logger

var logLevel slog.Level
var levelStr string
if levelStr = os.Getenv("PANOS_LOG_LEVEL"); c.CheckEnvironment && levelStr != "" {
err := logLevel.UnmarshalText([]byte(levelStr))
if err != nil {
return err
}
} else {
logLevel = slog.LevelInfo
}

if logging.SLogHandler == nil {
logger = slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{Level: logging.LogLevel}))
logger = slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{Level: logLevel}))
logger.Info("No slog handler provided, creating default os.Stderr handler.", "LogLevel", logging.LogLevel.Level())
} else {
logger = slog.New(logging.SLogHandler)
Expand All @@ -1019,7 +1030,7 @@ func (c *Client) setupLogging(logging LoggingInfo) error {
// 1. logging.LogCategories has the highest priority
// 2. If logging.LogCategories is not set, we check logging.LogSymbols
// 3. If logging.LogSymbols is empty and c.CheckEnvironment is true we consult
// PANOS_LOGGING environment variable.
// PANOS_LOG_CATEGORIES environment variable.
// 4. If no logging categories have been selected, default to basic library logging
// (i.e. "pango" category)
logMask := logging.LogCategories
Expand All @@ -1031,7 +1042,7 @@ func (c *Client) setupLogging(logging LoggingInfo) error {
}

if logMask == 0 {
if val := os.Getenv("PANOS_LOGGING"); c.CheckEnvironment && val != "" {
if val := os.Getenv("PANOS_LOG_CATEGORIES"); c.CheckEnvironment && val != "" {
symbols := strings.Split(val, ",")
logMask, err = LogCategoryFromStrings(symbols)
if err != nil {
Expand Down
8 changes: 8 additions & 0 deletions cmd/codegen/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@ terraform_provider_config:
description: "(Local inspection mode) The PAN-OS config file to load read in using `file()`"
optional: true
type: string
sdk_log_level:
description: "Log level configured for the PAN-OS SDK library"
optional: true
type: string
sdk_log_categories:
description: "Log categories to configure for the PAN-OS SDK library"
optional: true
type: string
panos_version:
description: "(Local inspection mode) The version of PAN-OS that exported the config file. This is only used if the root 'config' block does not contain the 'detail-version' attribute. Example: `10.2.3`."
optional: true
Expand Down

0 comments on commit ee0bed9

Please sign in to comment.