}Zc@s-ddddgZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ej dkZ ej dkZ defdYZdefd YZd efd YZd efd YZdefdYZdefdYZeZdS(t LogTargettFileLogtLoggertlogiNt3cBs5eZdZdZddZdZdZRS(s% Abstract class for logging targets. cCs d|_dS(N(tNonetfd(tself((s8/usr/lib/python2.7/site-packages/firewall/core/logger.pyt__init__*sicCstddS(Ns%LogTarget.write is an abstract method(tNotImplementedError(Rtdatatleveltloggertis_debug((s8/usr/lib/python2.7/site-packages/firewall/core/logger.pytwrite-scCstddS(Ns%LogTarget.flush is an abstract method(R (R((s8/usr/lib/python2.7/site-packages/firewall/core/logger.pytflush0scCstddS(Ns%LogTarget.close is an abstract method(R (R((s8/usr/lib/python2.7/site-packages/firewall/core/logger.pytclose3s(t__name__t __module__t__doc__RRRR(((s8/usr/lib/python2.7/site-packages/firewall/core/logger.pyR(s    t _StdoutLogcBs/eZdZddZdZdZRS(cCstj|tj|_dS(N(RRtsyststdoutR(R((s8/usr/lib/python2.7/site-packages/firewall/core/logger.pyR:s icCs|jj||jdS(N(RRR(RR R R R ((s8/usr/lib/python2.7/site-packages/firewall/core/logger.pyR>scCs|jdS(N(R(R((s8/usr/lib/python2.7/site-packages/firewall/core/logger.pyRCscCs|jjdS(N(RR(R((s8/usr/lib/python2.7/site-packages/firewall/core/logger.pyRFs(RRRRRR(((s8/usr/lib/python2.7/site-packages/firewall/core/logger.pyR9s   t _StderrLogcBseZdZRS(cCstj|tj|_dS(N(RRRtstderrR(R((s8/usr/lib/python2.7/site-packages/firewall/core/logger.pyRMs (RRR(((s8/usr/lib/python2.7/site-packages/firewall/core/logger.pyRLst _SyslogLogcBs/eZdZddZdZdZRS(cCs=tj|tjtjjtjdtj tj dS(Ni( RRtsyslogtopenlogtostpathtbasenameRtargvtLOG_PIDt LOG_DAEMON(R((s8/usr/lib/python2.7/site-packages/firewall/core/logger.pyRUs icCsd}|rtj}nl||jkr3tj}nQ||jkrNtj}n6||jkritj}n||j krtj }n|j dr|t |d }nt |dkr|dkrtj|qtj||ndS(Ns ii( RRt LOG_DEBUGtINFO1tLOG_INFOtWARNINGt LOG_WARNINGtERRORtLOG_ERRtFATALtLOG_CRITtendswithtlen(RR R R R tpriority((s8/usr/lib/python2.7/site-packages/firewall/core/logger.pyRcs"      cCstjdS(N(Rtcloselog(R((s8/usr/lib/python2.7/site-packages/firewall/core/logger.pyRyscCsdS(N((R((s8/usr/lib/python2.7/site-packages/firewall/core/logger.pyR|s(RRRRRR(((s8/usr/lib/python2.7/site-packages/firewall/core/logger.pyRTs   cBsAeZdZddZdZddZdZdZRS(s< FileLog class. File will be opened on the first write. twcCs#tj|||_||_dS(N(RRtfilenametmode(RR0R1((s8/usr/lib/python2.7/site-packages/firewall/core/logger.pyRs  cCsE|jr dSt|j|j|_tj|jtjtjdS(N(RtopenR0R1tfcntltF_SETFDt FD_CLOEXEC(R((s8/usr/lib/python2.7/site-packages/firewall/core/logger.pyR2s icCs7|js|jn|jj||jjdS(N(RR2RR(RR R R R ((s8/usr/lib/python2.7/site-packages/firewall/core/logger.pyRs  cCs'|js dS|jjd|_dS(N(RRR(R((s8/usr/lib/python2.7/site-packages/firewall/core/logger.pyRs  cCs|js dS|jjdS(N(RR(R((s8/usr/lib/python2.7/site-packages/firewall/core/logger.pyRs (RRRRR2RRR(((s8/usr/lib/python2.7/site-packages/firewall/core/logger.pyRs     cBseZdZdZdZdZdZdZdZe Z e Z e Zddd Zd Zd d Zd d Zd dZd dZdZdZdZdZdZdZed2dZed2dZed2dZed2dZed2dZ ed2dZ!dZ"dZ#dZ$dZ%d Z&d!Z'd"Z(d#Z)d$Z*d%Z+d&Z,dd'Z-d(Z.dd)Z/ed2dd*Z0ed2dd+Z1ed2dd,Z2dd-Z3d.Z4d/Z5d0Z6dd1Z7RS(3sL Format string: %(class)s Calling class the function belongs to, else empty %(date)s Date using Logger.date_format, see time module %(domain)s Full Domain: %(module)s.%(class)s.%(function)s %(file)s Filename of the module %(function)s Function name, empty in __main__ %(label)s Label according to log function call from Logger.label %(level)d Internal logging level %(line)d Line number in module %(module)s Module name %(message)s Log message Standard levels: FATAL Fatal error messages ERROR Error messages WARNING Warning messages INFOx, x in [1..5] Information DEBUGy, y in [1..10] Debug messages NO_INFO No info output NO_DEBUG No debug output INFO_MAX Maximum info level DEBUG_MAX Maximum debug level x and y depend on info_max and debug_max from Logger class initialization. See __init__ function. Default logging targets: stdout Logs to stdout stderr Logs to stderr syslog Logs to syslog Additional arguments for logging functions (fatal, error, warning, info and debug): nl Disable newline at the end with nl=0, default is nl=1. fmt Format string for this logging entry, overloads global format string. Example: fmt="%(file)s:%(line)d %(message)s" nofmt Only output message with nofmt=1. The nofmt argument wins over the fmt argument. Example: from logger import log log.setInfoLogLevel(log.INFO1) log.setDebugLogLevel(log.DEBUG1) for i in range(1, log.INFO_MAX+1): log.setInfoLogLabel(i, "INFO%d: " % i) log.setFormat("%(date)s %(module)s:%(line)d [%(domain)s] %(label)s: " "%(level)d %(message)s") log.setDateFormat("%Y-%m-%d %H:%M:%S") fl = FileLog("/tmp/log", "a") log.addInfoLogging("*", fl) log.addDebugLogging("*", fl) log.addInfoLogging("*", log.syslog, fmt="%(label)s%(message)s") log.debug3("debug3") log.debug2("debug2") log.debug1("debug1") log.info2("info2") log.info1("info1") log.warning("warning\n", nl=0) log.error("error\n", nl=0) log.fatal("fatal") log.info(log.INFO1, "nofmt info", nofmt=1) iiiiiiii cCsi|_i|_d|_d|_i|_i|_i|_i|_i|_i|_ |dkryt d|n|dkrt d|n|j |_ ||_ d|_||_|j|jd|j|jd|j|jd|j|j dxbtd|j dD]J}t|d |||j|dt|d |d ||q"Wxftd|jdD]N}t|d |||j|d |t|d|d||qW|j|j|j|j|jd|jd|jd|j|j|j|j g|jd|jgt|j|j dD] }|^qd|jd|jgtd|jdD] }|^qdS(s Logger class initialization tisLogger: info_max %d is too lowisLogger: debug_max %d is too lows FATAL ERROR: sERROR: s WARNING: sINFO%dsinfo%dcsfdS(Ncsj|||S(N(tinfo(tmessagetargstkwargs(Rtx(s8/usr/lib/python2.7/site-packages/firewall/core/logger.pyts((RR;((RR;s8/usr/lib/python2.7/site-packages/firewall/core/logger.pyR<ssDEBUG%ds DEBUG%d: sdebug%dcsfdS(Ncsj|||S(N(tdebug(R8R9R:(RR;(s8/usr/lib/python2.7/site-packages/firewall/core/logger.pyR<$s((RR;((RR;s8/usr/lib/python2.7/site-packages/firewall/core/logger.pyR<#ss%(label)s%(message)ss%d %b %Y %H:%M:%St*N( t_levelt _debug_levelt_formatt _date_formatt_labelt _debug_labelt_loggingt_debug_loggingt_domainst_debug_domainst ValueErrorR%tNO_INFOtINFO_MAXtNO_DEBUGt DEBUG_MAXtsetInfoLogLabelR)t TRACEBACKR'trangetsetattrtsetDebugLogLabeltsetInfoLogLevelR#tsetDebugLogLevelt setFormatt setDateFormattsetInfoLoggingRRtsetDebugLogging(Rtinfo_maxt debug_maxR?ti((s8/usr/lib/python2.7/site-packages/firewall/core/logger.pyRsX                     -cCshxat|j|jdD]F}||jkr5qnx(|j|D]\}}}|jqCWqWdS(s Close all logging targets iN(RPR)RMRER(RR tdummyttarget((s8/usr/lib/python2.7/site-packages/firewall/core/logger.pyR3s  R>cCs.|j|||jkr'|j|S|jS(s Get info log level. (t _checkDomainR?tNOTHING(Rtdomain((s8/usr/lib/python2.7/site-packages/firewall/core/logger.pytgetInfoLogLevel;s  cCsT|j|||jkr(|j}n||jkrC|j}n||j|(t_genDicttFalseRFREt startswithtfnmatcht fnmatchcasetTrue(RR R t_dictt point_domainRER`R\((s8/usr/lib/python2.7/site-packages/firewall/core/logger.pyRsPs   c Csr|jjdkrf|jjd}||jkrf|j|}|j|j|j}|rc|Sqfntj|j}|j}|j|j krt |j |jdr|j |jj |krdSnx|j j D]\}}trt|tjstrt|trt ||jrjt||j}t|tjkrg|j |krd|SqgqjqqWdS(s7 Function to get calling class. Returns class or None. it func_codeN(tf_codet co_argcountt co_varnamestf_localst _getClass2Rtinspectt getmoduletco_namet__dict__thasattrt__code__RtitemstPY2Rttypest ClassTypetPY3ttypetgetattrt FunctionType( Rtframetselfnamet_selftobjtmoduletcodeR\tvalue((s8/usr/lib/python2.7/site-packages/firewall/core/logger.pyt _getClassds,   cCsyxB|jjD]1}t|tjkr|j|krA|SqqWx-|jD]"}|j||}|rO|SqOWdS(s@ Internal function to get calling class. Returns class or None. N( RtvaluesRRRRt __bases__RR(RRRRtbaset_obj((s8/usr/lib/python2.7/site-packages/firewall/core/logger.pyRs cOsd}d|kr|d}nd}d|kr>|d}nd}d|kr]|d}n|j||}|sydSt|dkr|||dRls ( RR,RFRERRRRARR(RR RAR9R:R R~RRRREt used_targetsR`R]((s8/usr/lib/python2.7/site-packages/firewall/core/logger.pyRwsL              c Cs6g}t}|r0|j}|j}|j}n|j}|j}|j}xr|D]j}|dkr|||krt}t|dkrg}nPqqR|||krR|j |qRqRW| rt|dkrdS||krdSt j } x2| r-| j r-| jd|jkr-| j } qW| sCtdn| jd} | d} x'|D]}| j|rag}PqaqaW| j} t| } x||D]}|jd}|dkrqn|dkr|| }n|}| t|kr| j|s%dSq|j| sdSqWd}||krH||}ni | jd6| jd 6| d 6dd 6| jd 6dd 6|d6|d6tj|jtjd6}|d dkrd|d iiRs Frame information not available.RR6tfiletlineRtclasstfunctionR`RiR tdatet?s %(domain)s%(class)N( RR@RHRDR?RGRCRR,RRRt currentframetf_backt f_globalsRRIRRtfindt co_filenametf_linenoRttimetstrftimeRBt localtimeRARRRR(RR R t check_domainst simple_matchRRGRCR`tft module_namet point_moduletcot_lenR[tdt level_strt domain_neededRR((s8/usr/lib/python2.7/site-packages/firewall/core/logger.pyRs           (                 N(8RRRRR_R)ROR'R%RRRRRRRRRaRSRbRTRcRURdRVRNRRRRWRXRnRoRqRrRtRuRxRyRzR7R=R}RhRvR^RgRRRkRmRpRsRRRwR(((s8/usr/lib/python2.7/site-packages/firewall/core/logger.pyRsdG   ;                     !  4(t__all__RRRRRRR{R3tos.pathRtversionRRtobjectRRRRRRR(((s8/usr/lib/python2.7/site-packages/firewall/core/logger.pyts*         -! 4