{"action":"created","issue":{"url":"https://api.github.com/repos/getlogbook/logbook/issues/227","repository_url":"https://api.github.com/repos/getlogbook/logbook","labels_url":"https://api.github.com/repos/getlogbook/logbook/issues/227/labels{/name}","comments_url":"https://api.github.com/repos/getlogbook/logbook/issues/227/comments","events_url":"https://api.github.com/repos/getlogbook/logbook/issues/227/events","html_url":"https://github.com/getlogbook/logbook/issues/227","id":182111739,"number":227,"title":"Log level with extra context information where the context affects the log level behaviour","user":{"login":"symbolix","id":474655,"avatar_url":"https://avatars.githubusercontent.com/u/474655?v=3","gravatar_id":"","url":"https://api.github.com/users/symbolix","html_url":"https://github.com/symbolix","followers_url":"https://api.github.com/users/symbolix/followers","following_url":"https://api.github.com/users/symbolix/following{/other_user}","gists_url":"https://api.github.com/users/symbolix/gists{/gist_id}","starred_url":"https://api.github.com/users/symbolix/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/symbolix/subscriptions","organizations_url":"https://api.github.com/users/symbolix/orgs","repos_url":"https://api.github.com/users/symbolix/repos","events_url":"https://api.github.com/users/symbolix/events{/privacy}","received_events_url":"https://api.github.com/users/symbolix/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2016-10-10T20:49:04Z","updated_at":"2016-10-14T14:34:00Z","closed_at":null,"body":"Hi,\r\n\r\nThank you very much for logbook. I am curious about a specific user case and would like to know if that is possible with logbook.\r\n\r\nI would like to set-up a custom log level that besides displaying some contextual information also is controlled by that very same contextual information. Let me sum this up in an example.\r\n\r\nHere is a function that is being logger:\r\n\r\n```python\r\ndef test_condition_info():\r\n    my_log.event('Limit event has occured.', current_size=11,size_limit=9)\r\n```\r\n\r\nand the output is:\r\n\r\n`[2016-10-08 10:07:29,807] <__main__> {myApp:test_condition_info:93} (EVENT) Limit event has occurred. >> {\"current_size\":11, \"size_limit\":9}`\r\n\r\nand the reason we see this message is not only because the level is set to `logging.EVENT` but also because of a pre-defined logic `if current_size > size_limit: register the message`.\r\n\r\nIn a similar fashion a call like this one:\r\n\r\n```python\r\nmy_log.event('Limit event has occurred.', current_size=5, size_limit=9)\r\n```\r\n\r\nwill result with the message being NOT displayed even the log level is set to EVENT, since the `if current_size > size_limit: register the message` is not met.\r\n\r\nI know that this can be handled within the function with an `if block`, however, my case is slightly more complex and this is what I need to achieve.\r\n\r\nIs this kind of a customisation possible with logbook? Thanks."},"comment":{"url":"https://api.github.com/repos/getlogbook/logbook/issues/comments/253817530","html_url":"https://github.com/getlogbook/logbook/issues/227#issuecomment-253817530","issue_url":"https://api.github.com/repos/getlogbook/logbook/issues/227","id":253817530,"user":{"login":"symbolix","id":474655,"avatar_url":"https://avatars.githubusercontent.com/u/474655?v=3","gravatar_id":"","url":"https://api.github.com/users/symbolix","html_url":"https://github.com/symbolix","followers_url":"https://api.github.com/users/symbolix/followers","following_url":"https://api.github.com/users/symbolix/following{/other_user}","gists_url":"https://api.github.com/users/symbolix/gists{/gist_id}","starred_url":"https://api.github.com/users/symbolix/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/symbolix/subscriptions","organizations_url":"https://api.github.com/users/symbolix/orgs","repos_url":"https://api.github.com/users/symbolix/repos","events_url":"https://api.github.com/users/symbolix/events{/privacy}","received_events_url":"https://api.github.com/users/symbolix/received_events","type":"User","site_admin":false},"created_at":"2016-10-14T14:34:00Z","updated_at":"2016-10-14T14:34:00Z","body":"Thanks for adding the example. It might be close to what I am trying to achieve. I have included a test case that describes what I am trying to achieve:\r\n\r\nI would like to extend the existing logging.LEVEL mechanics so that I have the option of switching between different logging levels such as DEBUG, INFO, ERROR etc. (which is a standard feature) but also define a depth for each of the levels.\r\n\r\nFor example, let's assume that the logging level is set to logging.DEBUG. All of the logbook.DEBUG() calls will be visible as expected.\r\n\r\n```python\r\nlogbook.debug('Limit event has occurred.')\r\n```\r\n\r\nSo I get:\r\n\r\n```\r\n[2016-10-08 10:07:29,807] <__main__> {myApp:test_condition_info:93} (DEBUG) Limit event has occurred.\r\n```\r\n\r\nWhat I am after, is passing an extra depth level to the `logbook.debug()` call so that I can control how much of detail is printed in the DEBUG message, not entirely enabling or disabling the DEBUG level but controlling how much information the debug message will carry. So in all cases we see the debug message but in some instances, it is less detailed and on some occasions more information is included.\r\n\r\nFor example:\r\n\r\n```python\r\nlogbook.debug('Limit event has occurred.', verbosity=1)\r\nlogbook.debug('The following user has caused the limit event: %s' % (user), verbosity=3)\r\nlogbook.debug('The following files have been affected: %s' % [list_of_files], verbosity=7)\r\n```\r\n\r\nSo when the logging level is set to DEBUG and the global verbosity is set to `GLOBAL_VERBOSITY=1` we will get this:\r\n\r\n```\r\n[2016-10-08 10:07:29,807] <__main__> {myApp:test_condition_info:93} (DEBUG) Limit event has occurred.\r\n```\r\n\r\nAnd if the global verbosity is set to `GLOBAL_VERBOSITY=4` we will get this:\r\n\r\n```\r\n[2016-10-08 10:07:29,807] <__main__> {myApp:test_condition_info:93} (DEBUG) Limit event has occurred.\r\n[2016-10-08 10:07:29,807] <__main__> {myApp:test_condition_info:93} (DEBUG) The following user has caused the limit event: xpr\r\n```\r\n\r\nAnd if the global verbosity is set to `GLOBAL_VERBOSITY=9` we will get all of the details:\r\n\r\n```\r\n[2016-10-08 10:07:29,807] <__main__> {myApp:test_condition_info:93} (DEBUG) Limit event has occurred.\r\n[2016-10-08 10:07:29,807] <__main__> {myApp:test_condition_info:93} (DEBUG) The following user has caused the limit event: xpr\r\n[2016-10-08 10:07:29,807] <__main__> {myApp:test_condition_info:93} (DEBUG) The following files have been affected: ['inside.ini', 'render.so']\r\n```\r\n\r\nI am not sure if this is possible with **logbook** out of the box or do I need to create some customisation. Thank you very much."}}
{"actor":{"display_login":"symbolix"}}