{"action":"created","issue":{"url":"https://api.github.com/repos/qtile/qtile/issues/841","labels_url":"https://api.github.com/repos/qtile/qtile/issues/841/labels{/name}","comments_url":"https://api.github.com/repos/qtile/qtile/issues/841/comments","events_url":"https://api.github.com/repos/qtile/qtile/issues/841/events","html_url":"https://github.com/qtile/qtile/issues/841","id":125007048,"number":841,"title":"some thoughts around logging","user":{"login":"emdete","id":3251523,"avatar_url":"https://avatars.githubusercontent.com/u/3251523?v=3","gravatar_id":"","url":"https://api.github.com/users/emdete","html_url":"https://github.com/emdete","followers_url":"https://api.github.com/users/emdete/followers","following_url":"https://api.github.com/users/emdete/following{/other_user}","gists_url":"https://api.github.com/users/emdete/gists{/gist_id}","starred_url":"https://api.github.com/users/emdete/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/emdete/subscriptions","organizations_url":"https://api.github.com/users/emdete/orgs","repos_url":"https://api.github.com/users/emdete/repos","events_url":"https://api.github.com/users/emdete/events{/privacy}","received_events_url":"https://api.github.com/users/emdete/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":9,"created_at":"2016-01-05T17:00:55Z","updated_at":"2016-01-08T16:27:53Z","closed_at":"2016-01-06T22:57:45Z","body":" - the logline should not be formatted like in\r\n\r\n```python\r\n self.qtile.log.info(\"Unknown window property: %s\" % name)\r\n```\r\n\r\n instead it is much better to write\r\n\r\n```python\r\nself.qtile.log.info(\"Unknown window property: %s\", name)\r\n```\r\n and leave formatting up to the logging library (it will decide if that level will be logged at all before it does the formatting and save resources).\r\n\r\n - i would use loggers per module instead of a single logger for all, each module should contain a\r\n\r\n```python\r\nfrom logging import getLogger\r\nlogger = getLogger(__name__)\r\n```\r\n\r\n which makes clear where the logline comes from (and the linenumbers are usefull now).\r\n\r\n - the config should set the level on the root logger, currently this:\r\n\r\n```python\r\nlog = getLogger(logger)\r\nlog.setLevel(log_level)\r\n```\r\n\r\nonly sets it for the logger `logger` (if foreign modules would use logging this would get lost). this would be better:\r\n\r\n```python\r\nlog = getLogger()\r\nlog.setLevel(log_level)\r\n```\r\n\r\n - i would not doublicate logging into file + stdout but switch by config to either way\r\n\r\n - color logging should be optional dis/enabled by config\r\n\r\n - the log member of qtile should be removed or deprecated\r\n"},"comment":{"url":"https://api.github.com/repos/qtile/qtile/issues/comments/170047458","html_url":"https://github.com/qtile/qtile/issues/841#issuecomment-170047458","issue_url":"https://api.github.com/repos/qtile/qtile/issues/841","id":170047458,"user":{"login":"flacjacket","id":681093,"avatar_url":"https://avatars.githubusercontent.com/u/681093?v=3","gravatar_id":"","url":"https://api.github.com/users/flacjacket","html_url":"https://github.com/flacjacket","followers_url":"https://api.github.com/users/flacjacket/followers","following_url":"https://api.github.com/users/flacjacket/following{/other_user}","gists_url":"https://api.github.com/users/flacjacket/gists{/gist_id}","starred_url":"https://api.github.com/users/flacjacket/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/flacjacket/subscriptions","organizations_url":"https://api.github.com/users/flacjacket/orgs","repos_url":"https://api.github.com/users/flacjacket/repos","events_url":"https://api.github.com/users/flacjacket/events{/privacy}","received_events_url":"https://api.github.com/users/flacjacket/received_events","type":"User","site_admin":false},"created_at":"2016-01-08T16:27:53Z","updated_at":"2016-01-08T16:27:53Z","body":"You're right that the line number is already in the log, I'd thought the reason we wanted to do `logger = getLogger(__name__)` was to get the module path in the log through the logger name, but looking at the logging attributes [1], we can get the file name from `$(filename)s` in our Formatter string.\r\n\r\nI do like getting rid of the `self.qtile.log` to do logging, tho from this discussion using either `from libqtile.log import logger; logger.info()` or `import logging; logging.info()` are probably the better options.\r\n\r\n[1] https://docs.python.org/2/library/logging.html#logrecord-attributes"}}