Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

multiple logger instances populating single log python

import os
import time
import datetime
import logging
class Logger :
    logger = None
    def myLogger(self):
        if None == self.logger:
            self.logger=logging.getLogger('ProvisioningPython')
            self.logger.setLevel(logging.DEBUG)
            now = datetime.datetime.now()
            handler=logging.FileHandler('ProvisioningPython'+ now.strftime("%Y-%m-%d") +'.log')
            formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
            handler.setFormatter(formatter)
            self.logger.addHandler(handler)
        return self.logger

s = Logger()
m = s.myLogger()
m2 = s.myLogger()
m.info("Info1")
m2.info("info2")
Comment

PREVIOUS NEXT
Code Example
Python :: star program in python using for loop 
Python :: django change id to uuid 
Python :: generate barcode using python 
Python :: python re split 
Python :: numeric up down python tkinter 
Python :: plt.semilogx 
Python :: add row to dataframe 
Python :: webpage with aiohttp 
Python :: whitelist the ip address django 
Python :: python list pop 
Python :: fetch image url discord py 
Python :: Merge two Querysets in Python Django while preserving Queryset methods 
Python :: django not migrating 
Python :: change every element of list python with map 
Python :: python type casting 
Python :: plt.scatter background color 
Python :: Convert Int to String Using format() method 
Python :: update django model with dict 
Python :: reshape SAS matrix 
Python :: parse invoice python 
Python :: protected vs private python 
Python :: Time series missing values 
Python :: #index operator in python 
Python :: pop up window flutter 
Python :: phython to c converter 
Python :: draw bipartite graph networkx 
Python :: www.pd.date_range 
Python :: how to remove text from plot in python 
Python :: production mode flask 
Python :: checking length of sets in python 
ADD CONTENT
Topic
Content
Source link
Name
4+5 =