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

Formatting the log using parameter progname for the logger #1605

Closed
kodram opened this issue Dec 3, 2024 · 0 comments · Fixed by #1606
Closed

Formatting the log using parameter progname for the logger #1605

kodram opened this issue Dec 3, 2024 · 0 comments · Fixed by #1606

Comments

@kodram
Copy link
Contributor

kodram commented Dec 3, 2024

Basic Info

  • Faraday Version: 2.12.1
  • Ruby Version: ruby 3.2.2 (2023-03-30 revision e51014f9c0) [x86_64-linux]

Issue description

Now the logger uses the progname parameter as the message type. For example, here:

public_send(log_level, 'response') { "Status #{env.status}" }

https://docs.ruby-lang.org/en/master/Logger.html#method-i-info

And now you can't use this parameter from the outside. For example, like this:

conn = Faraday.new(url: 'http:/hello') do |faraday|
  faraday.response :logger, MyLogger.new($stdout, progname: 'my_best_program')
end

The log will still remain the same:

I, [2024-12-03T18:34:44.550323 #2735645]  INFO -- : request: GET http:/hello
I, [2024-12-03T18:34:44.550353 #2735645]  INFO -- : request: User-Agent: "Faraday v2.12.1"
I, [2024-12-03T18:34:44.550427 #2735645]  INFO -- : response: Status 200
I, [2024-12-03T18:34:44.550435 #2735645]  INFO -- : response: Content-Type: "text/html"

It seems to me it is better to transfer the message type from progname to the message body. And then this parameter will be used in the log:

I, [2024-12-03T18:35:01.582513 #2736044]  INFO -- my_best_program: request: GET http:/hello
I, [2024-12-03T18:35:01.582543 #2736044]  INFO -- my_best_program: request: User-Agent: "Faraday v2.12.1"
I, [2024-12-03T18:35:01.582619 #2736044]  INFO -- my_best_program: response: Status 200
I, [2024-12-03T18:35:01.582628 #2736044]  INFO -- my_best_program: response: Content-Type: "text/html"

This is necessary when several logs are recorded in one place (for example, in one file), and then you can easily separate some logger entries from others by parameter progname.

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 a pull request may close this issue.

1 participant