{"action":"created","issue":{"url":"https://api.github.com/repos/benoitc/gunicorn/issues/1187","labels_url":"https://api.github.com/repos/benoitc/gunicorn/issues/1187/labels{/name}","comments_url":"https://api.github.com/repos/benoitc/gunicorn/issues/1187/comments","events_url":"https://api.github.com/repos/benoitc/gunicorn/issues/1187/events","html_url":"https://github.com/benoitc/gunicorn/issues/1187","id":128162698,"number":1187,"title":"Allow statsd and custom logger_class","user":{"login":"bloodearnest","id":1042,"avatar_url":"https://avatars.githubusercontent.com/u/1042?v=3","gravatar_id":"","url":"https://api.github.com/users/bloodearnest","html_url":"https://github.com/bloodearnest","followers_url":"https://api.github.com/users/bloodearnest/followers","following_url":"https://api.github.com/users/bloodearnest/following{/other_user}","gists_url":"https://api.github.com/users/bloodearnest/gists{/gist_id}","starred_url":"https://api.github.com/users/bloodearnest/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bloodearnest/subscriptions","organizations_url":"https://api.github.com/users/bloodearnest/orgs","repos_url":"https://api.github.com/users/bloodearnest/repos","events_url":"https://api.github.com/users/bloodearnest/events{/privacy}","received_events_url":"https://api.github.com/users/bloodearnest/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/benoitc/gunicorn/labels/Feature/Logging","name":"Feature/Logging","color":"d4c5f9"},{"url":"https://api.github.com/repos/benoitc/gunicorn/labels/Feedback%20Requested","name":"Feedback Requested","color":"ffb114"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2016-01-22T14:03:52Z","updated_at":"2016-01-22T14:40:09Z","closed_at":null,"body":"Currently, if you configure statsd_host, you cannot customise the logger_class, gunicorn will just use hardcoded gunicorn.intrument.Statsd class.\r\n\r\nhttps://github.com/benoitc/gunicorn/blob/master/gunicorn/config.py#L150\r\n\r\nThis is not great, as the user's configured logger class is silently swallowed up and not used. \r\n\r\nCould we at least add a warning if the the user has configured logger_class and statsd_host, so at least we know what's happening? :)\r\n\r\nA simple fix would be to always prefer the user configured logger_class? And maybe improve docs to mention the Statsd class in logger_class config?\r\n\r\n \r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/benoitc/gunicorn/issues/comments/173937611","html_url":"https://github.com/benoitc/gunicorn/issues/1187#issuecomment-173937611","issue_url":"https://api.github.com/repos/benoitc/gunicorn/issues/1187","id":173937611,"user":{"login":"bloodearnest","id":1042,"avatar_url":"https://avatars.githubusercontent.com/u/1042?v=3","gravatar_id":"","url":"https://api.github.com/users/bloodearnest","html_url":"https://github.com/bloodearnest","followers_url":"https://api.github.com/users/bloodearnest/followers","following_url":"https://api.github.com/users/bloodearnest/following{/other_user}","gists_url":"https://api.github.com/users/bloodearnest/gists{/gist_id}","starred_url":"https://api.github.com/users/bloodearnest/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bloodearnest/subscriptions","organizations_url":"https://api.github.com/users/bloodearnest/orgs","repos_url":"https://api.github.com/users/bloodearnest/repos","events_url":"https://api.github.com/users/bloodearnest/events{/privacy}","received_events_url":"https://api.github.com/users/bloodearnest/received_events","type":"User","site_admin":false},"created_at":"2016-01-22T14:40:09Z","updated_at":"2016-01-22T14:40:09Z","body":"I mean I want to configure logging_class to use my own implementation[1], but I also want to use the statsd functionality and config.\r\n\r\nI inherited my custom class from gunicorn.instrument.Statsd, but I discovered my class was not being being used when I also configured statsd_host. Works fine if I don't configure statsd_host.\r\n\r\ne.g. (for clarity, apologies if obvious)\r\n\r\n# log output is as I expect\r\ngunicorn app --logger-class='myclass'  \r\n\r\n# log output is default gunicorn, myclass is not being used\r\ngunicorn app --logger-class='myclass'  --statsd_host=localhost:12345\r\n\r\n\r\n\r\nA possible fix (unfinished): \r\n\r\nhttps://github.com/benoitc/gunicorn/pull/1188\r\n\r\nRegards mixing different logging strategy, could we possibly merge the Statsd logger functionality into the base Logger class, this removing this switching logic all together? Some care would need to be taken to avoid a performance hit if statsd is not enabled, but I think that's probably doable.\r\n\r\nI'd be happy to do the work if you think that's worth pursuing.\r\n\r\nThanks (for a prompt response, and for gunicorn in general :)\r\n\r\n\r\n\r\n[1] FWIW, my motivations for providing a custom logger_class implementation are:\r\n\r\na) increase timestamp resolution to include msec on access logs (not possible AFAICS with out overriding Logger.now())\r\n\r\nb) use a custom formatter on the error log, which is currently hardcoded to logging.Formatter(Logger.error_fmt, Logger.datefmt). This to add some structured logging tags, like a request id, if present.\r\n\r\nBoth of these could maybe be addressed by extending the logger class, if you think they're worth doing. Then I wouldn't need a custom Logger implementation at all :)"}}