reorganized logger config
This commit is contained in:
parent
662e468df6
commit
746ca8c527
13 changed files with 72 additions and 53 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1,2 +1,4 @@
|
|||
node_modules
|
||||
.idea
|
||||
/config/sequelizeCliConfig.js
|
||||
/config/testingConfig.js
|
||||
|
|
|
@ -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
|
||||
};
|
||||
|
|
23
config/sequelizeCliConfig.example.js
Normal file
23
config/sequelizeCliConfig.example.js
Normal 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',
|
||||
},
|
||||
};
|
|
@ -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
|
||||
},
|
||||
|
|
24
helpers/configureLogger.js
Normal file
24
helpers/configureLogger.js
Normal 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');
|
||||
};
|
|
@ -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) {
|
2
index.js
2
index.js
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
15
server.js
15
server.js
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue