Hello David,
thanks for sharing your thoughts! I believe this is the first time
logging in gensim was brought up :-)
> Also, as far as I could see, the logging uses the "utils" domain,
> which does not really tell where the message is coming from (esp. if
> the application also has a "utils" module), and so it is not possible
Not sure what you mean by "domain". What appears in the message is
determined by the formatter (which you can/should configure yourself).
Each module in gensim has its own logger, and gensim doesn't define
any handlers or formatters -- that's up to the application using
gensim. So actually, by default you shouldn't see any messages! Only a
line automatically emitted by Python that says "No handlers could be
found for logger xyz", which means the gensim library uses logging but
your application doesn't.
Now if you see logging messages, like you say you do, it probably
means you already added handlers to your root logger (the parent of
all loggers) and the messages are getting through via that root.
> to selectively surpass (or grep, for that matter) logging messages
> coming from gensim. I believe it would be better define a "gensim"
> upper domain, and then optionally have "gensim.utils",
> "gensim.corpus", etc.
Excellent point! That way, we'll be able to remove (or rather, not
add) handlers only to the top `gensim` logger, without affecting the
root.
David, would you be willing to add this functionality to gensim? That
is, change all the loggers from e.g. `getLogger('ldamodel')` to
`getLogger('gensim.models.ldamodel')`. Or maybe even
`getLogger(__name__)`, but I'm not sure if that wouldn't break things
in modules that can also act as scripts (__name__ == '__main__' then).
That idea with a fake NullHandler is also nice. It could be added to
the root logger `gensim`, in the top-level __init__.py, to get rid of
the "No handlers could be found for logger xyz" warnings.
I raised this issue on github:
https://github.com/piskvorky/gensim/issues/17
.
Cheers,
Radim