Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Could someone share an example of using memory transport and ways to listen to it? #809

Closed
mrgoos opened this issue Feb 16, 2016 · 4 comments
Labels

Comments

@mrgoos
Copy link

mrgoos commented Feb 16, 2016

When I use Console transport, I know that I can add a listener like this:
logger.on('logging', (transport, level, msg, meta) => use the logged data....

But how can I log to memory and listen to it?
I'm basically looking for a solution to listen to logs without having them written in the console/file/sent over HTTP.

Cheers.

@indexzero
Copy link
Member

For winston@3 users: winston.transports.Memory has been removed – use winston.transports.Stream instead with any buffered stream implementation.

Historically from a winston < 3 perspective winston.transports.Memory was used for unit testing purposes. It was removed in winston@3 since streams are capable of handling back pressure. Please consider upgrading & thanks for using winston!

@lonix1
Copy link

lonix1 commented Apr 8, 2019

Hi the original question is still valid though - is there an example?

We also want to do this, to be able to perform logging to memory during testing.

@DVMVCGCG
Copy link

DVMVCGCG commented Mar 13, 2020

@lonix1 @indexzero something like this should work:

import { Writable } from 'stream';

let output = ''
const stream = new Writable()
stream._write = (chunk, encoding, next) => {
     output = output += chunk.toString()
     next()
}

const streamTransport = new winston.transports.Stream({ stream })
const logger = winston.createLogger({ transports: [streamTransport]})
logger.info('test message')
const logEvents = output.trim().split('\n')
assert(logEvents[0].includes('test message'))

@DannyHinshaw
Copy link

I don't suppose this could work with IE11, could it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants