-
-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
deps!: bump github.com/prometheus/exporter-toolkit from 0.11.0 to 0.1…
…3.0 (#596) * deps: bump github.com/prometheus/exporter-toolkit from 0.11.0 to 0.13.0 Bumps [github.com/prometheus/exporter-toolkit](https://github.com/prometheus/exporter-toolkit) from 0.11.0 to 0.13.0. - [Release notes](https://github.com/prometheus/exporter-toolkit/releases) - [Changelog](https://github.com/prometheus/exporter-toolkit/blob/master/CHANGELOG.md) - [Commits](prometheus/exporter-toolkit@v0.11.0...v0.13.0) --- updated-dependencies: - dependency-name: github.com/prometheus/exporter-toolkit dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> * refactor: migrate to log/slog * refactor: extract logging logic to log.go, adjust loglevels * fix: refactoring issues * chore: go mod tidy * style: set to SlogStyle * fix: minor log changes --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Sergei Zyubin <[email protected]> Co-authored-by: Sergei Zyubin <[email protected]>
- Loading branch information
1 parent
d1db481
commit fd44637
Showing
14 changed files
with
153 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"log/slog" | ||
"os" | ||
|
||
"github.com/prometheus/common/promslog" | ||
) | ||
|
||
type logConfig struct { | ||
logger *slog.Logger | ||
logFileHandler *os.File | ||
} | ||
|
||
// initLogFile opens the log file for writing if a log file is specified. | ||
func initLogFile(logFile string) (*os.File, error) { | ||
if logFile == "" { | ||
return nil, nil | ||
} | ||
logFileHandler, err := os.OpenFile(logFile, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0o644) | ||
if err != nil { | ||
return nil, fmt.Errorf("error opening log file: %w", err) | ||
} | ||
return logFileHandler, nil | ||
} | ||
|
||
// initLogConfig configures and initializes the logging system. | ||
func initLogConfig(logLevel, logFormat string, logFile string) (*logConfig, error) { | ||
logFileHandler, err := initLogFile(logFile) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if logFileHandler == nil { | ||
logFileHandler = os.Stderr | ||
} | ||
|
||
promslogConfig := &promslog.Config{ | ||
Level: &promslog.AllowedLevel{}, | ||
Format: &promslog.AllowedFormat{}, | ||
Style: promslog.SlogStyle, | ||
Writer: logFileHandler, | ||
} | ||
|
||
if err := promslogConfig.Level.Set(logLevel); err != nil { | ||
return nil, err | ||
} | ||
|
||
if err := promslogConfig.Format.Set(logFormat); err != nil { | ||
return nil, err | ||
} | ||
// Initialize logger. | ||
logger := promslog.New(promslogConfig) | ||
|
||
return &logConfig{ | ||
logger: logger, | ||
logFileHandler: logFileHandler, | ||
}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.