logdown.js icon indicating copy to clipboard operation
logdown.js copied to clipboard

Support for removing color coding

Open Shooshte opened this issue 4 years ago • 1 comments

When writing log files into a .log file escape characters get added before each line. This bloats the log file considerably, and makes it a bit harder to read.

My logger config:

import logdown from 'logdown';
import fs from 'fs';

const output = fs.createWriteStream('./stdout.log');
const errorOutput = fs.createWriteStream('./stderr.log');
const fileLogger = new console.Console(output, errorOutput);

const logger = logdown('API', {
  logger: fileLogger,
  markdown: false,
  plaintext: true
});

logger.state.isEnabled = true;

export default logger;

Usage example and output:

logger.log(`app started on port: ${PORT}`);
[37m [39m  [API] app started on port: 3000

I believe this is due to whitespace and colour coding being added to the passed string (inside the console there is whitespace and the text colour is green). Can support be for the plaintext to remove the formatting or would this be better suited for a plugin?

Shooshte avatar Apr 03 '21 10:04 Shooshte

According to the source code plaintext was implemented to add support for logging to files, but for some reason this option disable only part of colors leaving the another part on:

https://github.com/caiogondim/logdown.js/blob/master/src/node.js#L88-L109

I think it was made mistakingly and _getDecoratedPrefix() should drop emojis from output too.

SleepWalker avatar Apr 03 '21 13:04 SleepWalker