admin管理员组文章数量:1278789
I'm very new to backend web dev and I'm trying to set up a TypeScript project. Most everything else seems fine but when I try to use the Pino
logger, I get this error in the piled levels.js
file:
throw Error(`default level:${defaultLevel} must be included in custom levels`)
My logger.ts
looks like this:
1 import pino from 'pino';
2
3 const l = pino({
4 name: process.env.APP_ID,
5 level: process.env.LOG_LEVEL,
6 });
7
8 export default l;
The project was bootstrapped via yeoman
.
Not sure if that's enough to debug the issue.
I'm very new to backend web dev and I'm trying to set up a TypeScript project. Most everything else seems fine but when I try to use the Pino
logger, I get this error in the piled levels.js
file:
throw Error(`default level:${defaultLevel} must be included in custom levels`)
My logger.ts
looks like this:
1 import pino from 'pino';
2
3 const l = pino({
4 name: process.env.APP_ID,
5 level: process.env.LOG_LEVEL,
6 });
7
8 export default l;
The project was bootstrapped via yeoman
.
Not sure if that's enough to debug the issue.
Share Improve this question asked Nov 6, 2018 at 0:03 DSchanaDSchana 1,0384 gold badges14 silver badges30 bronze badges 4-
What is
process.env.LOG_LEVEL
set to? – schu34 Commented Nov 6, 2018 at 0:14 - It's undefined. Which is probably the issue but this was all set up through yeoman, I assumed the base app would be functional. – DSchana Commented Nov 6, 2018 at 0:34
-
Not sure, I've never used yeoman before, though if it's
undefined
it should just use the default value which isinfo
so that's probably not the issue. Explicitly settingundefined
in an object is the same as just not including a key. – schu34 Commented Nov 6, 2018 at 0:37 - Ok. So if I hardcode the APP_ID and LOG_LEVEL to the app name and "debug" respectively. That works. Also if I set up a fresh project with yeoman, it works right away. This current project was pulled from a git repo so I guess it put those variable values in some other location or something. – DSchana Commented Nov 6, 2018 at 0:50
2 Answers
Reset to default 7I feel dumb. The issue was that the generator didn't create a .env
; where all those variables should have been defined.
In my case I set incorrect value for LOG_LEVEL:
LOG_LEVEL=error # error | debug | info
as a result pino.level === 'error # error | debug | info'
So to solve the issue just set up correct values, for my case:
LOG_LEVEL=error
本文标签: javascriptPino default level undefinedStack Overflow
版权声明:本文标题:javascript - Pino: default level undefined - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741250355a2365675.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论