# How do I get my Lambda function to have a different log level depending on stage?

**URL:** <https://forum.serverless.com/t/how-do-i-get-my-lambda-function-to-have-a-different-log-level-depending-on-stage/17769>\
**Category:** Serverless Framework\
**Tags:** lambda, variables\
**Created:** [October 23, 2022, 9:07pm UTC](https://forum.serverless.com/t/how-do-i-get-my-lambda-function-to-have-a-different-log-level-depending-on-stage/17769 "2022-10-23T21:07:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![morgan-young1](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/morgan-young1/32/6852_2.png) [@morgan-young1](https://forum.serverless.com/u/morgan-young1)\
**Post date:** [October 23, 2022, 9:07pm UTC](https://forum.serverless.com/t/how-do-i-get-my-lambda-function-to-have-a-different-log-level-depending-on-stage/17769/1 "2022-10-23T21:07:04Z")

</div>

I want to have different log levels for the prod and dev env, how can I get it to do this?

I thought of a custom variable in serverless.yml, like loglevel, and then give the different stages various log levels, but then how do I get the code to know which environment it is in?

Any help much appreciated. Thanks

---

<div class="post-metadata">

**Author:** ![markl-vesper](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/markl-vesper/32/2338_2.png) [@markl-vesper](https://forum.serverless.com/u/markl-vesper)\
**Post date:** [October 24, 2022, 7:09pm UTC](https://forum.serverless.com/t/how-do-i-get-my-lambda-function-to-have-a-different-log-level-depending-on-stage/17769/2 "2022-10-24T19:09:50Z")

</div>

use a variable in self.provider.envrironment like

`LOG_LEVEL: ${self:custom.environment.${self:custom.stage}.logging}`

then have the appropriate level for each stage like

```auto
self.custom.environment.dev: debug
self.custom.environment.prod: warn/error (whatever your requirement is)

```

your can then reference it from code via

`process.env.LOG_LEVEL`

we use bole so in the log.js file we have

`bole.output({ level: process.env.LOG_LEVEL, stream })`

You can also define a LOG\_LEVEL at the function level to override the stages settings if you need

Hope this helps
