Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python logging to file

import logging
import sys

logger = logging.getLogger()
logger.setLevel(logging.INFO)
formatter = logging.Formatter('%(asctime)s | %(levelname)s | %(message)s', 
                              '%m-%d-%Y %H:%M:%S')

stdout_handler = logging.StreamHandler(sys.stdout)
stdout_handler.setLevel(logging.DEBUG)
stdout_handler.setFormatter(formatter)

file_handler = logging.FileHandler('logs.log')
file_handler.setLevel(logging.DEBUG)
file_handler.setFormatter(formatter)

logger.addHandler(file_handler)
logger.addHandler(stdout_handler)
Comment

python log file

import logging
logging.basicConfig(filename='example.log', encoding='utf-8', level=logging.DEBUG)
logging.debug('This message should go to the log file')
logging.info('So should this')
logging.warning('And this, too')
logging.error('And non-ASCII stuff, too, like Øresund and Malmö')
Comment

PREVIOUS NEXT
Code Example
Python :: flask tutorials 
Python :: python code to print prime numbers 
Python :: python create file if doesnt exist 
Python :: python how to print input 
Python :: the list of prime number in a given range python 
Python :: python flatten array of arrays 
Python :: strip all elements in list python 
Python :: remove nans and infs python 
Python :: install tensorflow gpu 
Python :: np.random.normal 
Python :: is python platform independent 
Python :: python count code, Count number of occurrences of a given substring 
Python :: train_test_split sklearn 
Python :: how to add for loop in python 
Python :: django get form data from post 
Python :: python remove items from list containing string 
Python :: Randint Random Library 
Python :: type string python 
Python :: python set day of date to 1 
Python :: fromkeys in python 
Python :: what is wsgi 
Python :: Find Specific value in Column 
Python :: how to load mnist dataset in python 
Python :: delete tuple from list 
Python :: can you release a python program to an exe file 
Python :: python int to binary string 
Python :: what is NoReverseMatch in django? 
Python :: pandas convert column to datetime 
Python :: how to get the ip address of laptop with python 
Python :: how to define function in python 
ADD CONTENT
Topic
Content
Source link
Name
3+1 =