Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Configure a logging.config
#1
Hello,

Please, help me update the config file below. I want to set different format for each logging level and set filltering for all handlers.
1) For level = ERROR the format should be
"format": "%(asctime)s - %(name)s - %(funcName)s - %(levelname)s - %(lineno)d - %(message)s"
For level = INFO the format should be
"format": "%(levelname)s - %(message)s"
2) For level = DEBUG set filtering for keywords. I don't want to see all the Debugs events. Only events which meet the filtering condition.

I looked for answers on the internet and didn't find them.


{

  "version": 1,
  "disable_existing_loggers": "False",

  "handlers": {
    "file": {
      "class": "logging.handlers.TimedRotatingFileHandler",
      "formatter": "simple",
      "filename": "logs/myfile.log",
      "when": "D",
      "interval": 1,
      "utc": "True",
      "backupCount": "14"
    },

    "console": {
      "class": "logging.StreamHandler",
      "formatter": "simple"
    },

    "telegram": {
      "class": "telegram_handler.TelegramHandler",
      "token": "myToken",
      "chat_id": "myChatId",
      "formatter": "telegram"
    }

  },

  "formatters": {
    "simple": {
      "format": "%(asctime)s - %(name)s - %(funcName)s - %(levelname)s - %(lineno)d - %(message)s"
    },

    "telegram": {
      "format": "%(levelname)s - %(message)s",
      "class": "telegram_handler.HtmlFormatter"
    }
  },

  "loggers": {
    "root": {
      "handlers": [ "file", "console", "telegram" ],
      "level": "CRITICAL"
    },

    "myModule": {
      "handlers": [ "file", "console", "telegram" ],
      "level": "INFO"
    }
  }
}
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Updating a config file [solved] ebolisa 8 2,531 Nov-04-2021, 10:20 AM
Last Post: Gribouillis
  Is there a library for recursive object creation using config objects johsmi96 0 1,823 May-03-2021, 08:09 PM
Last Post: johsmi96
  help with pytesseract.image_to_string(savedImage, config='--psm 11')iamge to string korenron 0 2,648 Apr-29-2021, 10:08 AM
Last Post: korenron
  configure delay on only one link using python3 HiImAl 3 2,666 Oct-21-2020, 07:51 PM
Last Post: buran
  Config file update Olivier74 0 1,451 Aug-18-2020, 03:36 PM
Last Post: Olivier74
  What is the best way to set application-wide config values? ajorona 1 1,856 May-07-2020, 05:03 PM
Last Post: buran
  Config file entry as list versus string? taziuk 2 1,788 Apr-25-2020, 12:01 PM
Last Post: ndc85430
  configure Github with python yellareddy 1 7,666 Apr-20-2020, 05:37 PM
Last Post: buran
  logging: child module unable to get parent config jerryxiao 3 3,305 Apr-09-2019, 04:17 AM
Last Post: jerryxiao
  variables help / update config file mapvis 3 3,331 Nov-27-2018, 02:24 PM
Last Post: mapvis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020