Skip to content

gw/config: Provide option to enable logger sampling #1179

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ This document outlines major changes between releases.
## [Unreleased]

### Added
- `logger.sampling.enabled` config option (#1179)

### Changed

Expand Down
11 changes: 7 additions & 4 deletions cmd/s3-gw/app_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ const (

const ( // Settings.
// Logger.
cfgLoggerLevel = "logger.level"
cfgLoggerEncoding = "logger.encoding"
cfgLoggerTimestamp = "logger.timestamp"
cfgLoggerLevel = "logger.level"
cfgLoggerEncoding = "logger.encoding"
cfgLoggerTimestamp = "logger.timestamp"
cfgLoggerSamplingOn = "logger.sampling.enabled"

// Wallet.
cfgWalletPath = "wallet.path"
Expand Down Expand Up @@ -413,7 +414,9 @@ func newLogger(v *viper.Viper) *Logger {
c := zap.NewProductionConfig()
c.Level = zap.NewAtomicLevelAt(lvl)
c.Encoding = encoding
c.Sampling = nil
if !v.GetBool(cfgLoggerSamplingOn) {
c.Sampling = nil
}
if (term.IsTerminal(int(os.Stdout.Fd())) && !v.GetBool(cfgLoggerTimestamp)) || v.GetBool(cfgLoggerTimestamp) {
c.EncoderConfig.EncodeTime = zapcore.ISO8601TimeEncoder
} else {
Expand Down
1 change: 1 addition & 0 deletions config/config.env
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ S3_GW_CONFIG=/path/to/config/yaml
S3_GW_LOGGER_LEVEL=debug
S3_GW_LOGGER_ENCODING=console
S3_GW_LOGGER_TIMESTAMP=false
S3_GW_LOGGER_SAMPLING_ENABLED=true

# RPC endpoint and order of resolving of bucket names
S3_GW_RPC_ENDPOINT=http://morph-chain.neofs.devenv:30333/
Expand Down
2 changes: 2 additions & 0 deletions config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ logger:
level: debug
encoding: console
timestamp: false
sampling:
enabled: true

# RPC endpoint and order of resolving of bucket names
fschain:
Expand Down
3 changes: 3 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -315,13 +315,16 @@ logger:
level: debug
encoding: console
timestamp: true
sampling:
enabled: true
```

| Parameter | Type | SIGHUP reload | Default value | Description |
|-------------|----------|---------------|---------------|-----------------------------------------------------------------------------------------------------|
| `level` | `string` | yes | `debug` | Logging level.<br/>Possible values: `debug`, `info`, `warn`, `error`, `dpanic`, `panic`, `fatal`. |
| `encoding` | `string` | | `console` | Encoding type.<br/>Possible values: `console`, `json`. |
| `timestamp` | `bool` | | `false` | Flag to enable timestamps. If the parameter is not set, they will be enabled when you run with tty. |
| `sampling.enabled` | `bool` | | `false` | Flag to enable log sampling. |

### `cache` section

Expand Down
Loading