{"action":"created","issue":{"url":"https://api.github.com/repos/slog-rs/slog/issues/163","repository_url":"https://api.github.com/repos/slog-rs/slog","labels_url":"https://api.github.com/repos/slog-rs/slog/issues/163/labels{/name}","comments_url":"https://api.github.com/repos/slog-rs/slog/issues/163/comments","events_url":"https://api.github.com/repos/slog-rs/slog/issues/163/events","html_url":"https://github.com/slog-rs/slog/pull/163","id":307901916,"number":163,"title":"Add a Drain::is_enabled method to check if a message should be logged.","user":{"login":"Techcable","id":4615889,"avatar_url":"https://avatars2.githubusercontent.com/u/4615889?v=4","gravatar_id":"","url":"https://api.github.com/users/Techcable","html_url":"https://github.com/Techcable","followers_url":"https://api.github.com/users/Techcable/followers","following_url":"https://api.github.com/users/Techcable/following{/other_user}","gists_url":"https://api.github.com/users/Techcable/gists{/gist_id}","starred_url":"https://api.github.com/users/Techcable/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Techcable/subscriptions","organizations_url":"https://api.github.com/users/Techcable/orgs","repos_url":"https://api.github.com/users/Techcable/repos","events_url":"https://api.github.com/users/Techcable/events{/privacy}","received_events_url":"https://api.github.com/users/Techcable/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-03-23T04:50:50Z","updated_at":"2018-03-23T22:05:43Z","closed_at":null,"author_association":"NONE","pull_request":{"url":"https://api.github.com/repos/slog-rs/slog/pulls/163","html_url":"https://github.com/slog-rs/slog/pull/163","diff_url":"https://github.com/slog-rs/slog/pull/163.diff","patch_url":"https://github.com/slog-rs/slog/pull/163.patch"},"body":"This can be used to avoid expensive computation of log message arguments\r\nif the message would be ignored anyway.\r\nThis is added as a condition in the `log!` macro,\r\nin order to avoid unnecessarily computing the arguments when the level is disabled.\r\n\r\nThis is the (somewhat nicer) slog alternative to `log` crate's `log_enabled!` macro.\r\nI've taken the liberty of bumping the version so you can hopefully push a new release ;)"},"comment":{"url":"https://api.github.com/repos/slog-rs/slog/issues/comments/375810747","html_url":"https://github.com/slog-rs/slog/pull/163#issuecomment-375810747","issue_url":"https://api.github.com/repos/slog-rs/slog/issues/163","id":375810747,"user":{"login":"Techcable","id":4615889,"avatar_url":"https://avatars2.githubusercontent.com/u/4615889?v=4","gravatar_id":"","url":"https://api.github.com/users/Techcable","html_url":"https://github.com/Techcable","followers_url":"https://api.github.com/users/Techcable/followers","following_url":"https://api.github.com/users/Techcable/following{/other_user}","gists_url":"https://api.github.com/users/Techcable/gists{/gist_id}","starred_url":"https://api.github.com/users/Techcable/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Techcable/subscriptions","organizations_url":"https://api.github.com/users/Techcable/orgs","repos_url":"https://api.github.com/users/Techcable/repos","events_url":"https://api.github.com/users/Techcable/events{/privacy}","received_events_url":"https://api.github.com/users/Techcable/received_events","type":"User","site_admin":false},"created_at":"2018-03-23T22:05:43Z","updated_at":"2018-03-23T22:05:43Z","author_association":"NONE","body":"Although it has been over two years, I was encouraged by your comments on this issue in #88 .\r\nThis is _not a global level_ whatsoever as I think that would be somewhat against the goals of this crate. The level is local to each `Drain` allowing each Drain to decide whether or not a given log level is enabled,\r\nThis design allows very nice composition alongside APIs like `FilterLevel`.\r\nIn order to avoid breaking backward compatibility, there is a default implementation on the `Drain` trait that checks against the static level.\r\nHowever, all builtin `Drain` implementations override the `is_enabled` method to either delegate or return more correct results (for example `Discard` unconditionally returns false and `FilterLevel` checks against its level).\r\n\r\nThis API is not only for somewhat easier migration from the log crate but can also allow for more elegant logging code.\r\nI have something along the lines of this in the main interpreter loop for my VM,\r\nwhich is somewhat difficult to express without this API.\r\n````\r\nif self.logger.trace_enabled() && config.trace_instructions() {\r\n     match instruction.decode() {\r\n           Instruction::Pop => trace!(self.logger, \"Popped\"; \"result\" => ?result),\r\n           Instruction::Push => trace!(self.logger, \"Pushed\"; \"pushed\" => ?stack.peek()),\r\n           _ => trace!(self.logger, \"Interpreted\"; \"instruction\" => ?instruction.decode(), \"result\" => ?result)\r\n     }\r\n}\r\n````"}}
{"actor":{"display_login":"Techcable"}}