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

Logging Objects or Errors is not working #49

Open
Starfox64 opened this issue Apr 22, 2017 · 8 comments
Open

Logging Objects or Errors is not working #49

Starfox64 opened this issue Apr 22, 2017 · 8 comments

Comments

@Starfox64
Copy link

'use strict';

const winston = require('winston');
const Graylog = require('winston-graylog2');

const logger = new winston.Logger({
	level: 'debug',
	transports: [
		new Graylog({
			level: 'debug',
			handleExceptions: true,
			graylog: {
				servers: [{ host: '10.42.221.139', port: 12201 }],
				facility: 'debug-test'
			}
		})
	]
});


logger.info('Text Test');
logger.debug({foo: 'bar'});
logger.error(new Error());
logger.error(new Error('Test Error'));

setTimeout(() => {process.exit(0)}, 1000);

When running the following script, the first test is the only one inserted in Graylog.

Graylog

@odino
Copy link
Contributor

odino commented Apr 22, 2017

Hi @Starfox64 -- can you reliably reproduce the error? Would appreciate a PR if you don't mind :)

@toleabivol
Copy link

I found out I have to do it with 2 parameters in order to get it working:

throw new Error('foo');
...
winston.error(error.toString(), error);

@urbanslug
Copy link
Contributor

urbanslug commented Mar 23, 2018

Logging objects

I'm also facing the same issue when logging objects. In my case the console transport and file transports can both handle a JS object as the message instead of a string. e.g logger.log('info', {message: 'Something', 'other': 'stuff'})

However for winston-graylog2 I have to set prelog: JSON.stringify for it to handle an object as the message but this still loses value of the message key.

So @Starfox64 you could set the option prelog: JSON.stringify but it still won't log anything under the message value.

@urbanslug
Copy link
Contributor

urbanslug commented Mar 27, 2018

Update

It does work but one has to pass an object as an extra argument to the log function e.g logger.log('info', 'the message', {more: 'stuff'}).

However, given that other transports such as console and file still work when the message is in the object; it would be nice if this transport also supported this functionality.

Edit:
What I am referring to is inspired by this series on strucutred logging https://honeycomb.io/blog/categories/logging/

@marjan2k
Copy link

Hello, this issue is still persisting as of 2.1.2.

Since we are relying on multiple transports, its a bit of a hassle to add objects via extra parameter only for graylog.

@canozmen
Copy link

canozmen commented Jan 2, 2020

Hello, this issue is still persisting as of 2.1.2.

Since we are relying on multiple transports, its a bit of a hassle to add objects via extra parameter only for graylog.

Do you have a working config you can share for this. I still can't send separate fields even if I add extra parameters as an object as the last parameter.

I can only log facility, full_message, level, message, source, timestamp fields.

@jeremy-j-ackso
Copy link
Contributor

Folks having these types of issues on more recent releases should check out setting Winston formatters and examples in the end-to-end tests.

@fetnimohamed
Copy link

antone found a solution for this??

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

No branches or pull requests

8 participants