rancher / qa-tasks

List of QA Backlog
1 stars 1 forks source link

Update logging in distros-test-framework to be simpler #1232

Open rancher-max opened 2 months ago

rancher-max commented 2 months ago

The discussion here prompted this: https://github.com/rancher/distros-test-framework/pull/70#discussion_r1516617439.

Right now, we have this LogLevel function (https://github.com/rancher/distros-test-framework/blob/fe3c16a1103806c6040cba2061d14b305d735322/shared/aux.go#L270-L298) where we pass in which level we want to print the log at. However, we don't have any gating for what the overall log level to print is -- it is always just at debug mode (see https://github.com/rancher/distros-test-framework/blob/fe3c16a1103806c6040cba2061d14b305d735322/pkg/logger/logger.go#L29). We should be OK to print logs at different levels to help us debug our own tests, but then we actually run them for tests (like in Jenkins or locally for patch validations) we should be able to just run on info level and all of the debug logs shouldn't print. This may require some redesign on the way we have the logger built currently, but hopefully not too much of an effort there.

fmoral2 commented 2 months ago

hey this is just the "entry" log level of the framework that u need to set in the setup. Its not set to debug always, is just a config telling the base level log that u want to start , and your consumers, you can call any log level

fmoral2 commented 2 months ago

this is an example of usage from the docs

package main

import (
  "os"
  log "github.com/sirupsen/logrus"
)

func init() {
  // Log as JSON instead of the default ASCII formatter.
  log.SetFormatter(&log.JSONFormatter{})

  // Output to stdout instead of the default stderr
  // Can be any io.Writer, see below for File example
  log.SetOutput(os.Stdout)

  // Only log the warning severity or above.
  log.SetLevel(log.WarnLevel)                             =>>>>>>>  here is what i said about entry level 
}

func main() {
  log.WithFields(log.Fields{
    "animal": "walrus",
    "size":   10,
  }).Info("A group of walrus emerges from the ocean")

  log.WithFields(log.Fields{
    "omg":    true,
    "number": 122,
  }).Warn("The group's number increased tremendously!")           =>>>>>>>  here is the different level usages 

  log.WithFields(log.Fields{
    "omg":    true,
    "number": 100,
  }).Fatal("The ice breaks!")                            =>>>>>>>  here is the different level usages 

  // A common pattern is to re-use fields between logging statements by re-using
  // the logrus.Entry returned from WithFields()
  contextLogger := log.WithFields(log.Fields{
    "common": "this is a common field",
    "other": "I also should be logged always",
  })

  contextLogger.Info("I'll be logged with common and other field")
  contextLogger.Info("Me too")                =>>>>>>>  here is the different level usages 
}

https://github.com/sirupsen/logrus

fmoral2 commented 2 months ago

So basically in our framework , you can call shared.LogLevel( "ANY LEVEL YOU WANT", " YOUR CUSTOM MESSAGE " )

and it will be logged only the level you choose

rancher-max commented 2 months ago

yeah I just mean to be simpler in general, so like with those docs you shared it'll only log the "WARN" and "FATAL" bits, which is expected since that's the level of the logger: https://go.dev/play/p/SctOdFImZ6-

So in the way we have it right now, it doesn't matter if you call shared.LogLevel("Info", "message") because that will get output every time the code is run. I think it would be nice to have logs at different levels and then the ability to run the code with different levels so that we can say "run at info level in Jenkins" but "run at debug level when working locally and updating the code" for example

fmoral2 commented 2 months ago

yeah I just mean to be simpler in general, so like with those docs you shared it'll only log the "WARN" and "FATAL" bits, which is expected since that's the level of the logger: https://go.dev/play/p/SctOdFImZ6-

So in the way we have it right now, it doesn't matter if you call shared.LogLevel("Info", "message") because that will get output every time the code is run. I think it would be nice to have logs at different levels and then the ability to run the code with different levels so that we can say "run at info level in Jenkins" but "run at debug level when working locally and updating the code" for example

OH got you now .

The idea is good, but how is this simpler ?

you are going to add configs and "ifs " in a lot of places instead of just using the level you want for that specific place.

rancher-max commented 2 months ago

Nah no configs or ifs, just maybe a top level flag for logLevel or something like that

fmoral2 commented 2 months ago

Nah no configs or ifs, just maybe a top level flag for logLevel or something like that

got you , but i am not seeing a simpler way even just with some top variable/flag since you will still need to manage that in some way , like adding another param to the func, and updating all calls to pass like LogLevel(" level" , " message " , "workEnv " ) and then inside here managing all envs that u want different logs or not

anyway, this is totally doable and nice to have, but on POV its not simpler.