首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往
您找到你想要的搜索结果了吗?
是的
没有找到

python 日志记录

#!/bin/env python #--*-- coding=utf8 --*-- # # Author: ablozhou # E-mail: ablozhou@gmail.com # # Copyright 2010 ablozhou # # Distributed under the terms of the GPL (GNU Public License) # # hzdq is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # # 2010.3.14 写文件,log级别常数定义 import datetime import sys import traceback import codecs import types #log编码全部按utf8处理 loglevels = {'stdout':['info','debug','warn','error','fatal'], 'file':['info','debug','warn','error','fatal'] } logfile = 'logs.txt' class log4py: def __init__(self,modulename='gloabal', loglevel=loglevels, filename='log4py.txt'): self.filename = filename #self.flag = set(loglevel['stdout']+loglevel['file']) self.loglevel = loglevel self.modulename = modulename self.fcname = None class function(): def __init__(self,fcname,parent): parent.debug('enter ',fcname) self.fcname = fcname self.parent = parent def __del__(self): self.parent.debug('exit ',self.fcname) def dbgfc(self,fcname): '''set debug function name''' f = None if 'debug' in self.flag: f = self.function(fcname,self) return f def _gettime(self): return datetime.datetime.now().isoformat() def outstd(self,*fmt): s = self.fmtstr(*fmt) print s def outfile

01

python接口自动化(四十)- logger 日志 - 下(超详解)

按照上一篇的计划,这一篇给小伙伴们讲解一下:(1)多模块使用logging,(2)通过文件配置logging模块,(3)自己封装一个日志(logging)类。可能有的小伙伴在这里会有个疑问一个logging为什么分两篇的篇幅来介绍她呢???那是因为日志是非常重要的,用于记录系统、软件操作事件的记录文件或文件集合,可分为事件日志和消息日志。具有处理历史数据、诊断问题的追踪以及理解系统、软件的活动等重要作用,在开发或者测试软系统过程中出现了问题,我们首先想到的就是她——logging。她可不像泰戈尔说的:“天空没有留下翅膀的痕迹,但我已经飞过”;这个90后的小姑娘,她可是一个爱炫耀,爱显摆的人已经达到了人过留名、雁过留声的境界。好了逗大家一乐,下面开始进入今天的正题。

06

Tomcat日志系统详解

综合:Tomcat下相关的日志文件 Cataline引擎的日志文件,文件名catalina.日期.log Tomcat下内部代码丢出的日志,文件名localhost.日期.log(jsp页面内部错误的异常,org.apache.jasper.runtime.HttpJspBase.service类丢出的,日志信息就在该文件!) Tomcat下默认manager应用日志,文件名manager.日期.log 控制台输出的日志,Linux下默认重定向到catalina.out Access日志(Servlet.xml配置) 应用程序通过log4j.properties:${catalina.base}/logs/probe.log重定向过来的日志 JULI:org.apache.juli.FileHandler对应的日志文件名:{prefix}.{date}.{suffix} 默认juli.日期.log Tomcat下Web应用程序可以使用如下3种日志: 使用JDK提供的日志java.util.logging. 使用Java Servlets规范中定义的日志javax.servlet.ServletContext.log(...) 使用其他日志框架,如log4j 不同Web应用程序下使用的Servlet日志(或者日志框架提供的日志)是相互独立的(这与Tomcat的class loader有关,参考Class Loader HOW-TO )。如果Web应用程序使用的是java.util.logging日志,那么它们并不相互独立,这是因为java.util.logging是由JAVA系统中的Bootstrap ClassLoader来加载的,因此它在各Web应用程序之间是共享的! Tomcat使用的日志配置文件:$CATALINA_BASE/conf/logging.properties Tomcat日志管理类默认使用的是JULI:LOGGING_MANAGER="-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager" Java的stdout and stderr会被重定向到$CATALINA_BASE/logs/catalina.out,同时:下面2种类型的错误信息,也会被记录在这里 Uncaught exceptions printed by java.lang.ThreadGroup.uncaughtException(.. Thread dumps, if you requested them via a system signal Access访问日志:它与一般的日志有关系但不太一样,它在Servlet.xml中的Context或者 Host或者Engine中配置。在上述的配置节中增加下述的Value就行,具体参考:The Valve Component Xml代码 <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="localhost_access_log." suffix=".logs" pattern="common" resolveHosts="false"/> Tomcat默认使用JULI日志系统(可以参考官网文档修改成使用log4j),它是对默认的JDK日志java.util.logging进行一定的封装,和标准JDK日志支持相同的配置。最大的不同是针对不同的classloader,可以使用不同的配置文件,使得tomcat下不同的Web应用程序可以使用各自独立的日志文件。也就是说,Tomcat下的默认日志有如下2个层次: 全局配置文件. That is usually done in the ${catalina.base}/conf/logging.properties file. The file is specified by the java.util.logging.config.file System property which is set by the startup scripts. If it is not readable or is not configured, the default is to use the ${java.home}/lib/logging.properties file in the JRE. Web应用程序中使用WEB-INF/classes/logging.properties 默认的JRE中的logging.properties会

06

扫码

添加站长 进交流群

领取专属 10元无门槛券

手把手带您无忧上云

扫码加入开发者社群

相关资讯

热门标签

活动推荐

    运营活动

    活动名称
    广告关闭
    领券