Refactor logging

This commit is contained in:
Calvin Montgomery 2017-04-04 23:02:31 -07:00
parent b1a328d2e0
commit 8306d2d1b6
29 changed files with 268 additions and 194 deletions

View file

@ -14,6 +14,9 @@ var Server = require("../server");
var session = require("../session");
var csrf = require("./csrf");
const url = require("url");
import { LoggerFactory } from '@calzoneman/jsli';
const LOGGER = LoggerFactory.getLogger('database/accounts');
/**
* Handles a GET request for /account/edit
@ -581,7 +584,7 @@ function handlePasswordReset(req, res) {
Config.get("mail.nodemailer").sendMail(mail, function (err, response) {
if (err) {
Logger.errlog.log("mail fail: " + err);
LOGGER.error("mail fail: " + err);
sendPug(res, "account-passwordreset", {
reset: false,
resetEmail: email,

View file

@ -7,7 +7,6 @@
var pug = require("pug");
var path = require("path");
var webserver = require("./webserver");
var cookieall = webserver.cookieall;
var sendPug = require("./pug").sendPug;
var Logger = require("../logger");
var $util = require("../utilities");
@ -16,6 +15,9 @@ var Config = require("../config");
var url = require("url");
var session = require("../session");
var csrf = require("./csrf");
import { LoggerFactory } from '@calzoneman/jsli';
const LOGGER = LoggerFactory.getLogger('web/auth');
/**
* Processes a login request. Sets a cookie upon successful authentication
@ -37,7 +39,7 @@ function handleLogin(req, res) {
var host = req.hostname;
if (host.indexOf(Config.get("http.root-domain")) === -1 &&
Config.get("http.alt-domains").indexOf(host) === -1) {
Logger.syslog.log("WARNING: Attempted login from non-approved domain " + host);
LOGGER.warn("Attempted login from non-approved domain " + host);
return res.sendStatus(403);
}

View file

@ -1,7 +1,8 @@
import Config from '../../config';
import CyTubeUtil from '../../utilities';
import Logger from '../../logger';
import * as HTTPStatus from '../httpstatus';
import { LoggerFactory } from '@calzoneman/jsli';
const LOGGER = LoggerFactory.getLogger('web/routes/socketconfig');
export default function initialize(app, clusterClient) {
app.get('/socketconfig/:channel.json', (req, res) => {
@ -14,7 +15,7 @@ export default function initialize(app, clusterClient) {
clusterClient.getSocketConfig(req.params.channel).then(config => {
res.json(config);
}).catch(err => {
Logger.errlog.log(err.stack);
LOGGER.error(err.stack);
return res.status(500).json({
error: err.message
});

View file

@ -1,9 +1,7 @@
import fs from 'fs';
import path from 'path';
import net from 'net';
import express from 'express';
import { sendPug } from './pug';
import Logger from '../logger';
import Config from '../config';
import bodyParser from 'body-parser';
import cookieParser from 'cookie-parser';
@ -13,6 +11,9 @@ import csrf from './csrf';
import * as HTTPStatus from './httpstatus';
import { CSRFError, HTTPError } from '../errors';
import counters from "../counters";
import { LoggerFactory } from '@calzoneman/jsli';
const LOGGER = LoggerFactory.getLogger('webserver');
function initializeLog(app) {
const logFormat = ':real-address - :remote-user [:date] ":method :url HTTP/:http-version" :status :res[content-length] ":referrer" ":user-agent"';
@ -111,7 +112,7 @@ function initializeErrorHandlers(app) {
// Log 5xx (server) errors
if (Math.floor(status / 100) === 5) {
Logger.errlog.log(err.stack);
LOGGER.error(err.stack);
}
res.status(status);
@ -141,7 +142,7 @@ module.exports = {
limit: '1kb' // No POST data should ever exceed this size under normal usage
}));
if (webConfig.getCookieSecret() === 'change-me') {
Logger.errlog.log('WARNING: The configured cookie secret was left as the ' +
LOGGER.warn('The configured cookie secret was left as the ' +
'default of "change-me".');
}
app.use(cookieParser(webConfig.getCookieSecret()));
@ -154,7 +155,7 @@ module.exports = {
app.use(require('compression')({
threshold: webConfig.getGzipThreshold()
}));
Logger.syslog.log('Enabled gzip compression');
LOGGER.info('Enabled gzip compression');
}
if (webConfig.getEnableMinification()) {
@ -172,7 +173,7 @@ module.exports = {
app.use(require('express-minify')({
cache: cacheDir
}));
Logger.syslog.log('Enabled express-minify for CSS and JS');
LOGGER.info('Enabled express-minify for CSS and JS');
}
require('./routes/channel')(app, ioConfig);