Skip to content
This repository was archived by the owner on Aug 18, 2025. It is now read-only.

Commit ffa9c97

Browse files
authored
Merge pull request #94 from AlonMaor14/set_log_format_json
Set logger format to json
2 parents 77cfc0e + 56b0746 commit ffa9c97

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

cmd/prometheus/main.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,11 @@ func main() {
256256
os.Exit(2)
257257
}
258258

259+
err = cfg.promlogConfig.Format.Set("json")
260+
if err != nil {
261+
fmt.Fprintln(os.Stderr, errors.Wrapf(err, "could not set log format json"))
262+
os.Exit(2)
263+
}
259264
logger := promlog.New(&cfg.promlogConfig)
260265

261266
cfg.web.ExternalURL, err = computeExternalURL(cfg.prometheusURL, cfg.web.ListenAddress)

storage/tsdb/v3io.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ type ReadyStorage struct {
5656
func (s *ReadyStorage) SetUseV3ioAggregations(useV3ioAggregations bool) {
5757
s.useV3ioAggregations = useV3ioAggregations
5858
configPath := s.getConfigPath()
59-
s.logger.Log("msg", "Creating v3io adapter after changing v3io aggregation indicator", "configPath", configPath, "useV3ioAggregations", useV3ioAggregations)
59+
level.Info(s.logger).Log("msg", "Creating v3io adapter after changing v3io aggregation indicator", "configPath", configPath, "useV3ioAggregations", useV3ioAggregations)
6060

6161
// create the initial v3io adapter
6262
adapter, _, err := s.createV3ioPromAdapater(configPath)
@@ -81,7 +81,7 @@ func (s *ReadyStorage) Set(db *tsdb.DB, startTimeMargin int64) {
8181

8282
// get the config path
8383
configPath := s.getConfigPath()
84-
s.logger.Log("msg", "Creating initial v3io adapter", "configPath", configPath)
84+
level.Info(s.logger).Log("msg", "Creating initial v3io adapter", "configPath", configPath)
8585

8686
// create the initial v3io adapter
8787
adapter, v3ioConfig, err := s.createV3ioPromAdapater(configPath)
@@ -122,7 +122,7 @@ func (s *ReadyStorage) Config() *config.V3ioConfig {
122122

123123
// Querier implements the Storage interface.
124124
func (s *ReadyStorage) Querier(ctx context.Context, mint, maxt int64) (storage.Querier, error) {
125-
s.logger.Log("msg", "Querier requested", "mint", mint, "maxt", maxt)
125+
level.Info(s.logger).Log("msg", "Querier requested", "mint", mint, "maxt", maxt)
126126

127127
if s.error != nil {
128128
return nil, errors.Wrap(s.error, "cannot return a querier without an adapter")
@@ -137,7 +137,7 @@ func (s *ReadyStorage) Querier(ctx context.Context, mint, maxt int64) (storage.Q
137137

138138
// Appender implements the Storage interface.
139139
func (s *ReadyStorage) Appender() (storage.Appender, error) {
140-
s.logger.Log("msg", "Appender requested")
140+
level.Info(s.logger).Log("msg", "Appender requested")
141141

142142
if s.error != nil {
143143
return nil, errors.Wrap(s.error, "cannot return an appender without an adapter")
@@ -168,7 +168,7 @@ func (s *ReadyStorage) getConfigPath() string {
168168
}
169169

170170
func (s *ReadyStorage) watchConfigForChanges(configPath string) error {
171-
s.logger.Log("msg", "Starting to watch configuration for changes", "configPath", configPath)
171+
level.Info(s.logger).Log("msg", "Starting to watch configuration for changes", "configPath", configPath)
172172

173173
// get initial file mtime
174174
lastConfigFileInfo, err := os.Stat(configPath)
@@ -195,7 +195,7 @@ func (s *ReadyStorage) watchConfigForChanges(configPath string) error {
195195
if lastConfigFileInfo.ModTime() != currentConfigFileInfo.ModTime() {
196196
lastConfigFileInfo = currentConfigFileInfo
197197

198-
s.logger.Log("msg", "Config file modification detected, recreating adapter", "configPath", configPath)
198+
level.Debug(s.logger).Log("msg", "Config file modification detected, recreating adapter", "configPath", configPath)
199199

200200
config.UpdateConfig(configPath)
201201
newV3ioPromAdapter, _, err := s.createV3ioPromAdapater(configPath)
@@ -209,7 +209,7 @@ func (s *ReadyStorage) watchConfigForChanges(configPath string) error {
209209
}
210210
}
211211

212-
s.logger.Log("msg", "Stopping config file change watch")
212+
level.Debug(s.logger).Log("msg", "Stopping config file change watch")
213213
}()
214214

215215
return nil
@@ -223,11 +223,11 @@ func (s *ReadyStorage) createV3ioPromAdapater(configPath string) (*V3ioPromAdapt
223223

224224
// if the disabled flag is set, don't create an adapter
225225
if loadedConfig.Disabled {
226-
s.logger.Log("msg", "Adapter is disabled, not creating")
226+
level.Info(s.logger).Log("msg", "Adapter is disabled, not creating")
227227
return nil, nil, nil
228228
}
229229

230-
s.logger.Log("msg", "Creating v3io adapter", "config", loadedConfig.String())
230+
level.Info(s.logger).Log("msg", "Creating v3io adapter", "config", loadedConfig.String())
231231

232232
adapter, err := NewV3ioProm(loadedConfig, nil)
233233
adapter.SetUseV3ioAggregations(s.useV3ioAggregations)

0 commit comments

Comments
 (0)