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 node_modules
.idea .idea
/config/sequelizeCliConfig.js
/config/testingConfig.js

View file

@ -1,24 +1,3 @@
const logLevel = 'debug'; // options: silly, debug, verbose, info module.exports = {
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');
}; };

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: { analytics: {
googleId: 'UA-60403362-6', // google id for analytics tracking; leave `null` if not applicable 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: { session: {
sessionKey: 'nans$#kfjanwe234rydns', // enter a secret key to be used for session encryption 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; const winstonSlackWebHook = require('winston-slack-webhook').SlackWebHook;
module.exports = (winston) => { module.exports = (winston, slackConfig) => {
const {slackWebHook, slackErrorChannel, slackInfoChannel} = slackConfig;
if (slackWebHook) { if (slackWebHook) {
// add a transport for errors to slack // add a transport for errors to slack
if (slackErrorChannel) { 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 // logging dependencies
const logger = require('winston'); const logger = require('winston');
function SpeechServer (config) { function SpeechServer ({mysqlConfig, siteConfig, slackConfig, lbrynetConfig}) {
this.mysqlConfig = config.mysql; this.mysqlConfig = mysqlConfig;
this.siteConfig = config.siteConfig; this.siteConfig = siteConfig;
this.lbrynetConfig = config.lbrynetConfig; this.slackConfig = slackConfig;
this.db = require('./models')(config.mysqlConfig); this.lbrynetConfig = lbrynetConfig;
this.db = require('./models')(mysqlConfig);
this.PORT = 3000; this.PORT = 3000;
this.speak = (something) => { this.speak = (something) => {
console.log(something); console.log(something);
@ -26,8 +27,8 @@ function SpeechServer (config) {
this.startServer(); this.startServer();
}; };
this.configureLogging = () => { this.configureLogging = () => {
require('./config/loggerConfig.js')(logger); require('./helpers/configureLogger.js')(logger);
require('./config/slackConfig.js')(logger); require('./helpers/configureSlack.js')(logger, this.slackConfig);
}; };
this.configureApp = () => { this.configureApp = () => {
const app = express(); // create an Express application const app = express(); // create an Express application

View file

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

View file

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