Use logger with Python for the time being

Purpose

Output the log using the logger because anything is fine with Python

Contents

Appearance element

The following three elements are required to output the minimum log

  1. Logger --Component for outputting logs
  2. Handler --Component for setting log output destination etc. --Various handlers are provided by default in logging.Handlers

sample

If you want to output it for the time being, this is spell-like.

Output for the time being


from logging import getLogger, StreamHandler, DEBUG

def main():
    logger = getLogger(__name__) #Get a logger
    handler = StreamHandler() #handler(StreamHandler)Get
    handler.setLevel(DEBUG) #Set the output level of the handler
    logger.setLevel(DEBUG) #Set the output level of the logger
    logger.addHandler(handler) #Add handler to logger
    logger.debug("It's a log ~") #Output log at debug level using logger

if __name__ == '__main__':
    main()

Recommended Posts

Use logger with Python for the time being
Run with CentOS7 + Apache2.4 + Python3.6 for the time being
Python Master RTA for the time being
I played with Floydhub for the time being
See python for the first time
Until you can install blender and run it with python for the time being
Use DeepL with python (for dissertation translation)
MongoDB for the first time in Python
Understanding the python class Struggle (1) Let's move it for the time being
Let's touch Google's Vision API from Python for the time being
For the time being, I want to convert files with ffmpeg !!
Try using FireBase Cloud Firestore in Python for the time being
How to use MkDocs for the first time
[Python] Use JSON with Python
Challenge image classification with TensorFlow2 + Keras CNN 1 ~ Move for the time being ~
[Python] [Machine learning] Beginners without any knowledge try machine learning for the time being
Specify the Python executable to use with virtualenv
For the time being, import them into jupyter
Make a histogram for the time being (matplotlib)
Use mecab with Python3
Run yolov4 "for the time being" on windows
Use DynamoDB with Python
Wrap C with Cython for use from Python
I tried python programming for the first time.
Use Python 3.8 with Anaconda
Try using LINE Notify for the time being
The easiest way to use OpenCV with python
Use python with docker
Wrap C ++ with Cython for use from Python
virtualenv For the time being, this is all!
Turn multiple lists with a for statement at the same time in Python
What I got into Python for the first time
Stop EC2 for specified time + start with Lambda (python)
Flow memo to move LOCUST for the time being
[Python] Measures and displays the time required for processing
Molecular dynamics simulation to try for the time being
I tried python on heroku for the first time
Information for controlling the motor with Python on RaspberryPi
I will install Arch Linux for the time being.
Specify MinGW as the compiler to use with Python
Next to Excel, for the time being, jupyter notebook
Kaggle for the first time (kaggle ①)
Use Twitter API with Python
Use TUN / TAP with Python
Execution time measurement with Python With
Kaguru for the first time
Call the API with python3.
Use subsonic API with python3
Time synchronization (Windows) with Python
I don't know what HEIC is. But for the time being, let's use PNG!
Write this in the ttl file for the time being for automatic SSH login with Teraterm
I was hooked for 2 minutes with the Python debugger pdb
Why can I use the module by importing with python?
[python] How to use the library Matplotlib for drawing graphs
I want to move selenium for the time being [for mac]
I tried running PIFuHD on Windows for the time being
[Understand in the shortest time] Python basics for data analysis
[Python] I want to use the -h option with argparse
Create a Twitter BOT with the GoogleAppEngine SDK for Python
I didn't know how to use the [python] for statement
Tips for Python beginners to use the Scikit-image example for themselves