jenkinsci / plugin-installation-manager-tool

Plugin Manager CLI tool for Jenkins
MIT License
394 stars 202 forks source link

[JENKINS-57973] Switch Plugin Installation Manager Tool to Java Util Logging Export #263

Open hp77-creator opened 3 years ago

hp77-creator commented 3 years ago

Currently the tool uses System out for logging. It would be great to switch to Java Util Logging so that the tool can be used as a library in Jenkins components.

Reporter: Oleg Nenashev

202

10

timja commented 3 years ago

Doesn't have to be java util logging, just should probably use a proper logger

hp77-creator commented 3 years ago

what are the other options @timja , I know about log4j, and what do you mean by a proper logger, is java.util.logging not a proper logger?

timja commented 3 years ago

it is yes although it's not very user friendly, but most of Jenkins seems to use it for some reason so maybe best to stick to it.

here's a link with some other ones: https://stackify.com/compare-java-logging-frameworks/

hp77-creator commented 3 years ago

I don't have any issue in using other library, do we need to follow the trend of using JUL? Going through that link, I just saw that log4j has been archived, log4j2 is the currently developed library while I read somewhere that many prefer slf4j with logback over JUL, so I will explore all of these, And will update you with the preferred option. Frankly I have never used JUL in any of the project so idk what nuances it presents, I will try it.

timja commented 3 years ago

The api is just... bad

But fine to keep the status quo and use JUL

log4j2 is the most modern logger java has as far as I know with logback over slf4j being the second choice normally

hp77-creator commented 3 years ago

I see! :sweat_smile: tbh they seemed fine to me, There are levels defined which can be then used to print the logs(This shows the knowledge of logging that I have at the moment, don't know of its behaviour in printing to file or console), but if you have any example in mind, I would love to hear those, and can you also shed some info on how do you categorise APIs to be bad or good, Maybe I will learn to write/use them better in the process. Thanks.

timja commented 3 years ago

JUL has very limited parameters for the level specific methods,

logger.warn("") etc only take very limited parameters.

99% of the time you end up having to do:

logger.log(Level.WARN, "My message", e)

and then if you want to pass parameters to your log message you need to create an object array and you the MessageFormat string format which is not that nice either

hp77-creator commented 3 years ago

@timja, What format should I keep for the log messages?Default one prints out

Date time Class name Method name
Level: Message

like this:

May 20, 2021 6:52:20 PM io.jenkins.tools.pluginmanager.impl.PluginManager getJson
INFO: Cache miss for: plugin-versions
timja commented 3 years ago

I don't think anything should be there at all other than the message

hp77-creator commented 3 years ago

not even the level? Like how it is in maven?

timja commented 3 years ago

no it's a CLI, try out some other CLI tools and see the output they give, a debug / verbose level log could maybe add some more information

hp77-creator commented 3 years ago

I have used some linux cli tools, and yep they give some additional information in verbose mode, so you are suggesting to add some more info here or you are saying it is too much for a non verbose mode? I am sorry I don't understand that part.

hectoralicea commented 3 years ago

Yea, additional log4j logging capability would really help debug when your troubleshooting your corporate proxy connection. Need to see headers to and from for the plugins download http calls.