question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ANSI Color Codes being logged to log files

See original GitHub issue

Track of old issues: https://github.com/winstonjs/winston/issues/5 https://github.com/Marak/colors.js/issues/4

I’m still having this issue with exceptions and if I log an Error Object. On other logs it does not occur.

Code

inspect = require('eyespect').inspector({maxLength: null})
chalk = require('chalk')

winston = require('winston')
mkdirp = require('mkdirp')
require('winston-mongodb').MongoDB

envrionment = require('../config/config.js')()

socketIoMessenger = require('../socket-io/socket-io-messenger.js')
environment = require('../config/config.js')()

logger = null
io = null
lastMessage = null

exports.launchLogger = (db)->
  mkdirp('logs', (err) ->
    console.log err if err?
  )

  winston.emitErrs = true
  logger = new winston.Logger({
    transports: [
      new winston.transports.MongoDB({
          level: 'info'
          db : db,
          collection: 'serverlogs'
          handleExceptions: false
          colorize: false
          timestamp: true
        }),
      new winston.transports.Console({
        level: 'info'
        handleExceptions: false
        json: false
        colorize: true
      })
    ],
    exitOnError: false
  })
  winston.level = 'error'
  winston.handleExceptions(new winston.transports.File({ filename: 'logs/uncaughtExceptions.log', colorize: false })) if envrionment != 'development'

  winston.exitOnError = false

  logger.stream = {
    write: (message, encoding) ->
      logger.info(message)
  }

  logger.on('logging', (transport, level, message, meta) ->
    # console.log "[#{message}] and [#{JSON.stringify(meta)}] have now been logged at [#{level}] to [#{transport}]"
    if io != null && message != lastMessage && level == 'info'
      lastMessage = message
      socketIoMessenger.sendLog(io, {'message':message, 'level':level, 'meta':meta})
  )

  logger.setIo = (newIo) ->
    console.log "setIO"
    io = newIo

  return logger

exports.getLogger = ()->
  return logger

Error (meta)

{"stack":" \u001b[0m\u001b[97m\u001b[41mInternalOAuthError\u001b[0m\u001b[90m:\u001b[0m\u001b[37m \u001b[0m\u001b[97m<!DOCTYPE html> \u001b[0m\n\u001b[0m \u001b[0m\u001b[97m<html> \u001b[0m\n\u001b[0m \u001b[0m\u001b[97m <head> \u001b[0m\n\u001b[0m \u001b[0m\u001b[97m <title>Die Ressource kann nicht gefunden werden.</title> \u001b[0m\n\u001b[0m \u001b[0m\u001b[97m <meta name=\"viewport\" content=\"width=device-width\" /> \u001b[0m\n\u001b[0m \u001b[0m\u001b[97m <style> \u001b[0m\n\u001b[0m \u001b[0m\u001b[97m body {font-family:\"Verdana\";font-weight:normal;font-size: .7em;color:\u001b[0m \u001b[0m\u001b[97mblack;} \u001b[0m\n\u001b[0m \u001b[0m\u001b[97m p {font-family:\"Verdana\";font-weight:normal;color:black;margin-top: -\u001b[0m \u001b[0m\u001b[97m5px} \u001b[0m\n\u001b[0m \u001b[0m\u001b[97m b {font-family:\"Verdana\";font-weight:bold;color:black;margin-top: -5p\u001b[0m \u001b[0m\u001b[97mx} \u001b[0m\n\u001b[0m \u001b[0m\u001b[97m H1 { font-family:\"Verdana\";font-weight:normal;font-size:18pt;color:re\u001b[0m \u001b[0m\u001b[97md } \u001b[0m\n\u001b[0m \u001b[0m\u001b[97m H2 { font-family:\"Verdana\";font-weight:normal;font-size:14pt;color:ma\u001b[0m \u001b[0m\u001b[97mroon } \u001b[0m\n\u001b[0m \u001b[0m\u001b[97m pre {font-family:\"Consolas\",\"Lucida Console\",Monospace;font-size:11pt\u001b[0m \u001b[0m\u001b[97m;margin:0;padding:0.5em;line-height:14pt} \u001b[0m\n\u001b[0m \u001b[0m\u001b[97m .marker {font-weight: bold; color: black;text-decoration: none;} \u001b[0m\n\u001b[0m \u001b[0m\u001b[97m .version {color: gray;} \u001b[0m\n\u001b[0m \u001b[0m\u001b[97m .error {margin-bottom: 10px;} \u001b[0m\n\u001b[0m \u001b[0m\u001b[97m .expandable { text-decoration:underline; font-weight:bold; color:navy\u001b[0m \u001b[0m\u001b[97m; cursor:hand; } \u001b[0m\n\u001b[0m \u001b[0m\u001b[97m @media screen and (max-width: 639px) { \u001b[0m\n\u001b[0m \u001b[0m\u001b[97m pre { width: 440px; overflow: auto; white-space: pre-wrap; word-wrap\u001b[0m \u001b[0m\u001b[97m: break-word; } \u001b[0m\n\u001b[0m \u001b[0m\u001b[97m } \u001b[0m\n\u001b[0m \u001b[0m\u001b[97m @media screen and (max-width: 479px) { \u001b[0m\n\u001b[0m \u001b[0m\u001b[97m pre { width: 280px; } \u001b[0m\n\u001b[0m \u001b[0m\u001b[97m } \u001b[0m\n\u001b[0m \u001b[0m\u001b[97m </style> \u001b[0m\n\u001b[0m \u001b[0m\u001b[97m </head> \u001b[0m\n\u001b[0m \u001b[0m\n\u001b[0m \u001b[0m\u001b[97m <body bgcolor=\"white\"> \u001b[0m\n\u001b[0m \u001b[0m\n\u001b[0m \u001b[0m\u001b[97m <span><H1>Serverfehler in der Anwendung /.<hr width=100% size=1 co\u001b[0m \u001b[0m\u001b[97mlor=silver></H1> \u001b[0m\n\u001b[0m \u001b[0m\n\u001b[0m \u001b[0m\u001b[97m <h2> <i>Die Ressource kann nicht gefunden werden.</i> </h2></span>\u001b[0m \u001b[0m\n\u001b[0m \u001b[0m\n\u001b[0m \u001b[0m\u001b[97m <font face=\"Arial, Helvetica, Geneva, SunSans-Regular, sans-serif \u001b[0m \u001b[0m\u001b[97m\"> \u001b[0m\n\u001b[0m \u001b[0m\n\u001b[0m \u001b[0m\u001b[97m <b> Beschreibung: </b>HTTP 404. Die gesuchte Ressource oder eine i\u001b[0m \u001b[0m\u001b[97mhrer Abh&#228;ngigkeiten wurde m&#246;glicherweise entfernt, umbenannt oder is\u001b[0m \u001b[0m\u001b[97mt vor&#252;bergehend nicht verf&#252;gbar. &#220;berpr&#252;fen Sie folgende U\u001b[0m \u001b[0m\u001b[97mRL, und stellen Sie sicher, dass sie richtig geschrieben wurde. \u001b[0m\n\u001b[0m \u001b[0m\u001b[97m <br><br> \u001b[0m\n\u001b[0m \u001b[0m\n\u001b[0m \u001b[0m\u001b[97m <b> Angeforderter URL: </b>/oauth/auth_form.aspx<br><br> \u001b[0m\n\u001b[0m \u001b[0m\n\u001b[0m \u001b[0m\u001b[97m </body> \u001b[0m\n\u001b[0m \u001b[0m\u001b[97m</html> \u001b[0m\n\u001b[0m \u001b[0m\u001b[97m)\u001b[0m\n\u001b[0m \u001b[0m\n\u001b[0m \u001b[0m\u001b[90m-\u001b[0m \u001b[0m\u001b[37mFailed to obtain access token (status: 404 data: <!DOCTYPE html>\u001b[0m\n\u001b[0m \u001b[0m\n\u001b[0m \u001b[0m\u001b[90m-\u001b[0m \u001b[0m\u001b[37m<html>\u001b[0m\n\u001b[0m \u001b[0m\n\u001b[0m \u001b[0m\u001b[90m-\u001b[0m \u001b[0m\u001b[37m<head>\u001b[0m\n\u001b[0m \u001b[0m\n\u001b[0m \u001b[0m\u001b[90m-\u001b[0m \u001b[0m\u001b[37m<title>Die Ressource kann nicht gefunden werden.</title>\u001b[0m\n\u001b[0m \u001b[0m\n\u001b[0m \u001b[0m\u001b[90m-\u001b[0m \u001b[0m\u001b[37m<meta name=\"viewport\" content=\"width=device-width\" />\u001b[0m\n\u001b[0m \u001b[0m\n\u001b[0m \u001b[0m\u001b[90m-\u001b[0m \u001b[0m\u001b[37m<style>\u001b[0m\n\u001b[0m \u001b[0m\n\u001b[0m \u001b[0m\u001b[90m-\u001b[0m \u001b[0m\u001b[37mbody {font-family:\"Verdana\";font-weight:normal;font-size: .7em;color:black;}\u001b[0m \u001b[0m\n\u001b[0m \u001b[0m\u001b[90m-\u001b[0m \u001b[0m\u001b[37mp {font-family:\"Verdana\";font-weight:normal;color:black;margin-top: -5px}\u001b[0m\n\u001b[0m \u001b[0m\n\u001b[0m \u001b[0m\u001b[90m-\u001b[0m \u001b[0m\u001b[37mb {font-family:\"Verdana\";font-weight:bold;color:black;margin-top: -5px}\u001b[0m\n\u001b[0m \u001b[0m\n\u001b[0m \u001b[0m\u001b[90m-\u001b[0m \u001b[0m\u001b[37mH1 { font-family:\"Verdana\";font-weight:normal;font-size:18pt;color:red }\u001b[0m\n\u001b[0m \u001b[0m\n\u001b[0m \u001b[0m\u001b[90m-\u001b[0m \u001b[0m\u001b[37mH2 { font-family:\"Verdana\";font-weight:normal;font-size:14pt;color:maroon }\u001b[0m\n\u001b[0m \u001b[0m\n\u001b[0m \u001b[0m\u001b[90m-\u001b[0m \u001b[0m\u001b[37mpre {font-family:\"Consolas\",\"Lucida Console\",Monospace;font-size:11pt;margin\u001b[0m \u001b[0m \u001b[0m\u001b[37m:0;padding:0.5em;line-height:14pt}\u001b[0m\n\u001b[0m \u001b[0m\n\u001b[0m \u001b[0m\u001b[90m-\u001b[0m \u001b[0m\u001b[37m.marker {font-weight: bold; color: black;text-decoration: none;}\u001b[0m\n\u001b[0m \u001b[0m\n\u001b[0m \u001b[0m\u001b[90m-\u001b[0m \u001b[0m\u001b[37m.version {color: gray;}\u001b[0m\n\u001b[0m \u001b[0m\n\u001b[0m \u001b[0m\u001b[90m-\u001b[0m \u001b[0m\u001b[37m.error {margin-bottom: 10px;}\u001b[0m\n\u001b[0m \u001b[0m\n\u001b[0m \u001b[0m\u001b[90m-\u001b[0m \u001b[0m\u001b[37m.expandable { text-decoration:underline; font-weight:bold; color:navy; curso\u001b[0m \u001b[0m \u001b[0m\u001b[37mr:hand; }\u001b[0m\n\u001b[0m \u001b[0m\n\u001b[0m \u001b[0m\u001b[90m-\u001b[0m \u001b[0m\u001b[37m@media screen and (max-width: 639px) {\u001b[0m\n\u001b[0m \u001b[0m\n\u001b[0m \u001b[0m\u001b[90m-\u001b[0m \u001b[0m\u001b[37mpre { width: 440px; overflow: auto; white-space: pre-wrap; word-wrap: break-\u001b[0m \u001b[0m \u001b[0m\u001b[37mword; }\u001b[0m\n\u001b[0m \u001b[0m\n\u001b[0m \u001b[0m\u001b[90m-\u001b[0m \u001b[0m\u001b[37m}\u001b[0m\n\u001b[0m \u001b[0m\n\u001b[0m \u001b[0m\u001b[90m-\u001b[0m \u001b[0m\u001b[37m@media screen and (max-width: 479px) {\u001b[0m\n\u001b[0m \u001b[0m\n\u001b[0m \u001b[0m\u001b[90m-\u001b[0m \u001b[0m\u001b[37mpre { width: 280px; }\u001b[0m\n\u001b[0m \u001b[0m\n\u001b[0m \u001b[0m\u001b[90m-\u001b[0m \u001b[0m\u001b[37m}\u001b[0m\n\u001b[0m \u001b[0m\n\u001b[0m \u001b[0m\u001b[90m-\u001b[0m \u001b[0m\u001b[37m</style>\u001b[0m\n\u001b[0m \u001b[0m\n\u001b[0m \u001b[0m\u001b[90m-\u001b[0m \u001b[0m\u001b[37m</head>\u001b[0m\n\u001b[0m \u001b[0m\n\u001b[0m \u001b[0m\u001b[90m-\u001b[0m \u001b[0m\u001b[37m<body bgcolor=\"white\">\u001b[0m\n\u001b[0m \u001b[0m\n\u001b[0m \u001b[0m\u001b[90m-\u001b[0m \u001b[0m\u001b[37m<span><H1>Serverfehler in der Anwendung /.<hr width=100% size=1 color=silver\u001b[0m \u001b[0m \u001b[0m\u001b[37m></H1>\u001b[0m\n\u001b[0m \u001b[0m\n\u001b[0m \u001b[0m\u001b[90m-\u001b[0m \u001b[0m\u001b[37m<h2> <i>Die Ressource kann nicht gefunden werden.</i> </h2></span>\u001b[0m\n\u001b[0m \u001b[0m\n\u001b[0m \u001b[0m\u001b[90m-\u001b[0m \u001b[0m\u001b[37m<font face=\"Arial, Helvetica, Geneva, SunSans-Regular, sans-serif \">\u001b[0m\n\u001b[0m \u001b[0m\n\u001b[0m \u001b[0m\u001b[90m-\u001b[0m \u001b[0m\u001b[37m<b> Beschreibung: </b>HTTP 404. Die gesuchte Ressource oder eine ihrer Abh&#\u001b[0m \u001b[0m \u001b[0m\u001b[37m228;ngigkeiten wurde m&#246;glicherweise entfernt, umbenannt oder ist vor&#2\u001b[0m \u001b[0m \u001b[0m\u001b[37m52;bergehend nicht verf&#252;gbar. &#220;berpr&#252;fen Sie folgende URL, un\u001b[0m \u001b[0m \u001b[0m\u001b[37md stellen Sie sicher, dass sie richtig geschrieben wurde.\u001b[0m\n\u001b[0m \u001b[0m\n\u001b[0m \u001b[0m\u001b[90m-\u001b[0m \u001b[0m\u001b[37m<br><br>\u001b[0m\n\u001b[0m \u001b[0m\n\u001b[0m \u001b[0m\u001b[90m-\u001b[0m \u001b[0m\u001b[37m<b> Angeforderter URL: </b>/oauth/auth_form.aspx<br><br>\u001b[0m\n\u001b[0m \u001b[0m\n\u001b[0m \u001b[0m\u001b[90m-\u001b[0m \u001b[0m\u001b[37m</body>\u001b[0m\n\u001b[0m \u001b[0m\n\u001b[0m \u001b[0m\u001b[90m-\u001b[0m \u001b[0m\u001b[37m</html>\u001b[0m\n\u001b[0m \u001b[0m\n\u001b[0m \u001b[0m\u001b[90m-\u001b[0m \u001b[0m\u001b[37m)\u001b[0m\n\u001b[0m \u001b[0m\n\u001b[0m \u001b[0m\u001b[90m-\u001b[0m \u001b[0m\u001b[93mstrategy.js\u001b[0m\u001b[90m:\u001b[0m\u001b[93m348\u001b[0m\u001b[37m \u001b[0m\u001b[37mOAuth2Strategy._createOAuthError\u001b[0m\n\u001b[0m \u001b[0m \u001b[0m\u001b[90m[lok]/[passport-oauth2]/lib/strategy.js:348:17\u001b[0m\n\u001b[0m \u001b[0m\n\u001b[0m \u001b[0m\u001b[90m-\u001b[0m \u001b[0m\u001b[93mstrategy.js\u001b[0m\u001b[90m:\u001b[0m\u001b[93m171\u001b[0m\u001b[37m \u001b[0m\n\u001b[0m \u001b[0m \u001b[0m\u001b[90m[lok]/[passport-oauth2]/lib/strategy.js:171:43\u001b[0m\n\u001b[0m \u001b[0m\n\u001b[0m \u001b[0m\u001b[90m-\u001b[0m \u001b[0m\u001b[93moauth2.js\u001b[0m\u001b[90m:\u001b[0m\u001b[93m177\u001b[0m\u001b[37m \u001b[0m\n\u001b[0m \u001b[0m \u001b[0m\u001b[90m[lok]/[oauth]/lib/oauth2.js:177:18\u001b[0m\n\u001b[0m \u001b[0m\n\u001b[0m \u001b[0m\u001b[90m-\u001b[0m \u001b[0m\u001b[93moauth2.js\u001b[0m\u001b[90m:\u001b[0m\u001b[93m123\u001b[0m\u001b[37m \u001b[0m\u001b[37mpassBackControl\u001b[0m\n\u001b[0m \u001b[0m \u001b[0m\u001b[90m[lok]/[oauth]/lib/oauth2.js:123:9\u001b[0m\n\u001b[0m \u001b[0m\n\u001b[0m \u001b[0m\u001b[90m-\u001b[0m \u001b[0m\u001b[93moauth2.js\u001b[0m\u001b[90m:\u001b[0m\u001b[93m143\u001b[0m\u001b[37m \u001b[0m\u001b[37mIncomingMessage.<anonymous>\u001b[0m\n\u001b[0m \u001b[0m \u001b[0m\u001b[90m[lok]/[oauth]/lib/oauth2.js:143:7\u001b[0m\n\u001b[0m \u001b[0m\n\u001b[0m \u001b[0m\u001b[90m-\u001b[0m \u001b[0m\u001b[93mevents.js\u001b[0m\u001b[90m:\u001b[0m\u001b[93m72\u001b[0m\u001b[37m \u001b[0m\u001b[37memitNone\u001b[0m\n\u001b[0m \u001b[0m \u001b[0m\u001b[90mevents.js:72:20\u001b[0m\n\u001b[0m \u001b[0m\n\u001b[0m \u001b[0m\u001b[90m-\u001b[0m \u001b[0m\u001b[93mevents.js\u001b[0m\u001b[90m:\u001b[0m\u001b[93m166\u001b[0m\u001b[37m \u001b[0m\u001b[37mIncomingMessage.emit\u001b[0m\n\u001b[0m \u001b[0m \u001b[0m\u001b[90mevents.js:166:7\u001b[0m\n\u001b[0m \u001b[0m\n\u001b[0m \u001b[0m\u001b[90m-\u001b[0m \u001b[0m\u001b[93m_stream_readable.js\u001b[0m\u001b[90m:\u001b[0m\u001b[93m905\u001b[0m\u001b[37m \u001b[0m\u001b[37mendReadableNT\u001b[0m\n\u001b[0m \u001b[0m \u001b[0m\u001b[90m_stream_readable.js:905:12\u001b[0m\n\u001b[0m \u001b[0m\n\u001b[0m \u001b[0m\u001b[90m-\u001b[0m \u001b[0m\u001b[93mnode.js\u001b[0m\u001b[90m:\u001b[0m\u001b[93m474\u001b[0m\u001b[37m \u001b[0m\u001b[37mnextTickCallbackWith2Args\u001b[0m\n\u001b[0m \u001b[0m \u001b[0m\u001b[90mnode.js:474:9\u001b[0m\n\u001b[0m \u001b[0m\n\u001b[0m \u001b[0m\u001b[90m-\u001b[0m \u001b[0m\u001b[93mnode.js\u001b[0m\u001b[90m:\u001b[0m\u001b[93m429\u001b[0m\u001b[37m \u001b[0m\u001b[37mprocess._tickDomainCallback\u001b[0m\n\u001b[0m \u001b[0m \u001b[0m\u001b[90mnode.js:429:17\u001b[0m\n\u001b[0m \u001b[0m\n\u001b[0m","name":"InternalOAuthError","message":"Failed to obtain access token"}

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
soichihcommented, Apr 26, 2017

I’ve worked around this by using following configuration for winston

            new winston.transports.Console({
                ...
                colorize: process.stdout.isTTY,
            }),

process.stdout.isTTY is set to true only if the stdout is TTY (text terminal) - not pipe.

0reactions
indexzerocommented, Mar 23, 2018

In winston@3.0.0 you can control colorization using built-in or custom formats. Please consider upgrading.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Mangled ANSI Color Codes in Log File - Stack Overflow
I am trying to output logs with colour codes using Logback and SpringBoot . I am sure this has nothing to do with...
Read more >
More colorful logging with ANSI color codes - Papertrail
Papertrail's event viewer now honors ANSI color codes in log messages. Here's an example: image. The light blue and purple colors were ...
Read more >
shell - How to "un-ANSI-fy" logs? - Server Fault
If you know that you will be writing the output to a file, the easiest thing to do (at least for NPM) is...
Read more >
View Your Logs In Colour - Medium
Tada! The log file displays in colour without ANSI escape sequences. We can also take advantage of VS Code's Search and Minimap features....
Read more >
Visualizing ansi color escape codes in log files correctly in ...
Use the emacs library ansi-color.el : M-x load-library ansi-color M-: (ansi-color-apply-on-region (point-min) (point-max)).
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found