Add logging support
ClosedPublic

Authored by mkrizek on Feb 11 2014, 3:59 PM.

Details

Summary

Only stream logging with debug level is enabled for now.

Test Plan

Works on my dev machine.

Diff Detail

Lint
Lint Skipped
Unit
Unit Tests Skipped
tflink requested changes to this revision.Feb 12 2014, 7:44 AM

Other than the init issue and the potential conflicts with D5, it looks good to me. We'll need to file a task for actually configuring the logs in a sane way, but I see that as a bit out of scope for this change.

libtaskotron/__init__.py
4 ↗(On Diff #13)

In general, init on import is a bad idea. I think this should be initialized on startup of the runner instead. Explicit is better in this case and it'll be all the more important when we start shipping logs - it shouldn't try to connect to anything over the network until explicitly initialized

libtaskotron/runner.py
3

Can you back the logging changes out of the runner? I'd prefer adding these changes to D5 or separately so that the merge into that code isn't quite so messy since D5 changes this code so much.

Agreed, configuring the logs will be done separately.

libtaskotron/__init__.py
4 ↗(On Diff #13)

Just a note, the init function will not change when we start shipping logs nor it will try to connect to anything over the network. logstash just scans whatever logging produces. Anyway, I am fine with putting init into the runner.

libtaskotron/runner.py
3

Yeah, I was/am going to hold on with this until D5 is merged in develop.

mkrizek updated this revision.Feb 12 2014, 12:54 PM
  • Move logger init into runner
kparal added inline comments.Feb 12 2014, 12:56 PM
libtaskotron/__init__.py
4 ↗(On Diff #13)

How will it work when I use some libtaskotron module but don't run it through the runner (containing the init code)? Martin, please test.

4 ↗(On Diff #13)

Do we want to default to DEBUG? It might be better to have a command line option for that a default to WARN or INFO?

libtaskotron/file_utils.py
77

Let's change to logging.debug()

libtaskotron/logger.py
37–38

Can you add docstrings for the arguments? Not everyone knows what 'streaming' is, where does it stream to, and what kind of values filelog accepts - e.g. file names or handlers. Should filelog default to None instead?

mkrizek added inline comments.Feb 12 2014, 2:42 PM
libtaskotron/__init__.py
4 ↗(On Diff #13)

How will it work when I use some libtaskotron module but don't run it through the runner (containing the init code)? Martin, please test.

In that case, the output is muted. You need to run the init function in order to use logging.

Do we want to default to DEBUG? It might be better to have a command line option for that a default to WARN or INFO?

Let's leave default to DEBUG for now for development purposes and change it along with adding command line/configuration options with sane defaults for another task.

mkrizek updated this revision.Feb 12 2014, 2:43 PM
  • Add docstring to the logger.init function

Kamil: I can't think of any use cases where we'd be using libtaskotron without the runner and didn't think it was a problem - did I miss a use case?

If not, it looks good to me

Kamil: I can't think of any use cases where we'd be using libtaskotron without the runner and didn't think it was a problem - did I miss a use case?

For example the upgradepath script, I want to be able to run it standalone, without the runner, like this:

$ ./upgradepath.py f20-updates

I'm using libtaskotron modules inside for koji and bodhi operations, for example.

If I need to call some special method to enable logging in those modules, that's fine for me (and I don't know what the usual approach is anyway). I was just worried whether it would crash or something.

mkrizek updated this revision.Feb 19 2014, 12:23 PM
  • Use custom logger instead of the root logger
kparal requested changes to this revision.Feb 19 2014, 12:51 PM

Only the sys.excepthook needs to be changed I think, the rest of it are cosmetic issues.

libtaskotron/directives/koji_directive.py
83

pylint says you can use comma instead of the percent sign, it could be a bit more efficient. this applies to everywhere else

libtaskotron/logger.py
35

The docs say you can use logger.exception() for this use case:
http://docs.python.org/2.7/library/logging.html#logging.Logger.exception

Also, you should call this on 'log' variable instead of 'logging' module?

39

I think this should go into init() (i.e. we run the program)? Otherwise we will override this setting for anyone using our library.

44

I would default to name='libtaskotron'

libtaskotron/runner.py
126

libtaskotron.logger.init() would be clearer here

mkrizek updated this revision.Feb 19 2014, 3:30 PM
  • Move excepthook into logger.init
kparal accepted this revision.Feb 19 2014, 3:58 PM
mkrizek closed this revision.Feb 20 2014, 9:57 AM

Closed by commit rLTRN2a5dc7b7e7b8 (authored by @mkrizek).