Skip to content

Commit

Permalink
feat: New logs implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexGue committed Jun 11, 2021
1 parent 3219d16 commit 3624262
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 100 deletions.
7 changes: 4 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
'use strict';

const governify = require('governify-commons');
const logger = governify.getLogger().tag('initialization');

const server = require('./server');

const env = process.env.NODE_ENV ? process.env.NODE_ENV : 'production';

governify.init().then((commonsMiddleware) => {
server.deploy(env, commonsMiddleware).catch(err => { console.log(err); });
server.deploy(env, commonsMiddleware).catch(err => { logger.error(err); });
});

// quit on ctrl-c when running docker in terminal
process.on('SIGINT', function onSigint () {
console.log('Got SIGINT (aka ctrl-c in docker). Graceful shutdown ', new Date().toISOString());
logger.info('Got SIGINT (aka ctrl-c in docker). Graceful shutdown ', new Date().toISOString());
shutdown();
});

// quit properly on docker stop
process.on('SIGTERM', function onSigterm () {
console.log('Got SIGTERM (docker container stop). Graceful shutdown ', new Date().toISOString());
logger.info('Got SIGTERM (docker container stop). Graceful shutdown ', new Date().toISOString());
shutdown();
});

Expand Down
134 changes: 127 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"compression": "^1.7.2",
"cors": "^2.8.4",
"express": "^4.16.3",
"governify-commons": "1.x",
"governify-commons": "^1.9.7",
"helmet": "^3.23.3",
"js-yaml": "^3.14.0",
"mustache": "^4.0.1",
Expand All @@ -51,4 +51,4 @@
"docker": {
"url": "https://hub.docker.com/r/governify/render"
}
}
}
15 changes: 8 additions & 7 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */

'use strict';

/*
* Put here your dependencies
*/



function check (name, pass, config) {
const nameOK = config.auth.user;
const passOK = config.auth.password;
Expand All @@ -32,7 +32,7 @@ function check (name, pass, config) {
return valid;
}

const deploy = (env, commonsMiddleware) => {
const deploy = (env, commonsMiddleware, callback) => {
return new Promise((resolve, reject) => {
try {
const bodyParser = require('body-parser');
Expand All @@ -42,12 +42,13 @@ const deploy = (env, commonsMiddleware) => {
const compression = require('compression');
const basicAuth = require('basic-auth');
const path = require('path');

const governify = require('governify-commons');
const logger = governify.getLogger().tag('initialization');
const config = require('./src/backend/configurations');
const logger = require('./src/backend/logger');


const app = express();
app.use("/commons", commonsMiddleware);
app.use(commonsMiddleware);

if (config.server.enableHTTPBasicAuth) {
logger.info("Adding 'WWW-Authenticate:' header to every path. Check config/env for getting user and pass");
Expand Down
78 changes: 0 additions & 78 deletions src/backend/logger/index.js

This file was deleted.

6 changes: 3 additions & 3 deletions src/backend/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ mustache.escape = function (text) { return text; };
const governify = require('governify-commons');

const config = require('./configurations');
const logger = require('./logger');
const logger = governify.getLogger().tag("routes")

module.exports = router;

Expand Down Expand Up @@ -81,7 +81,7 @@ router.get('/render', async function (req, res) {
var view = req.query.view;

if (!ctrl || !view || !model) {
logger.warning('No params');
logger.warn('No params');
res.sendStatus(404);
} else {
var files;
Expand All @@ -97,7 +97,7 @@ router.get('/render', async function (req, res) {
var htmlRendered = mustache.render(htmlTemplate, files, {}, ['$_[', ']']);
res.send(htmlRendered);
} catch (err) {
logger.warning('Error getting files: ' + err);
logger.warn('Error getting files: ' + err);
res.status(404).send('404 Not found - ' + err.message);
}
}
Expand Down

0 comments on commit 3624262

Please sign in to comment.