Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Programming \ Usage logs Python library     - JavaScript file loader LABjs API Explanation (Programming)

- Run Windows in FreeBSD bhyve (Linux)

- httpd-2.4 feature (Server)

- Android custom title bar (Programming)

- APR for Tomcat installation under Linux (Server)

- To install the Contiki development toolchain on Ubuntu (Linux)

- Linux user management (Linux)

- Nmcli based network management command-line tool (Linux)

- Examples of Exploration Class File (Programming)

- How do you temporarily emptied Bash environment variable before running the command on Linux (Linux)

- GROUP BY extension (Database)

- How to Install SeaMonkey 2.25 for Ubuntu (Linux)

- Using nmcli commands to manage network in RedHat / CentOS 7.x (Linux)

- sed command (Linux)

- Linux with Windows Explorer as a security system (Linux)

- Zabbix monitors Nginx status (Server)

- Management Linux Container with Docker in Ubuntu (Linux)

- MySQL various log summary (Database)

- Using the Android interface in Parcelable (Programming)

- Logging information through the web GUI (LogAnalyzer) (Server)

 
         
  Usage logs Python library
     
  Add Date : 2018-11-21      
         
         
         
  Regardless of the log for the development or operation and maintenance is a very important thing, it can be used for debugging, troubleshooting and statistical analysis.

This article describes the use of python log library.

Log database: import logging

Use logs need to define the following things:

1. Obtain log name, such as

logging.getLogger (__ name__)

2. Define Handler, such as

logging.FileHandler ( '/ var / log / messages')

3. Set the level, such as

fh.setLevel (logging.DEBUG)

4. Define the format, such as

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

5. Print logs, such as

LOG.error ( "python logging test !!")

Here are a script is used to output logs to / var / log / messages and terminals.

import logging

LOG = logging.getLogger (__ name__)

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

fh = logging.FileHandler ( '/ var / log / messages')

fh.setLevel (logging.DEBUG)

fh.setFormatter (formatter)

LOG.addHandler (fh)

ch = logging.StreamHandler ()

ch.setLevel (logging.ERROR)

ch.setFormatter (formatter)

LOG.addHandler (ch)

LOG.error ( "python logging test !!")


Run, you'll find the / var / log / messages and the screen will have a similar "2015-06-28 07: 41: 41,527 - test - ERROR - python logging test !!".

This is the basic usage log, the future will introduce the use of more complex points.
     
         
         
         
  More:      
 
- High-performance JavaScript reflows and repaints (Programming)
- Denyhosts prevent hackers using SSH scanning (Linux)
- Analysis of C ++ exception mechanism (Programming)
- 10 Codes of good practice PHP (Programming)
- The script Linux command (Linux)
- AngularJS - Custom instructions (Programming)
- IronPython and C # to interact (Programming)
- Close common port to protect server security (Linux)
- Python script running in the background (Programming)
- Java code JIT compiler-friendly Mody (Programming)
- Ubuntu 14.04 install the NVIDIA driver + CUDA + MATLAB (Linux)
- Five kinds of IO Model under Linux (Programming)
- Linux POST fstab configuration file read-only variable can not be modified problem (Linux)
- CentOS installation pycurl (Linux)
- Use the dd command to the hard disk I / O performance test (Linux)
- Oracle Database asynchronous IO cause slow query response (Database)
- PostgreSQL query lock and kill the process (Database)
- Eclipse Android development environment installation (Linux)
- DB2 manually create a library (Database)
- Copy files between two Linux hosts (Linux)
     
           
     
  CopyRight 2002-2020 newfreesoft.com, All Rights Reserved.