Python Forum
how to create my own custom logging message
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to create my own custom logging message
#1
Hi All,

Could any one please let me know, how to create my own custom logging.

For example below:

2020-05-15 11:55:17,823: [action_done] Python is simply awesome

here -- 2020-05-15-15 11:55:17,823 = %(asctime)s
Python is simply awesome = %(message)s
[action_done] = ?

So I wanted to add this custom message '[action_done]' to each log print while logging. And it should be able to do it in all the method of that corresponding class.

Can any one suggest. Thanks in advance.

Regards,
Maiya
Reply
#2
You just pass a regular string to the formatter. But it will parse out your (usually old-style) format variables. Just put in anything else you want though.

import logging

logging.basicConfig(
        format='%(asctime)s: [action_done] %(message)s',
        level=logging.DEBUG
        )
logging.debug("Mymessage")
Output:
2020-05-15 22:18:37,347: [action_done] Mymessage
Reply
#3
Thanks sir

How to add multiple levels into it, and it should print both the levels.
For example:
logging.debug('my message')
logging.info('simply awesome')

Cool, I got it. Thanks
Reply
#4
Hi Sir,

How can I provide the file size limit and it should start write into a new log file once it reaches the file limit.
Thanks a lot.

Regards,
Maiya
Reply
#5
Hi All,
any help regarding this, much appreciated. Thanks a lot.
Regards,
Maiya
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  I want to create custom charts in Python. js1152410 1 537 Nov-13-2023, 05:45 PM
Last Post: gulshan212
  create new log file on logging? korenron 6 2,281 Mar-22-2022, 07:14 AM
Last Post: korenron
  How to create random hex message korenron 6 2,911 Jan-26-2021, 10:42 AM
Last Post: korenron
  How to create Custom Buttons for 3D Scatter plots in Plotly? yourboyjoe 0 2,136 Jun-01-2020, 10:58 PM
Last Post: yourboyjoe
  Custom logging handler looping continuously linuxaddikt 0 1,789 Mar-12-2020, 06:58 PM
Last Post: linuxaddikt
  Create custom Enumerations killerrex 2 3,017 Apr-28-2018, 09:56 AM
Last Post: killerrex
  code that takes inputs for user name amounts etc and then sends custom message shaumyabrata 5 5,315 Feb-12-2017, 11:37 AM
Last Post: ichabod801

Forum Jump:

User Panel Messages

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