{"action":"created","issue":{"url":"https://api.github.com/repos/mcollina/pino/issues/36","repository_url":"https://api.github.com/repos/mcollina/pino","labels_url":"https://api.github.com/repos/mcollina/pino/issues/36/labels{/name}","comments_url":"https://api.github.com/repos/mcollina/pino/issues/36/comments","events_url":"https://api.github.com/repos/mcollina/pino/issues/36/events","html_url":"https://github.com/mcollina/pino/issues/36","id":152532406,"number":36,"title":"Provide a way to access the loglevel as a number.","user":{"login":"satazor","id":1017236,"avatar_url":"https://avatars.githubusercontent.com/u/1017236?v=3","gravatar_id":"","url":"https://api.github.com/users/satazor","html_url":"https://github.com/satazor","followers_url":"https://api.github.com/users/satazor/followers","following_url":"https://api.github.com/users/satazor/following{/other_user}","gists_url":"https://api.github.com/users/satazor/gists{/gist_id}","starred_url":"https://api.github.com/users/satazor/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/satazor/subscriptions","organizations_url":"https://api.github.com/users/satazor/orgs","repos_url":"https://api.github.com/users/satazor/repos","events_url":"https://api.github.com/users/satazor/events{/privacy}","received_events_url":"https://api.github.com/users/satazor/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2016-05-02T11:02:10Z","updated_at":"2016-05-02T12:32:26Z","closed_at":null,"body":"I have some piece of code that I want only to be run if the log level is >= info. This might be akward at first but consider that I want to log the progress of some huge task that requires looking some stuff into the DB and possibly other sources:\r\n\r\n```js\r\n\r\nfunction statProgress(npmNano, npmsNano) {\r\n    // Do nothing if loglevel is gte than info\r\n   // TODO: this won't work, pino doesn't supply getting the log level as number\r\n    if (log.levels[log.level] < log.level.stat) {\r\n        return;\r\n    }\r\n\r\n    const blacklistCount = Object.keys(config.blacklist).length;\r\n    let pending = false;\r\n\r\n    setInterval(() => {\r\n        if (pending) {\r\n            log.info('Progress stat is still being retrieved..');\r\n            return;\r\n        }\r\n\r\n        pending = true;\r\n\r\n        Promise.props({\r\n            npmDocsCount: npmNano.infoAsync().then((res) => res.doc_count - blacklistCount),\r\n            npmDesignDocsCount: npmNano.listAsync({ startkey: '_design/', endkey: '_design0' }).then((res) => res.rows.length),\r\n            npmsModulesCount: npmsNano.viewAsync('npms-analyzer', 'modules-evaluation', { reduce: true }).then((res) => res.rows[0].value),\r\n        })\r\n        .finally(() => { pending = false; })\r\n        .then((result) => {\r\n            const analysis = `${(result.npmsModulesCount / (result.npmDocsCount - result.npmDesignDocsCount) * 100).toFixed(4)}%`;\r\n\r\n            log.info({ analysis }, 'Progress stat');\r\n        }, (err) => {\r\n            log.error({ err }, 'Progress stat failed');\r\n        })\r\n        .done();\r\n    }, 15000)\r\n    .unref();\r\n}\r\n```\r\n\r\nObviously I don't want to be querying the DB if the loglevel is >= info. I know I can compare with strings, but I have to do 3 comparisons and is not \"future\" proof.\r\n"},"comment":{"url":"https://api.github.com/repos/mcollina/pino/issues/comments/216223578","html_url":"https://github.com/mcollina/pino/issues/36#issuecomment-216223578","issue_url":"https://api.github.com/repos/mcollina/pino/issues/36","id":216223578,"user":{"login":"jsumners","id":321201,"avatar_url":"https://avatars.githubusercontent.com/u/321201?v=3","gravatar_id":"","url":"https://api.github.com/users/jsumners","html_url":"https://github.com/jsumners","followers_url":"https://api.github.com/users/jsumners/followers","following_url":"https://api.github.com/users/jsumners/following{/other_user}","gists_url":"https://api.github.com/users/jsumners/gists{/gist_id}","starred_url":"https://api.github.com/users/jsumners/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jsumners/subscriptions","organizations_url":"https://api.github.com/users/jsumners/orgs","repos_url":"https://api.github.com/users/jsumners/repos","events_url":"https://api.github.com/users/jsumners/events{/privacy}","received_events_url":"https://api.github.com/users/jsumners/received_events","type":"User","site_admin":false},"created_at":"2016-05-02T12:32:26Z","updated_at":"2016-05-02T12:32:26Z","body":"The `Pino` prototype already has a private-by-convention `_getLevel`. Why not just make it public?"}}