Skip to content
This repository has been archived by the owner on Aug 28, 2021. It is now read-only.

Commit

Permalink
updated winston to 3, and reconfiguring logs + ignoring logs, etc
Browse files Browse the repository at this point in the history
  • Loading branch information
didimitrie committed Nov 21, 2018
1 parent 98cb869 commit 3fbb851
Show file tree
Hide file tree
Showing 6 changed files with 974 additions and 993 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#standard ignores
node_modules/
logs/
*.sublime-project
*.sublime-workspace
npm-debug.log
Expand Down
2 changes: 2 additions & 0 deletions app/ws/ClientStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ module.exports = {

// push to my amazing datastore
this.clients.push( ws )
winston.debug( chalk.green("(add) Clients: " + this.clients.length + ".") )
winston.debug( chalk.blue( `There are now ${this.clients.length} ws clients in ${process.pid}: ${this.clients.map( cl => cl.clientId )}` ) )
},

Expand All @@ -40,6 +41,7 @@ module.exports = {
// cut him out
this.clients.splice( this.clients.indexOf( ws ), 1 )
ws.close()

winston.debug( chalk.bgRed( 'Socket removed', ws.clientId ) )
winston.debug( chalk.blue( `There are now ${this.clients.length} ws clients in ${process.pid}.` ) )
}
Expand Down
38 changes: 38 additions & 0 deletions config/logger.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
'use strict'
const fs = require( 'fs' )
const path = require( 'path' )
const { createLogger, format, transports } = require( 'winston' )
const drf = require( 'winston-daily-rotate-file' )


const env = process.env.NODE_ENV || 'dev'
const logDir = 'logs'

if ( !fs.existsSync( logDir ) ) {
fs.mkdirSync( logDir )
}

const drfTransport = new transports.DailyRotateFile( {
filename: `${logDir}/%DATE%.log`,
datePattern: `YYYY-MM-DD`
} )

const logger = createLogger( {
level: 'debug',
format: format.combine(
format.timestamp( { format: 'YYYY-MM-DD HH:mm:ss' } ),
format.json( )
),
transports: [
new transports.Console( {
level: 'debug',
format: format.combine(
format.colorize( ),
format.timestamp( { format: 'YYYY-MM-DD HH:mm:ss' } ),
format.printf( info => `${info.timestamp} ${info.level}: ${info.message}` ), )
} ),
drfTransport
]
} )

module.exports = logger
Loading

0 comments on commit 3fbb851

Please sign in to comment.