Skip to content

Commit 6e102e5

Browse files
authoredMar 3, 2025
slog fixes (#190)
Signed-off-by: Anders Swanson <anders.swanson@oracle.com>
1 parent 7184018 commit 6e102e5

File tree

3 files changed

+15
-16
lines changed

3 files changed

+15
-16
lines changed
 

‎collector/collector.go

+12-14
Original file line numberDiff line numberDiff line change
@@ -216,12 +216,12 @@ func (e *Exporter) scrape(ch chan<- prometheus.Metric, tick *time.Time) {
216216
begun := time.Now()
217217

218218
if connectionError := e.db.Ping(); connectionError != nil {
219-
e.logger.Debug("error = " + connectionError.Error())
219+
e.logger.Debug("connection error", "error", connectionError)
220220
if strings.Contains(connectionError.Error(), "sql: database is closed") {
221221
e.logger.Info("Reconnecting to DB")
222222
connectionError = e.connect()
223223
if connectionError != nil {
224-
e.logger.Error("Error reconnecting to DB", connectionError)
224+
e.logger.Error("Error reconnecting to DB", "error", connectionError)
225225
}
226226
}
227227
}
@@ -327,7 +327,7 @@ func (e *Exporter) connect() error {
327327
var P godror.ConnectionParams
328328
// If password is not specified, externalAuth will be true and we'll ignore user input
329329
e.externalAuth = e.password == ""
330-
e.logger.Debug("external authentication set to ", e.externalAuth)
330+
e.logger.Debug(fmt.Sprintf("external authentication set to %t", e.externalAuth))
331331
msg := "Using Username/Password Authentication."
332332
if e.externalAuth {
333333
msg = "Database Password not specified; will attempt to use external authentication (ignoring user input)."
@@ -341,15 +341,15 @@ func (e *Exporter) connect() error {
341341
P.Username, P.Password, P.ConnectString, P.ExternalAuth = e.user, godror.NewPassword(e.password), e.connectString, externalAuth
342342

343343
if e.config.PoolIncrement > 0 {
344-
e.logger.Debug("set pool increment to ", e.config.PoolIncrement)
344+
e.logger.Debug(fmt.Sprintf("set pool increment to %d", e.config.PoolIncrement))
345345
P.PoolParams.SessionIncrement = e.config.PoolIncrement
346346
}
347347
if e.config.PoolMaxConnections > 0 {
348-
e.logger.Debug("set pool max connections to ", e.config.PoolMaxConnections)
348+
e.logger.Debug(fmt.Sprintf("set pool max connections to %d", e.config.PoolMaxConnections))
349349
P.PoolParams.MaxSessions = e.config.PoolMaxConnections
350350
}
351351
if e.config.PoolMinConnections > 0 {
352-
e.logger.Debug("set pool min connections to ", e.config.PoolMinConnections)
352+
e.logger.Debug(fmt.Sprintf("set pool min connections to %d", e.config.PoolMinConnections))
353353
P.PoolParams.MinSessions = e.config.PoolMinConnections
354354
}
355355

@@ -377,17 +377,15 @@ func (e *Exporter) connect() error {
377377
P.AdminRole = dsn.NoRole
378378
}
379379

380-
e.logger.Debug("connection properties: " + fmt.Sprint(P))
381-
382380
// note that this just configures the connection, it does not actually connect until later
383381
// when we call db.Ping()
384382
db := sql.OpenDB(godror.NewConnector(P))
385-
e.logger.Debug("set max idle connections to ", e.config.MaxIdleConns)
383+
e.logger.Debug(fmt.Sprintf("set max idle connections to %d", e.config.MaxIdleConns))
386384
db.SetMaxIdleConns(e.config.MaxIdleConns)
387-
e.logger.Debug("set max open connections to ", e.config.MaxOpenConns)
385+
e.logger.Debug(fmt.Sprintf("set max open connections to %d", e.config.MaxOpenConns))
388386
db.SetMaxOpenConns(e.config.MaxOpenConns)
389387
db.SetConnMaxLifetime(0)
390-
e.logger.Debug("Successfully configured connection to " + maskDsn(e.connectString))
388+
e.logger.Debug(fmt.Sprintf("Successfully configured connection to %d" + maskDsn(e.connectString)))
391389
e.db = db
392390

393391
if _, err := db.Exec(`
@@ -399,13 +397,13 @@ func (e *Exporter) connect() error {
399397

400398
var result int
401399
if err := db.QueryRow("select sys_context('USERENV', 'CON_ID') from dual").Scan(&result); err != nil {
402-
e.logger.Info("dbtype err =" + string(err.Error()))
400+
e.logger.Info("dbtype err", "error", err)
403401
}
404402
e.dbtype = result
405403

406404
var sysdba string
407405
if err := db.QueryRow("select sys_context('USERENV', 'ISDBA') from dual").Scan(&sysdba); err != nil {
408-
e.logger.Info("got error checking my database role")
406+
e.logger.Error("error checking my database role", "error", err)
409407
}
410408
e.logger.Info("Connected as SYSDBA? " + sysdba)
411409

@@ -463,7 +461,7 @@ func (e *Exporter) reloadMetrics() {
463461
for _, _customMetrics := range strings.Split(e.config.CustomMetrics, ",") {
464462
metrics := &Metrics{}
465463
if _, err := toml.DecodeFile(_customMetrics, metrics); err != nil {
466-
e.logger.Error("failed to load custom metrics", err)
464+
e.logger.Error("failed to load custom metrics", "error", err)
467465
panic(errors.New("Error while loading " + _customMetrics))
468466
} else {
469467
e.logger.Info("Successfully loaded custom metrics from " + _customMetrics)

‎collector/default_metrics.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func (e *Exporter) DefaultMetrics() Metrics {
2828
}
2929

3030
if _, err := toml.Decode(defaultMetricsToml, &metricsToScrape); err != nil {
31-
e.logger.Error("failed to load default metrics", err)
31+
e.logger.Error("failed to load default metrics", "error", err)
3232
panic(errors.New("Error while loading " + defaultMetricsToml))
3333
}
3434
return metricsToScrape

‎main.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package main
66

77
import (
88
"context"
9+
"fmt"
910
"github.com/prometheus/common/promslog"
1011
"github.com/prometheus/common/promslog/flag"
1112
"net/http"
@@ -172,7 +173,7 @@ func main() {
172173
if *logDisable == 1 {
173174
logger.Info("log.disable set to 1, so will not export the alert logs")
174175
} else {
175-
logger.Info("Exporting alert logs to ", *logDestination)
176+
logger.Info(fmt.Sprintf("Exporting alert logs to %s", *logDestination))
176177
logTicker := time.NewTicker(*logInterval)
177178
defer logTicker.Stop()
178179

0 commit comments

Comments
 (0)
Failed to load comments.