Serverless cleanup
A plugin for the Serverless Framework.
It does what the name says (and more): cleans up logs from your JS code when you deploy your services.
I created it to remove logs after the compile step of the serverless-plugin-typescript It also works nice with the serverless-offline plugin.
How it works
You define your build folder and the log levels to be be removed. The log level can be defined in the logs section of the logRemover custom settings but you can also define a regex (extending it to basically remove whatever matches the regex).
Than you need to define on what stages to remove the logs (probably you need your debug logs for debug, so maybe remove them only on prod stage (--stage prod
when you run sls deploy
), and safely keep the "log" log level)
Now each time you run sls deploy --stage prod
or sls deploy --stage staging
, the debug logs will be removed and the rest of the logs (like log and info) will be kept.
Features
- remove logs like "debug", "log", "error"
- remove comments: single line and multi line
- remove any result of the given regex pattern
Install
npm i serverless-cleanup
Version 0.2.0
Added the concept of jobs, now you can define many different jobs to work on different folders, see example.
Add the plugin to the plugins section of your serverless.yml
plugins:
- serverless-plugin-typescript
- serverless-offline
- serverless-cleanup
Example:
custom:
cleanup:
currentStage: ${opt:stage, 'dev'}
jobs:
- dir: ./.build
logs:
- debug
comments: true
tidyup: true
patterns:
- console.error\(.*\);?
stages:
- prod
- staging
- dir: ./node_modules
logs:
- debug
- log
- info
stages:
- dev
- qa
- staging
- prod
Copyright
Distributed under European Union Public License, version 1.2 (EUPL-1.2)