reorganized logger config

This commit is contained in:
bill bittner 2018-03-09 11:20:13 -08:00
parent 662e468df6
commit 746ca8c527
13 changed files with 72 additions and 53 deletions

2
.gitignore vendored
View file

@ -1,2 +1,4 @@
node_modules
.idea
/config/sequelizeCliConfig.js
/config/testingConfig.js

View file

@ -1,24 +1,3 @@
const logLevel = 'debug'; // options: silly, debug, verbose, info
module.exports = (winston) => {
// configure
winston.configure({
transports: [
new (winston.transports.Console)({
level : logLevel,
timestamp : false,
colorize : true,
prettyPrint : true,
handleExceptions : true,
humanReadableUnhandledException: true,
}),
],
});
// test all the log levels
winston.error('Level 0');
winston.warn('Level 1');
winston.info('Level 2');
winston.verbose('Level 3');
winston.debug('Level 4');
winston.silly('Level 5');
module.exports = {
logLevel: 'debug', // options: silly, debug, verbose, info
};

View file

@ -0,0 +1,23 @@
module.exports = {
development: {
username: '',
password: '',
database: '',
host : '127.0.0.1',
dialect : 'mysql',
},
test: {
username: '',
password: '',
database: '',
host : '127.0.0.1',
dialect : 'mysql',
},
production: {
username: '',
password: '',
database: '',
host : '127.0.0.1',
dialect : 'mysql',
},
};

View file

@ -2,11 +2,6 @@ module.exports = {
analytics: {
googleId: 'UA-60403362-6', // google id for analytics tracking; leave `null` if not applicable
},
logging: {
slackWebHook : 'https://hooks.slack.com/services/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', // enter a webhook if you wish to push logs to slack; otherwise leave as `null`
slackErrorChannel: null, // enter a slack channel (#example) for errors to be sent to; otherwise leave null
slackInfoChannel : '#speech-dev1-errors', // enter a slack channel (#info) for info level logs to be sent to otherwise leave null
},
session: {
sessionKey: 'nans$#kfjanwe234rydns', // enter a secret key to be used for session encryption
},

View file

@ -0,0 +1,24 @@
const { logLevel } = require('../config/loggerConfig');
module.exports = (winston) => {
// configure
winston.configure({
transports: [
new (winston.transports.Console)({
level : logLevel,
timestamp : false,
colorize : true,
prettyPrint : true,
handleExceptions : true,
humanReadableUnhandledException: true,
}),
],
});
// test all the log levels
winston.error('Level 0');
winston.warn('Level 1');
winston.info('Level 2');
winston.verbose('Level 3');
winston.debug('Level 4');
winston.silly('Level 5');
};

View file

@ -1,8 +1,7 @@
const { logging } = require('./speechConfig.js');
const { slackWebHook, slackErrorChannel, slackInfoChannel } = logging;
const winstonSlackWebHook = require('winston-slack-webhook').SlackWebHook;
module.exports = (winston) => {
module.exports = (winston, slackConfig) => {
const {slackWebHook, slackErrorChannel, slackInfoChannel} = slackConfig;
if (slackWebHook) {
// add a transport for errors to slack
if (slackErrorChannel) {

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -10,11 +10,12 @@ const cookieSession = require('cookie-session');
// logging dependencies
const logger = require('winston');
function SpeechServer (config) {
this.mysqlConfig = config.mysql;
this.siteConfig = config.siteConfig;
this.lbrynetConfig = config.lbrynetConfig;
this.db = require('./models')(config.mysqlConfig);
function SpeechServer ({mysqlConfig, siteConfig, slackConfig, lbrynetConfig}) {
this.mysqlConfig = mysqlConfig;
this.siteConfig = siteConfig;
this.slackConfig = slackConfig;
this.lbrynetConfig = lbrynetConfig;
this.db = require('./models')(mysqlConfig);
this.PORT = 3000;
this.speak = (something) => {
console.log(something);
@ -26,8 +27,8 @@ function SpeechServer (config) {
this.startServer();
};
this.configureLogging = () => {
require('./config/loggerConfig.js')(logger);
require('./config/slackConfig.js')(logger);
require('./helpers/configureLogger.js')(logger);
require('./helpers/configureSlack.js')(logger, this.slackConfig);
};
this.configureApp = () => {
const app = express(); // create an Express application

View file

@ -2,9 +2,7 @@
const logger = require('winston');
const db = require('../models'); // require our models for syncing
// configure logging
const config = require('../config/speechConfig.js');
const { logLevel } = config.logging;
require('../config/loggerConfig.js')(logger, logLevel);
require('../helpers/configureLogger.js')(logger);
let totalClaims = 0;
let totalClaimsNoCertificate = 0;

View file

@ -1,10 +1,8 @@
// load dependencies
const logger = require('winston');
const db = require('../models'); // require our models for syncing
const db = require('../models');
// configure logging
const config = require('../config/speechConfig.js');
const { logLevel } = config.logging;
require('../config/loggerConfig.js')(logger, logLevel);
require('../helpers/configureLogger.js')(logger);
const userName = process.argv[2];
logger.debug('user name:', userName);