This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// run npm i -D @types/winston | |
// run npm i winston | |
import {Logger, transports} from 'winston'; | |
// run npm i winston-loggly-bulk | |
require('winston-loggly-bulk'); | |
const logger = new Logger({ | |
transports: [ | |
new transports.Console(), | |
new transports.Loggly({ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require('express'); | |
const morgan = require('morgan'); | |
const MorganLogglyLoggerStream = require('./morgan-loggly'); | |
const app = express(); | |
const logglyStream = new MorganLogglyLoggerStream( | |
{ | |
TOKEN: 'YOUR TOKEN', | |
SUBDOMAIN: 'YOUR SUBDOMAIN' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const {Writable} = require('stream'); | |
const loggly = require('node-loggly-bulk'); | |
class MorganLogglyLoggerStream extends Writable { | |
/** | |
* Create a new instance of MorganLogglyLogger | |
* @param options {Object} | |
* @param options.TOKEN {String} your loggly token | |
* @param options.SUBDOMAIN {String} your loggly SUBDOMAIN | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require('express'); | |
const morgan = require('morgan'); | |
const app = express(); | |
// use combined preset, see https://github.com/expressjs/morgan#combined | |
app.use(morgan('combined')); | |
app.get('/', (req, res) => { | |
res.send('Hello from Express.js server!') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// log is also a previously defined variable (logger) and we use shorthand syntax in constructor to | |
const devLogger = new DevelopmentLogger({ log }); | |
devLogger.logIt("Problem with MySQL server."); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DevelopmentLogger { | |
constructor(options) { | |
this.log = options.log.child({environment: 'development'}); | |
} | |
logIt(message) { | |
this.log.info(message) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let compoundObject = { | |
name: { | |
first: 'Matthew', | |
last: 'Setter' | |
}, | |
occupation: 'Freelance Developer & Technical Writer' | |
}; | |
// log the object | |
log.info(compoundObject); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const bunyan = require('bunyan'); | |
const Bunyan2Loggly = require('bunyan-loggly'); | |
const log = bunyan.createLogger({ | |
name: 'logglylog', | |
streams: [ | |
{ | |
type: 'raw', | |
stream: new Bunyan2Loggly({ | |
token: 'YOUR_TOKEN', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const bunyan = require('bunyan'); | |
const Bunyan2Loggly = require('bunyan-loggly'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const production = winston.loggers.get('production'); | |
production.info('logging from your IoC container-based logger'); | |
const development = winston.loggers.get('development'); | |
development.debug('logging from your IoC container-based logger - development'); |