Fix: Replace all Printf log messages with appropriate loglevels

This commit is contained in:
2025-12-11 11:20:11 +01:00
parent d24d85b970
commit f13be109c2
12 changed files with 32 additions and 36 deletions

View File

@@ -220,7 +220,7 @@ func addUser(userSpec string) error {
return fmt.Errorf("adding user '%s' with roles '%s': %w", parts[0], parts[1], err) return fmt.Errorf("adding user '%s' with roles '%s': %w", parts[0], parts[1], err)
} }
cclog.Printf("Add User: Added new user '%s' with roles '%s'.\n", parts[0], parts[1]) cclog.Infof("Add User: Added new user '%s' with roles '%s'", parts[0], parts[1])
return nil return nil
} }
@@ -229,7 +229,7 @@ func delUser(username string) error {
if err := ur.DelUser(username); err != nil { if err := ur.DelUser(username); err != nil {
return fmt.Errorf("deleting user '%s': %w", username, err) return fmt.Errorf("deleting user '%s': %w", username, err)
} }
cclog.Printf("Delete User: Deleted user '%s' from DB.\n", username) cclog.Infof("Delete User: Deleted user '%s' from DB", username)
return nil return nil
} }
@@ -262,7 +262,7 @@ func generateJWT(authHandle *auth.Authentication, username string) error {
return fmt.Errorf("generating JWT for user '%s': %w", user.Username, err) return fmt.Errorf("generating JWT for user '%s': %w", user.Username, err)
} }
cclog.Printf("JWT: Successfully generated JWT for user '%s': %s\n", user.Username, jwt) cclog.Infof("JWT: Successfully generated JWT for user '%s': %s", user.Username, jwt)
return nil return nil
} }
@@ -294,7 +294,7 @@ func initSubsystems() error {
if err := importer.HandleImportFlag(flagImportJob); err != nil { if err := importer.HandleImportFlag(flagImportJob); err != nil {
return fmt.Errorf("importing job: %w", err) return fmt.Errorf("importing job: %w", err)
} }
cclog.Printf("Import Job: Imported Job '%s' into DB.\n", flagImportJob) cclog.Infof("Import Job: Imported Job '%s' into DB", flagImportJob)
} }
// Initialize taggers // Initialize taggers

View File

@@ -330,9 +330,9 @@ func (s *Server) Start(ctx context.Context) error {
MinVersion: tls.VersionTLS12, MinVersion: tls.VersionTLS12,
PreferServerCipherSuites: true, PreferServerCipherSuites: true,
}) })
cclog.Printf("HTTPS server listening at %s...\n", config.Keys.Addr) cclog.Infof("HTTPS server listening at %s...", config.Keys.Addr)
} else { } else {
cclog.Printf("HTTP server listening at %s...\n", config.Keys.Addr) cclog.Infof("HTTP server listening at %s...", config.Keys.Addr)
} }
// //
// Because this program will want to bind to a privileged port (like 80), the listener must // Because this program will want to bind to a privileged port (like 80), the listener must

View File

@@ -669,7 +669,7 @@ func (api *RestApi) startJob(rw http.ResponseWriter, r *http.Request) {
return return
} }
cclog.Printf("REST: %s\n", req.GoString()) cclog.Debugf("REST: %s", req.GoString())
req.State = schema.JobStateRunning req.State = schema.JobStateRunning
if err := importer.SanityChecks(&req); err != nil { if err := importer.SanityChecks(&req); err != nil {
@@ -713,7 +713,7 @@ func (api *RestApi) startJob(rw http.ResponseWriter, r *http.Request) {
} }
} }
cclog.Printf("new job (id: %d): cluster=%s, jobId=%d, user=%s, startTime=%d", id, req.Cluster, req.JobID, req.User, req.StartTime) cclog.Infof("new job (id: %d): cluster=%s, jobId=%d, user=%s, startTime=%d", id, req.Cluster, req.JobID, req.User, req.StartTime)
rw.Header().Add("Content-Type", "application/json") rw.Header().Add("Content-Type", "application/json")
rw.WriteHeader(http.StatusCreated) rw.WriteHeader(http.StatusCreated)
if err := json.NewEncoder(rw).Encode(DefaultApiResponse{ if err := json.NewEncoder(rw).Encode(DefaultApiResponse{
@@ -946,7 +946,7 @@ func (api *RestApi) checkAndHandleStopJob(rw http.ResponseWriter, job *schema.Jo
} }
} }
cclog.Printf("archiving job... (dbid: %d): cluster=%s, jobId=%d, user=%s, startTime=%d, duration=%d, state=%s", job.ID, job.Cluster, job.JobID, job.User, job.StartTime, job.Duration, job.State) cclog.Infof("archiving job... (dbid: %d): cluster=%s, jobId=%d, user=%s, startTime=%d, duration=%d, state=%s", job.ID, job.Cluster, job.JobID, job.User, job.StartTime, job.Duration, job.State)
// Send a response (with status OK). This means that errors that happen from here on forward // Send a response (with status OK). This means that errors that happen from here on forward
// can *NOT* be communicated to the client. If reading from a MetricDataRepository or // can *NOT* be communicated to the client. If reading from a MetricDataRepository or

View File

@@ -162,7 +162,7 @@ func archivingWorker() {
continue continue
} }
cclog.Debugf("archiving job %d took %s", job.JobID, time.Since(start)) cclog.Debugf("archiving job %d took %s", job.JobID, time.Since(start))
cclog.Printf("archiving job (dbid: %d) successful", job.ID) cclog.Infof("archiving job (dbid: %d) successful", job.ID)
repository.CallJobStopHooks(job) repository.CallJobStopHooks(job)
archivePending.Done() archivePending.Done()

View File

@@ -149,7 +149,7 @@ func InitDB() error {
} }
r.TransactionEnd(t) r.TransactionEnd(t)
cclog.Printf("A total of %d jobs have been registered in %.3f seconds.\n", i, time.Since(starttime).Seconds()) cclog.Infof("A total of %d jobs have been registered in %.3f seconds.", i, time.Since(starttime).Seconds())
return nil return nil
} }

View File

@@ -44,14 +44,14 @@ func Archiving(wg *sync.WaitGroup, ctx context.Context) {
return return
case <-ticks: case <-ticks:
t := time.Now().Add(-d) t := time.Now().Add(-d)
cclog.Printf("[METRICSTORE]> start archiving checkpoints (older than %s)...\n", t.Format(time.RFC3339)) cclog.Infof("[METRICSTORE]> start archiving checkpoints (older than %s)...", t.Format(time.RFC3339))
n, err := ArchiveCheckpoints(Keys.Checkpoints.RootDir, n, err := ArchiveCheckpoints(Keys.Checkpoints.RootDir,
Keys.Archive.RootDir, t.Unix(), Keys.Archive.DeleteInstead) Keys.Archive.RootDir, t.Unix(), Keys.Archive.DeleteInstead)
if err != nil { if err != nil {
cclog.Printf("[METRICSTORE]> archiving failed: %s\n", err.Error()) cclog.Errorf("[METRICSTORE]> archiving failed: %s", err.Error())
} else { } else {
cclog.Printf("[METRICSTORE]> done: %d files zipped and moved to archive\n", n) cclog.Infof("[METRICSTORE]> done: %d files zipped and moved to archive", n)
} }
} }
} }

View File

@@ -82,14 +82,14 @@ func Checkpointing(wg *sync.WaitGroup, ctx context.Context) {
case <-ctx.Done(): case <-ctx.Done():
return return
case <-ticks: case <-ticks:
cclog.Printf("[METRICSTORE]> start checkpointing (starting at %s)...\n", lastCheckpoint.Format(time.RFC3339)) cclog.Infof("[METRICSTORE]> start checkpointing (starting at %s)...", lastCheckpoint.Format(time.RFC3339))
now := time.Now() now := time.Now()
n, err := ms.ToCheckpoint(Keys.Checkpoints.RootDir, n, err := ms.ToCheckpoint(Keys.Checkpoints.RootDir,
lastCheckpoint.Unix(), now.Unix()) lastCheckpoint.Unix(), now.Unix())
if err != nil { if err != nil {
cclog.Printf("[METRICSTORE]> checkpointing failed: %s\n", err.Error()) cclog.Errorf("[METRICSTORE]> checkpointing failed: %s", err.Error())
} else { } else {
cclog.Printf("[METRICSTORE]> done: %d checkpoint files created\n", n) cclog.Infof("[METRICSTORE]> done: %d checkpoint files created", n)
lastCheckpoint = now lastCheckpoint = now
} }
} }
@@ -194,7 +194,7 @@ func (m *MemoryStore) ToCheckpoint(dir string, from, to int64) (int, error) {
continue continue
} }
cclog.Printf("[METRICSTORE]> error while checkpointing %#v: %s", workItem.selector, err.Error()) cclog.Errorf("[METRICSTORE]> error while checkpointing %#v: %s", workItem.selector, err.Error())
atomic.AddInt32(&errs, 1) atomic.AddInt32(&errs, 1)
} else { } else {
atomic.AddInt32(&n, 1) atomic.AddInt32(&n, 1)
@@ -394,7 +394,7 @@ func (m *MemoryStore) FromCheckpointFiles(dir string, from int64) (int, error) {
if err != nil { if err != nil {
cclog.Fatalf("[METRICSTORE]> Error creating directory: %#v\n", err) cclog.Fatalf("[METRICSTORE]> Error creating directory: %#v\n", err)
} }
cclog.Printf("[METRICSTORE]> %#v Directory created successfully.\n", dir) cclog.Debugf("[METRICSTORE]> %#v Directory created successfully", dir)
} }
// Config read (replace with your actual config read) // Config read (replace with your actual config read)
@@ -413,7 +413,7 @@ func (m *MemoryStore) FromCheckpointFiles(dir string, from int64) (int, error) {
if found, err := checkFilesWithExtension(dir, fileFormat); err != nil { if found, err := checkFilesWithExtension(dir, fileFormat); err != nil {
return 0, fmt.Errorf("[METRICSTORE]> error checking files with extension: %v", err) return 0, fmt.Errorf("[METRICSTORE]> error checking files with extension: %v", err)
} else if found { } else if found {
cclog.Printf("[METRICSTORE]> Loading %s files because fileformat is %s\n", fileFormat, fileFormat) cclog.Infof("[METRICSTORE]> Loading %s files because fileformat is %s", fileFormat, fileFormat)
return m.FromCheckpoint(dir, from, fileFormat) return m.FromCheckpoint(dir, from, fileFormat)
} }
@@ -422,7 +422,7 @@ func (m *MemoryStore) FromCheckpointFiles(dir string, from int64) (int, error) {
if found, err := checkFilesWithExtension(dir, altFormat); err != nil { if found, err := checkFilesWithExtension(dir, altFormat); err != nil {
return 0, fmt.Errorf("[METRICSTORE]> error checking files with extension: %v", err) return 0, fmt.Errorf("[METRICSTORE]> error checking files with extension: %v", err)
} else if found { } else if found {
cclog.Printf("[METRICSTORE]> Loading %s files but fileformat is %s\n", altFormat, fileFormat) cclog.Infof("[METRICSTORE]> Loading %s files but fileformat is %s", altFormat, fileFormat)
return m.FromCheckpoint(dir, from, altFormat) return m.FromCheckpoint(dir, from, altFormat)
} }

View File

@@ -119,7 +119,7 @@ func ReceiveNats(conf *(NatsConfig),
for m := range msgs { for m := range msgs {
dec := lineprotocol.NewDecoderWithBytes(m.Data) dec := lineprotocol.NewDecoderWithBytes(m.Data)
if err := DecodeLine(dec, ms, clusterTag); err != nil { if err := DecodeLine(dec, ms, clusterTag); err != nil {
cclog.Printf("error: %s\n", err.Error()) cclog.Errorf("error: %s", err.Error())
} }
} }
@@ -134,7 +134,7 @@ func ReceiveNats(conf *(NatsConfig),
sub, err = nc.Subscribe(sc.SubscribeTo, func(m *nats.Msg) { sub, err = nc.Subscribe(sc.SubscribeTo, func(m *nats.Msg) {
dec := lineprotocol.NewDecoderWithBytes(m.Data) dec := lineprotocol.NewDecoderWithBytes(m.Data)
if err := DecodeLine(dec, ms, clusterTag); err != nil { if err := DecodeLine(dec, ms, clusterTag); err != nil {
cclog.Printf("error: %s\n", err.Error()) cclog.Errorf("error: %s", err.Error())
} }
}) })
} }
@@ -142,7 +142,7 @@ func ReceiveNats(conf *(NatsConfig),
if err != nil { if err != nil {
return err return err
} }
cclog.Printf("NATS subscription to '%s' on '%s' established\n", sc.SubscribeTo, conf.Address) cclog.Infof("NATS subscription to '%s' on '%s' established", sc.SubscribeTo, conf.Address)
subs = append(subs, sub) subs = append(subs, sub)
} }
@@ -150,7 +150,7 @@ func ReceiveNats(conf *(NatsConfig),
for _, sub := range subs { for _, sub := range subs {
err = sub.Unsubscribe() err = sub.Unsubscribe()
if err != nil { if err != nil {
cclog.Printf("NATS unsubscribe failed: %s", err.Error()) cclog.Errorf("NATS unsubscribe failed: %s", err.Error())
} }
} }
close(msgs) close(msgs)

View File

@@ -27,7 +27,7 @@ func RegisterLdapSyncService(ds string) {
gocron.NewTask( gocron.NewTask(
func() { func() {
t := time.Now() t := time.Now()
cclog.Printf("ldap sync started at %s", t.Format(time.RFC3339)) cclog.Infof("ldap sync started at %s", t.Format(time.RFC3339))
if err := auth.LdapAuth.Sync(); err != nil { if err := auth.LdapAuth.Sync(); err != nil {
cclog.Errorf("ldap sync failed: %s", err.Error()) cclog.Errorf("ldap sync failed: %s", err.Error())
} }

View File

@@ -25,8 +25,8 @@ func RegisterUpdateDurationWorker() {
gocron.NewTask( gocron.NewTask(
func() { func() {
start := time.Now() start := time.Now()
cclog.Printf("Update duration started at %s\n", start.Format(time.RFC3339)) cclog.Infof("Update duration started at %s", start.Format(time.RFC3339))
jobRepo.UpdateDuration() jobRepo.UpdateDuration()
cclog.Printf("Update duration is done and took %s\n", time.Since(start)) cclog.Infof("Update duration is done and took %s", time.Since(start))
})) }))
} }

View File

@@ -34,7 +34,7 @@ func RegisterFootprintWorker() {
c := 0 c := 0
ce := 0 ce := 0
cl := 0 cl := 0
cclog.Printf("Update Footprints started at %s\n", s.Format(time.RFC3339)) cclog.Infof("Update Footprints started at %s", s.Format(time.RFC3339))
for _, cluster := range archive.Clusters { for _, cluster := range archive.Clusters {
s_cluster := time.Now() s_cluster := time.Now()
@@ -136,6 +136,6 @@ func RegisterFootprintWorker() {
} }
cclog.Debugf("Finish Cluster %s, took %s\n", cluster.Name, time.Since(s_cluster)) cclog.Debugf("Finish Cluster %s, took %s\n", cluster.Name, time.Since(s_cluster))
} }
cclog.Printf("Updating %d (of %d; Skipped %d) Footprints is done and took %s\n", c, cl, ce, time.Since(s)) cclog.Infof("Updating %d (of %d; Skipped %d) Footprints is done and took %s", c, cl, ce, time.Since(s))
})) }))
} }

View File

@@ -50,7 +50,7 @@ func importArchive(srcBackend, dstBackend archive.ArchiveBackend) (int, int, err
// Create channels for job distribution // Create channels for job distribution
jobs := make(chan archive.JobContainer, numWorkers*2) jobs := make(chan archive.JobContainer, numWorkers*2)
// WaitGroup to track worker completion // WaitGroup to track worker completion
var wg sync.WaitGroup var wg sync.WaitGroup
@@ -127,8 +127,6 @@ func importArchive(srcBackend, dstBackend archive.ArchiveBackend) (int, int, err
return finalImported, finalFailed, nil return finalImported, finalFailed, nil
} }
func main() { func main() {
var srcPath, flagConfigFile, flagLogLevel, flagRemoveCluster, flagRemoveAfter, flagRemoveBefore string var srcPath, flagConfigFile, flagLogLevel, flagRemoveCluster, flagRemoveAfter, flagRemoveBefore string
var flagSrcConfig, flagDstConfig string var flagSrcConfig, flagDstConfig string
@@ -147,7 +145,6 @@ func main() {
flag.StringVar(&flagDstConfig, "dst-config", "", "Destination archive backend configuration (JSON), e.g. '{\"kind\":\"sqlite\",\"dbPath\":\"./archive.db\"}'") flag.StringVar(&flagDstConfig, "dst-config", "", "Destination archive backend configuration (JSON), e.g. '{\"kind\":\"sqlite\",\"dbPath\":\"./archive.db\"}'")
flag.Parse() flag.Parse()
archiveCfg := fmt.Sprintf("{\"kind\": \"file\",\"path\": \"%s\"}", srcPath) archiveCfg := fmt.Sprintf("{\"kind\": \"file\",\"path\": \"%s\"}", srcPath)
cclog.Init(flagLogLevel, flagLogDateTime) cclog.Init(flagLogLevel, flagLogDateTime)
@@ -189,7 +186,6 @@ func main() {
ccconf.Init(flagConfigFile) ccconf.Init(flagConfigFile)
// Load and check main configuration // Load and check main configuration
if cfg := ccconf.GetPackageConfig("main"); cfg != nil { if cfg := ccconf.GetPackageConfig("main"); cfg != nil {
if clustercfg := ccconf.GetPackageConfig("clusters"); clustercfg != nil { if clustercfg := ccconf.GetPackageConfig("clusters"); clustercfg != nil {
@@ -209,7 +205,7 @@ func main() {
if flagValidate { if flagValidate {
config.Keys.Validate = true config.Keys.Validate = true
for job := range ar.Iter(true) { for job := range ar.Iter(true) {
cclog.Printf("Validate %s - %d\n", job.Meta.Cluster, job.Meta.JobID) cclog.Debugf("Validate %s - %d", job.Meta.Cluster, job.Meta.JobID)
} }
os.Exit(0) os.Exit(0)
} }