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 is info so that's probably not the issue. Explicitly setting undefined 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
Add a ment  | 

2 Answers 2

Reset to default 7

I 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