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

Add new pseudo log level CONSOLE that logs to console and to log file #4536

Closed
IlfirinPL opened this issue Nov 15, 2022 · 10 comments
Closed
Labels
Milestone

Comments

@IlfirinPL
Copy link
Contributor

It would be useful to allow set log level to "Console" for keyword,
Currently To print list of dictionary you have to do it your self using Log To Console

Keywords in mind

  • Log Dictionary
  • Log List
@pekkaklarck
Copy link
Member

Do you mean that if you'd log something with a level CONSOLE, it would be logged to the console? For example:

Log    message    level=CONSOLE

That sounds fine to me. The Log keyword actually has also_console=False option so this wouldn't be too useful with it, but other keywords accepting an optional log level would benefit. Possibly also_console could then later be deprecated.

I guess it would make sense to log the message to the log file using INFO level as well. In practice CONSOLE would then be a new pseudo level like HTML that logs the message as INFO so that the message is rendered as HTML. We could consider making it possible to change the level of the message written to log with something like CONSOLE:WARN and HTML:DEBUG, but that would require its own issue.

@IlfirinPL
Copy link
Contributor Author

Yes, exactly. "level=CONSOLE", its provided information about intend where information will be printed.
In long run it would be better to add parameter "output" where options there would be example "console | html |file | etc." and log level keep only for information about "log level"

@pekkaklarck
Copy link
Member

New options can be added to keywords if needed. What I like about adding CONSOLE pseudo log level is that it doesn't need them, all keywords that support customizing the log level benefit from it automatically. Supporting level with CONSOLE, and HTML, wouldn't be hard but should get its own issue. We could also support HTML:CONSOLE:DEBUG if needed.

This would be a safe enhancement to do already in RF 6.1. It's also pretty easy so good candidate for someone wanting to contribute.

@pekkaklarck pekkaklarck added this to the v6.1 milestone Nov 15, 2022
@pekkaklarck pekkaklarck changed the title Add new Log Level "Console" Add new pseudo log level CONSOLE that logs to console and to log file Nov 15, 2022
@Snooz82
Copy link
Member

Snooz82 commented Jan 11, 2023

I do not really get it.

Scenario:
So you run robot --loglevel INFO
then you have the following test

*** Task ***
Task
   Log    Hello    level=CONSOLE    #what should happen here???
   Log    World    level=DEBUG    #It is logged as DEBUG
   Log     Failure    level=ERROR    #It is logged as Error

So would be Log Hello level=CONSOLE the same as Log To Console Hello ?

But how would you prevent that logging?
Log World level=DEBUG is not logged, when you run robot --loglevel INFO

For me that sounds inconsistent and would be better to implement as library keyword in an own lib.

@IlfirinPL
Copy link
Contributor Author

I see it as level above INFO since print more then info itself.

So would be Log Hello level=CONSOLE the same as Log To Console Hello ?

Yes, but this change is mostly in mind of other keywords Log List and Log Dictionary

And for preventing that log its for me weird question, since when you set to log level to console you expect to log to console, the same as you would as Log To Console question how to stop from printing to console.

The author decide expected behavior

@pekkaklarck
Copy link
Member

Yeah, this feature isn't useful at all with the Log keyword, it already has a separate console argument, but it's convenient with other keywords that accept log level as an argument. This is basically same as adding a console argument to all of them. This is also really easy to implement.

@fabioz
Copy link
Contributor

fabioz commented Jan 16, 2023

I think that level as CONSOLE doesn't make sense semantically for me.

INFO, DEBUG, ERROR do make sense as level. CONSOLE is not a level, so, trying to reuse that argument is really weird for me.

Having a console=True in Log List does makes more sense IMHO. Users can always create their own keywords to set that console=True by default if they want.

This is basically same as adding a console argument to all of them. This is also really easy to implement.

This means that what you plan to implement is adding the console parameter to each of those?

@IlfirinPL
Copy link
Contributor Author

For me any solution that allow to print to console list of dictionary is ok for me

@turunenm turunenm mentioned this issue Mar 6, 2023
@pekkaklarck pekkaklarck added the acknowledge To be acknowledged in release notes label Mar 14, 2023
@pekkaklarck
Copy link
Member

This was implemented by @turunenm in PR #4673. Thanks for contribution!

@pekkaklarck
Copy link
Member

There was a comment above stating that it would be better to add optional console argument to Log List and other such keywords. That could have been done with a single keyword, but a new pseudo log level adds this capability to all keywords accepting log levels without making any other changes. We already had similar HTML pseudo level earlier so there's precedence.

Another benefit of this new pseudo level is that in simple libraries you can write to console using print('*CONSOLE* Message') instead of print('Message', file=sys.__stdout__).

pekkaklarck added a commit that referenced this issue Mar 14, 2023
When using `print('*CONSOLE* Message')`, the space before `Message`
was included into the message logged to the console. It's removed from
the message written to the log file later, but needs to be removed
separately here. This minor fix is related to #4536.
yanne pushed a commit that referenced this issue Mar 18, 2023
yanne pushed a commit that referenced this issue Mar 18, 2023
When using `print('*CONSOLE* Message')`, the space before `Message`
was included into the message logged to the console. It's removed from
the message written to the log file later, but needs to be removed
separately here. This minor fix is related to #4536.
yanne pushed a commit that referenced this issue Mar 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants