Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python logging into two different files

import logging
formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')


def setup_logger(name, log_file, level=logging.INFO):
    """To setup as many loggers as you want"""

    handler = logging.FileHandler(log_file)        
    handler.setFormatter(formatter)

    logger = logging.getLogger(name)
    logger.setLevel(level)
    logger.addHandler(handler)

    return logger

# first file logger
logger = setup_logger('first_logger', 'first_logfile.log')
logger.info('This is just info message')

# second file logger
super_logger = setup_logger('second_logger', 'second_logfile.log')
super_logger.error('This is an error message')

def another_method():
   # using logger defined above also works here
   logger.info('Inside method')
Comment

PREVIOUS NEXT
Code Example
Python :: loss funfction suited for softmax 
Python :: matplotlib boxplot colors 
Python :: how to iterate through ordereddict in python 
Python :: first column of a dataframe python 
Python :: print all unique values in a dictionary 
Python :: flask port 
Python :: save image from jupyter notebook 
Python :: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel(). y = column_or_1d(y, warn=True) 
Python :: discord py edit message 
Python :: python dictionary rename key 
Python :: k choose n python 
Python :: 2d gaussian function python 
Python :: how to get key of a particular value in dictionary python using index 
Python :: strip first occurence of substring python 
Python :: pandas where 
Python :: python remove characters from end of string 
Python :: randint python 
Python :: remove element from list 
Python :: date-fns difference in days 
Python :: know datatype of pandas 
Python :: python define an array of dictonary 
Python :: import get object 
Python :: python move a file from one folder to another 
Python :: how to remove a tuple from a list python 
Python :: python pygame how to start a game 
Python :: 3d array python numpy 
Python :: how to hide tensorflow warnings 
Python :: python 3 f string float format 
Python :: extract integer from a string in pandas 
Python :: python list all methods of a class 
ADD CONTENT
Topic
Content
Source link
Name
7+3 =