TomFrost / Bristol

Insanely configurable logging for Node.js
MIT License
113 stars 19 forks source link

Can't omit the file path altogether #53

Open dandv opened 6 years ago

dandv commented 6 years ago

For certain messages, it's not interesting where they originate from (file:line). One example would be startup messages:

logger.info("We're up and running");  // the filepath:line is not interesting

Fortunately, though this is undocumented, .addTransform also receives the file:line as an object. I've tried adding a transform to suppress the line, but if it returns the empty string, the file:line is still output:

import logger from 'bristol';
logger.addTarget('console').withFormatter('human');

logger.addTransform(e => e.file && e.line ? '' : e);

logger.info('Started!');  // [2018-07-12 16:19:36] INFO: Started (file:///...:6)

Returning a whitespace is better, though because the file:path object is the first passed on to transform functions, this will lead to an extra whitespace in the middle of your output:

logger.addTransform(e => e.file && e.line ? ' ' : e);

logger.info('Note double space');  // [2018-07-12 16:28:35] INFO:   Note double space
dandv commented 5 years ago

@MarkHerhold: does Palin supports hiding the source of the message for individual log calls, rather than for all of them?

MarkHerhold commented 5 years ago

@dandv It does not - just all of them.

However, I would like to point out that if you specify your project's root folder option with palin, the paths become very short which may be sufficient for you.