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

Django integration

Open jjlorenzo opened this issue 8 years ago • 4 comments

It is possible to completely integrate this wonderful package with django?

I'm using this, but I've to change the fmt because the hostname for example doesn't get injected.

LOGGING = {
  "version": 1,
  "disable_existing_loggers": False,
  "formatters": {
    "coloredlogs": {
      "()": "coloredlogs.ColoredFormatter",
      "fmt": "[%(asctime)s] %(name)s %(levelname)s %(message)s",
    },
  },
  "handlers": {
    "console": {
      "class": "logging.StreamHandler",
      "level": LOGGING_LEVEL,
      "formatter": "coloredlogs",
    },
  },
  "loggers": {
    "": {
      "handlers": [
        "console",
      ],
      "level": LOGGING_LEVEL,
    },
  },
}

jjlorenzo avatar Aug 18 '17 00:08 jjlorenzo

I was able to add the hostname filter, but yet I don't know how to integrate the verboselogs package

LOGGING = {
  "version": 1,
  "disable_existing_loggers": False,
  "formatters": {
    "coloredlogs": {
      "()": "coloredlogs.ColoredFormatter",
      "fmt": "[%(asctime)s] %(hostname)s %(name)s %(levelname)s %(message)s",
    },
  },
  "handlers": {
    "console": {
      "class": "logging.StreamHandler",
      "level": LOGGING_LEVEL,
      "formatter": "coloredlogs",
      "filters": [
        "hostname",
      ],
    },
  },
  "filters": {
    "hostname": {
      "()": "coloredlogs.HostNameFilter",
    },
  },
  "loggers": {
    "": {
      "handlers": [
        "console",
      ],
      "level": LOGGING_LEVEL,
    },
    "botocore": {
      "handlers": ["console"],
      "level": "WARNING",
    },
    "boto3": {
      "handlers": ["console"],
      "level": "WARNING",
    },
  },
}

jjlorenzo avatar Aug 18 '17 01:08 jjlorenzo

@jjlorenzo were you able to solve this eventually? would be great if you shared your solution. I still can't seem to get the hostname filter working.

epicwhale avatar Jan 05 '18 05:01 epicwhale

Unfortunately I change this and I'm not using anymore, but for what I remember, my previous message include my working solution for django logging config using the hostname filter.

jjlorenzo avatar Jan 05 '18 05:01 jjlorenzo

@jjlorenzo thanks, got it working... a mishap on my end. that solution still works.

epicwhale avatar Jan 05 '18 06:01 epicwhale