Skip to content

Conversation

@Igor-splunk
Copy link
Collaborator

Description

What does this PR have in it?

Key Changes

Highlight the updates in specific files

Testing and Verification

How did you test these changes? What automated tests are added?

Related Issues

Jira tickets, GitHub issues, Support tickets...

PR Checklist

  • Code changes adhere to the project's coding standards.
  • Relevant unit and integration tests are included.
  • Documentation has been updated accordingly.
  • All tests pass locally.
  • The PR description follows the project's guidelines.

@coveralls
Copy link
Collaborator

coveralls commented Jan 16, 2026

Pull Request Test Coverage Report for Build 21068664710

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 86.371%

Totals Coverage Status
Change from base Build 21029015253: 0.0%
Covered Lines: 10729
Relevant Lines: 12422

💛 - Coveralls

@@ -0,0 +1,947 @@
// Copyright (c) 2018-2022 Splunk Inc. All rights reserved.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2026 instead of 2022?

@Igor-splunk Igor-splunk changed the base branch from develop to feature/slog-as-default-logger January 21, 2026 10:40
Comment on lines +104 to +106
flag.StringVar(&slogLevel, "slog-level", "", "slog log level: debug, info, warn, error (overrides LOG_LEVEL env var)")
flag.StringVar(&slogFormat, "slog-format", "", "slog output format: json, text (overrides LOG_FORMAT env var)")
flag.BoolVar(&slogAddSource, "slog-add-source", false, "add source file:line to slog output (overrides LOG_ADD_SOURCE env var)")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe those flags should be implementation agnostic? So just log-level, log-format and log-add-source


// LoadConfig loads logging configuration from environment variables
// Environment variables take precedence over defaults
func LoadConfig() Config {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we use it outside of logging package? Maybe it shouldn't be exported?

AddSource: false,
}

if level := os.Getenv(EnvLogLevel); level != "" {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[not in this PR] We should have one place where we define configuration. Having those system calls all over codebase is messy.

Comment on lines +136 to +158
// NewProductionHandler creates a handler optimized for production
// JSON format, INFO level, no source location, sensitive data redaction
func NewProductionHandler() slog.Handler {
opts := &slog.HandlerOptions{
Level: slog.LevelInfo,
AddSource: false,
ReplaceAttr: redactSensitiveData,
}

return slog.NewJSONHandler(os.Stdout, opts)
}

// NewDevelopmentHandler creates a handler optimized for development
// Text format, DEBUG level, source location enabled
func NewDevelopmentHandler() slog.Handler {
opts := &slog.HandlerOptions{
Level: slog.LevelDebug,
AddSource: true,
ReplaceAttr: redactSensitiveData,
}

return slog.NewTextHandler(os.Stdout, opts)
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we set up those opts via config? What peace of code is expected to call those functions?

Comment on lines +180 to +188
func SetupLogger(cfg Config) *slog.Logger {
handler := NewHandler(cfg)
logger := slog.New(handler)
slog.SetDefault(logger)
return logger
}

// SetupLoggerWithAttrs initializes the global slog logger with common attributes
func SetupLoggerWithAttrs(cfg Config, component, version, build string) *slog.Logger {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should use such function here:
SetupLogger(cfg Config, attrs ...slog.Attr)

Comment on lines +201 to +203
func LevelFromString(s string) slog.Level {
return parseLevel(s)
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] Maybe we should just use LevelFromString and move parseLevel code here

// See the License for the specific language governing permissions and
// limitations under the License.

package logging
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not black box testing?
Aren't we using build tags?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants