Logger
This commit is contained in:
6
.gitignore
vendored
6
.gitignore
vendored
@@ -3,4 +3,8 @@ node_modules/
|
||||
.env
|
||||
|
||||
## VSCODE ##
|
||||
.vscode/
|
||||
.vscode/
|
||||
|
||||
## CONFIG ##
|
||||
config/
|
||||
!config/default.yml
|
||||
|
||||
@@ -1,3 +1,8 @@
|
||||
logger:
|
||||
level: 'info'
|
||||
format: '{{timestamp}} [{{title}}] <{{file}}:{{line}}> {{message}}'
|
||||
datetime: 'HH:MM:ss'
|
||||
|
||||
web:
|
||||
host: 127.0.0.1
|
||||
port: 8080
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
"concat-stream": "^1.6.0",
|
||||
"config": "^1.28.1",
|
||||
"express": "^4.16.1",
|
||||
"js-yaml": "^3.10.0"
|
||||
"js-yaml": "^3.10.0",
|
||||
"tracer": "^0.8.11"
|
||||
}
|
||||
}
|
||||
|
||||
24
server.js
24
server.js
@@ -1,9 +1,11 @@
|
||||
/* --- IMPORTS -------------------------- */
|
||||
|
||||
const config = require('config');
|
||||
const tracer = require('tracer');
|
||||
|
||||
const express = require('express');
|
||||
const bodyParser = require('body-parser');
|
||||
const concatStream = require('concat-stream');
|
||||
const config = require('config');
|
||||
|
||||
const fs = require('fs');
|
||||
const os = require('os');
|
||||
@@ -11,6 +13,13 @@ const path = require('path');
|
||||
|
||||
/* --- SETUP ---------------------------- */
|
||||
|
||||
// Logger
|
||||
global.logger = tracer.console({
|
||||
level: config.get('logger.level'),
|
||||
format: config.get('logger.format'),
|
||||
dateformat: config.get('logger.datetime')
|
||||
});
|
||||
|
||||
// Express
|
||||
const app = express();
|
||||
app.use((req, res, next) => {
|
||||
@@ -42,6 +51,11 @@ function toOsPath(urlPath) {
|
||||
|
||||
/* --- ROUTING -------------------------- */
|
||||
|
||||
app.all('*', (req, res, next) => {
|
||||
global.logger.trace('Path: %s | Method: %s', req.originalUrl, req.method);
|
||||
next();
|
||||
});
|
||||
|
||||
app.route(`/${config.get('maven.url')}/*`)
|
||||
.get((req, res) => {
|
||||
let osPath = toOsPath(req.path);
|
||||
@@ -60,7 +74,7 @@ app.route(`/${config.get('maven.url')}/*`)
|
||||
|
||||
fs.writeFile(osPath, req.rawBody, (err) => {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
global.logger.error(err);
|
||||
res.status(500).send();
|
||||
} else {
|
||||
res.status(200).send();
|
||||
@@ -70,5 +84,7 @@ app.route(`/${config.get('maven.url')}/*`)
|
||||
|
||||
/* --- START APP ------------------------ */
|
||||
|
||||
console.info(`Start web server :: ${config.get('web.host')}:${config.get('web.port')}`);
|
||||
app.listen(config.get('web.port'), config.get('web.host'));
|
||||
const host = config.get('web.host'),
|
||||
port = config.get('web.port')
|
||||
global.logger.info('Start server :: %s:%s', host, port);
|
||||
app.listen(port, host);
|
||||
|
||||
20
yarn.lock
20
yarn.lock
@@ -38,6 +38,10 @@ bytes@3.0.0:
|
||||
version "3.0.0"
|
||||
resolved "https://registry.yarnpkg.com/bytes/-/bytes-3.0.0.tgz#d32815404d689699f85a4ea4fa8755dd13a96048"
|
||||
|
||||
colors@1.1.2:
|
||||
version "1.1.2"
|
||||
resolved "https://registry.yarnpkg.com/colors/-/colors-1.1.2.tgz#168a4701756b6a7f51a12ce0c97bfa28c084ed63"
|
||||
|
||||
concat-stream@^1.6.0:
|
||||
version "1.6.0"
|
||||
resolved "https://registry.yarnpkg.com/concat-stream/-/concat-stream-1.6.0.tgz#0aac662fd52be78964d5532f694784e70110acf7"
|
||||
@@ -73,6 +77,10 @@ core-util-is@~1.0.0:
|
||||
version "1.0.2"
|
||||
resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7"
|
||||
|
||||
dateformat@2.0.0:
|
||||
version "2.0.0"
|
||||
resolved "https://registry.yarnpkg.com/dateformat/-/dateformat-2.0.0.tgz#2743e3abb5c3fc2462e527dca445e04e9f4dee17"
|
||||
|
||||
debug@2.6.9:
|
||||
version "2.6.9"
|
||||
resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.9.tgz#5d128515df134ff327e90a4c93f4e077a536341f"
|
||||
@@ -343,6 +351,18 @@ string_decoder@~1.0.3:
|
||||
dependencies:
|
||||
safe-buffer "~5.1.0"
|
||||
|
||||
tinytim@0.1.1:
|
||||
version "0.1.1"
|
||||
resolved "https://registry.yarnpkg.com/tinytim/-/tinytim-0.1.1.tgz#c968a1e5559ad9553224ef7627bab34e3caef8a8"
|
||||
|
||||
tracer@^0.8.11:
|
||||
version "0.8.11"
|
||||
resolved "https://registry.yarnpkg.com/tracer/-/tracer-0.8.11.tgz#5941c67404410d86665b75bba68bb1c9d2c3cacd"
|
||||
dependencies:
|
||||
colors "1.1.2"
|
||||
dateformat "2.0.0"
|
||||
tinytim "0.1.1"
|
||||
|
||||
type-is@~1.6.15:
|
||||
version "1.6.15"
|
||||
resolved "https://registry.yarnpkg.com/type-is/-/type-is-1.6.15.tgz#cab10fb4909e441c82842eafe1ad646c81804410"
|
||||
|
||||
Reference in New Issue
Block a user