python-coloredlogs icon indicating copy to clipboard operation
python-coloredlogs copied to clipboard

Logging to files doesn't function the same with coloredlogs installed

Open Winning117 opened this issue 6 years ago • 0 comments

With the following settings in my log_config.json I am able to log DEBUG to console and DEBUG to a file (without coloredlogs installed).

  "version": 1,
  "disable_existing_loggers": true,
  "formatters": {
    "standard": {
      "class": "logging.Formatter",
      "format": "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
    }
  },
  "handlers": {
    "console": {
      "class": "logging.StreamHandler",
      "formatter": "standard",
      "level": "DEBUG", # <---- Normally this setting is what decides the log level of your console (i.e. setting to DEBUG will show debug info in console). With coloredlogs it doesn't
      "stream": "ext://sys.stdout"
    },
    "timed_rotating_file_handler": {
      "class": "logging.handlers.TimedRotatingFileHandler",
      "encoding": "utf-8",
      "filename": "logs/MacEnvironmentSetup.log",
      "when": "midnight",
      "interval": 1,
      "backupCount": 2,
      "formatter": "standard",
      "level": "DEBUG"
    }
  },
  "loggers": {},
  "root": {
    "handlers": [
      "console",
      "timed_rotating_file_handler"
    ],
    "level": "DEBUG"
  }
}

If I use the same settings with coloredlogs installed, it will no longer direct DEBUG to the console. DEBUG now only shows up in the log file. This is the only line of code that I added in order to enable coloredlogs (aside from importing it): coloredlogs.install(milliseconds=True)

Is this a bug with coloredlogs, or is there a special way to set it up so that it can debug to the console as well? Thanks

Winning117 avatar Jul 05 '19 19:07 Winning117