Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dont init the logger inside config #3960

Closed
wants to merge 3 commits into from
Closed

Conversation

Peltoche
Copy link
Contributor

@Peltoche Peltoche commented Jun 1, 2023

No description provided.

@Peltoche Peltoche requested a review from a team as a code owner June 1, 2023 12:25
Copy link
Member

@nono nono left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are some CLI commands like cozy-stack jobs run, for which we want to have initialized loggers, but the stack init is not called

@Peltoche
Copy link
Contributor Author

Peltoche commented Jun 1, 2023

There are some CLI commands like cozy-stack jobs run, for which we want to have initialized loggers, but the stack init is not called

Seems that we don't use the logger for that but directly fmt.Printf:

		if flagJobPrintLogs {
			o.Logs = make(chan *client.JobLog)
			go func() {
				for log := range o.Logs {
					fmt.Printf("[%s]", log.Level)
					if flagJobPrintLogsVerbose {
						fmt.Printf("[time:%s]", log.Time.Format(time.RFC3339))
						for k, v := range log.Data {
							fmt.Printf("[%s:%s]", k, v)
						}
					}
					fmt.Printf(" %s\n", log.Message)
				}
			}()
		}

I don't see any import to logrus or pkg/log* in /cmd

@nono
Copy link
Member

nono commented Jun 1, 2023

OK, bad example. Let's take cozy-stack fix mime.

@nono
Copy link
Member

nono commented Jun 1, 2023

Or the cozy-stack swift ...

@Peltoche
Copy link
Contributor Author

Peltoche commented Jun 1, 2023

Both seems to do only calls via the http client and use fmt.Print* for the outputs. This seems coherent, if this was not the case this would mean that we are running server code directly inside the client and we would have logrus outputs for the cli.

By moving out the logger and debugger setting from the `config.Setup`
func we avoid them to be call for each command and so force an
unecessary dependency to redis for every commands
This reverts commit 3e71fc3.

After moving the logger and debugger out of `config.Setup` we
can handle the error again
@nono
Copy link
Member

nono commented Jun 1, 2023

if this was not the case this would mean that we are running server code directly inside the client

We do have server code running inside the client. I don't remember for which commands, it is a legacy things. When I have time, I try to rewrite them to move the code on the server, but I don't think we are done.

@Peltoche
Copy link
Contributor Author

Peltoche commented Jun 1, 2023

Ok, good to know.

And for those case the default logrus config is not enough? All we want we want is to print the logs on stdout and the logrus.StandardLogger does that by default. If we don't call logger.Init we will fallback on the default logrus logger config with a MemDebugger.

@nono
Copy link
Member

nono commented Jun 5, 2023

All we want we want is to print the logs on stdout and the logrus.StandardLogger does that by default.

Nope, I would prefer to send the logs to syslog. What should be printed on stdout or stderr should use an explicit fmt.Printf (or equivalent).

@Peltoche
Copy link
Contributor Author

Peltoche commented Jun 9, 2023

Everyone seems to aggreed that if there is some remaining logs on cozy-stack we should send them on syslog and not stdout.

This review could be resolved when we will be sure that there is no more logs inside cozy-stack

@Peltoche Peltoche closed this Jun 9, 2023
@nono nono deleted the dont-init-in-config branch June 21, 2023 08:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants