Skip to content

Commit 3f5f156

Browse files
committed
allows to disable logs
1 parent 9c259fc commit 3f5f156

File tree

4 files changed

+11
-2
lines changed

4 files changed

+11
-2
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ The `/restana-static/config` directory should be populated/overwritten during im
2020
"cacheControlHeaderValue": "public, no-cache, max-age=604800",
2121
"distDirectory": "dist/",
2222
"defaultFile": "index.html",
23+
"logsEnabled": true,
2324
"logsFormat": "tiny"
2425
}
2526
```
@@ -38,6 +39,8 @@ CACHE_CONTROL_HEADER_VALUE
3839
DIST_DIRECTORY
3940
# defaultFile
4041
DEFALUT_FILE
42+
# logsEnabled
43+
LOGS_ENABLED
4144
# logsFormat
4245
LOGS_FORMAT
4346
```

config/default.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@
44
"cacheControlHeaderValue": "public, no-cache, max-age=604800",
55
"distDirectory": "dist/",
66
"defaultFile": "index.html",
7+
"logsEnabled": true,
78
"logsFormat": "tiny"
89
}

server.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ module.exports = () => {
1313
CACHE_ENABLED,
1414
CACHE_CONTROL_HEADER_VALUE,
1515
DEFALUT_FILE,
16-
LOGS_FORMAT
16+
LOGS_FORMAT,
17+
LOGS_ENABLED
1718
} = process.env
1819

1920
const distDirectory = DIST_DIRECTORY || config.get('distDirectory') ||
@@ -25,6 +26,7 @@ module.exports = () => {
2526
'public, no-cache, max-age=604800'
2627
const defaultFile = DEFALUT_FILE || config.get('defaultFile') ||
2728
'index.html'
29+
const logsEnabled = isEnabled(LOGS_ENABLED, 'logsEnabled', config)
2830
const logsFormat = LOGS_FORMAT || config.get('logsFormat') ||
2931
'tiny'
3032

@@ -40,7 +42,9 @@ module.exports = () => {
4042

4143
// server bootstrap
4244
const server = require('restana')({})
43-
server.use(morgan(logsFormat))
45+
if (logsEnabled) {
46+
server.use(morgan(logsFormat))
47+
}
4448
server.use((req, res, next) => {
4549
if (req.url === '/') {
4650
req.url = defaultFile

tests/2.environment-configuration.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ describe('Smoke - Environment based configuration', () => {
1010
it('should successfully start server - env based config', async () => {
1111
process.env.PORT = 5000
1212
process.env.CACHE_ENABLED = false
13+
process.env.LOGS_ENABLED = false
1314

1415
const { server: service, port } = require('../server')()
1516

0 commit comments

Comments
 (0)