Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Programming \ Usage logs Python library     - WebLogic administrator account and reset the password (Database)

- Linux user opens a number of adjustment processes (Linux)

- Use Bash script write CVS version control (Server)

- Getting Started with Linux system to learn: how to use tcpdump to capture TCP SYN, ACK and FIN packets (Linux)

- Cobbler Add custom YUM source (Linux)

- Varnish achieve page jump (Server)

- Shell array: Define Shell array, the array length (Programming)

- How to enable fbcon in Debian (Linux)

- MongoDB relations, references, index query coverage (Database)

- CentOS6 5 Configure SSH password Free (Linux)

- Export error: ORA-04063: package body dmsys dbms dm model exp has error (Database)

- Linux system Passwd file detailed analysis (Linux)

- How to install or upgrade to the Linux kernel in Ubuntu 4.2 (Linux)

- Give your photos Instagram style filters plus program in ubuntu (Linux)

- Ubuntu 14.04 and derivative versions of the user install Pantheon Photos 0.1 (Linux)

- Oracle bug Ora-04043 (Database)

- Linux installation Jetty deployment under RedHat5 8 (Linux)

- Struts2 interceptor simulation (Programming)

- Debian 7.8 system installation and configuration process (Linux)

- Linux System Getting Started Tutorial: Installing Git on Linux (Linux)

 
         
  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:      
 
- MongoDB in bulk timestamp change the date format (Database)
- The correct method to modify the maximum number of concurrent connections Tomcat 7 (Server)
- Create a project using Android Studio LinearLayout (Programming)
- JDK installation notes under CentOS (Linux)
- Linux file and directory management - ls, cp, mv (Linux)
- Java concurrent programming using the synchronized keyword ReentrantLock alternative primitive (Programming)
- Ubuntu 14.04 Docker installation (Linux)
- Install RAID 6 (Striping double distributed parity) (Linux)
- Zabbix Agent (Server)
- Android developers learning Adapter (data adapter) (Programming)
- Forgot Linux root password (Linux)
- Ubuntu 14.04 install the NVIDIA driver + CUDA + MATLAB (Linux)
- Linux AS4 VPN server in conjunction with a firewall perfect (Linux)
- Using iptables achieve NAT (Linux)
- Ubuntu Linux use ufw or iptables firewall configuration (Linux)
- 10 Regulation of painless SQL Schema (Database)
- Ubuntu 14.04 LTS compiler installation R Source Code (Linux)
- Five kinds of IO Model under Linux (Programming)
- Ubuntu install code editor Sublime Text 3 (Linux)
- KVM virtualization nested configuration (Server)
     
           
     
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.