ó
1ËoQc           @   s  d  Z  d Z d d l Z d d l Z d Z d Z d d d „  ƒ  YZ d e f d	 „  ƒ  YZ e a d
 e f d „  ƒ  YZ	 i  Z
 d e f d „  ƒ  YZ d „  Z d „  Z d „  Z e e
 d <e e
 d <d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d d „ Z d „  Z d „  Z d S(   t   Loggings   $Id$iÿÿÿÿNi   i   t   ILoggerc           B   s_   e  Z d  Z d Z d „  Z d „  Z d „  Z d „  Z d „  Z e	 e ƒ Z d „  Z
 d „  Z RS(	   s[   Logger interface, by default this class
    will be used and logging calls are no-ops.
    i    c         C   s   d  S(   N(    (   t   selft   msg(    (    s3   /usr/lib/python2.7/dist-packages/wstools/logging.pyt   __init__   s    c         O   s   d  S(   N(    (   R   t   argst   kw(    (    s3   /usr/lib/python2.7/dist-packages/wstools/logging.pyt   warning   s    c         O   s   d  S(   N(    (   R   R   R   (    (    s3   /usr/lib/python2.7/dist-packages/wstools/logging.pyt   debug   s    c         O   s   d  S(   N(    (   R   R   R   (    (    s3   /usr/lib/python2.7/dist-packages/wstools/logging.pyt   error   s    c         C   s   | |  _  d  S(   N(   t   level(   t   clsR
   (    (    s3   /usr/lib/python2.7/dist-packages/wstools/logging.pyt   setLevel!   s    c         C   s   |  j  t k S(   N(   R
   t   DEBUG(   R   (    (    s3   /usr/lib/python2.7/dist-packages/wstools/logging.pyt   <lambda>%   s    c         C   s   |  j  t k S(   N(   R
   t   WARN(   R   (    (    s3   /usr/lib/python2.7/dist-packages/wstools/logging.pyR   &   s    (   t   __name__t
   __module__t   __doc__R
   R   R   R   R	   R   t   classmethodt   debugOnt   warnOn(    (    (    s3   /usr/lib/python2.7/dist-packages/wstools/logging.pyR      s   						t   BasicLoggerc           B   sS   e  Z d  Z e j d „ Z d „  Z d Z d „  Z d Z	 d „  Z
 d Z d „  Z RS(	   t    c         C   s   | | |  _  |  _ d  S(   N(   R   t   out(   R   R   R   (    (    s3   /usr/lib/python2.7/dist-packages/wstools/logging.pyR   ,   s    c         O   ss   |  j  ƒ  t k r d  St j |  j k rP |  j t _ |  d I|  j Id IJn  |  d |  j I|  | | IJd  S(   Ns   ---- s    ----s       %s  (   R   t   FalseR   t   lastR   R   (   R   R   R   R   (    (    s3   /usr/lib/python2.7/dist-packages/wstools/logging.pyR   /   s    s   [WARN]c         O   ss   |  j  ƒ  t k r d  St j |  j k rP |  j t _ |  d I|  j Id IJn  |  d |  j I|  | | IJd  S(   Ns   ---- s    ----s       %s  (   R   R   R   R   R   R   (   R   R   R   R   (    (    s3   /usr/lib/python2.7/dist-packages/wstools/logging.pyR   9   s    s   [DEBUG]c         O   s]   t  j |  j k r: |  j t  _ |  d I|  j Id IJn  |  d |  j I|  | | IJd  S(   Ns   ---- s    ----s       %s  (   R   R   R   t   ERROR(   R   R   R   R   (    (    s3   /usr/lib/python2.7/dist-packages/wstools/logging.pyR	   C   s
    s   [ERROR]c         G   s4   x | D] } |  j  j | ƒ q Wd j | Œ  } d S(   s4   Write convenience function; writes strings.
        R   N(   R   t   writet   join(   R   R   t   st   event(    (    s3   /usr/lib/python2.7/dist-packages/wstools/logging.pyR   K   s    (   R   R   R   t   syst   stdoutR   R   R   R   R   R	   R   R   (    (    (    s3   /usr/lib/python2.7/dist-packages/wstools/logging.pyR   )   s   			t
   GridLoggerc           B   s#   e  Z d  „  Z d „  Z d „  Z RS(   c         O   s+   |  j  | d <t d | | d d |  d  S(   Nt	   componentR   R
   R   (   R   t   gridLog(   R   R   R   R   (    (    s3   /usr/lib/python2.7/dist-packages/wstools/logging.pyR   W   s    c         O   s+   |  j  | d <t d | | d d |  d  S(   NR#   R   R
   t   WARNING(   R   R$   (   R   R   R   R   (    (    s3   /usr/lib/python2.7/dist-packages/wstools/logging.pyR   [   s    c         O   s+   |  j  | d <t d | | d d |  d  S(   NR#   R   R
   R   (   R   R$   (   R   R   R   R   (    (    s3   /usr/lib/python2.7/dist-packages/wstools/logging.pyR	   _   s    (   R   R   R   R   R	   (    (    (    s3   /usr/lib/python2.7/dist-packages/wstools/logging.pyR"   V   s   		t   GLRecordc           B   sº   e  Z d  Z d Z d  Z e d d d	 d
 d d d d d d d d d d d d d d ƒ 	Z d! d „ Z d „  Z	 d e
 f d „  ƒ  YZ i e
 e 6d „  e 6e
 e 6d „  e
 6e
 e 6e
 e 6Z RS("   sâ  Grid Logging Best Practices Record, Distributed Logging Utilities

    The following names are reserved:

    event -- log event name
        Below is EBNF for the event name part of a log message.
            name        = <nodot> ( "." <name> )?
            nodot       = {RFC3896-chars except "."}

        Suffixes:
            start: Immediately before the first action in a task.
            end: Immediately after the last action in a task (that succeeded).
            error: an error condition that does not correspond to an end event.

    ts -- timestamp
    level -- logging level (see levels below)
    status -- integer status code
    gid -- global grid identifier
    gid, cgid -- parent/child identifiers
    prog -- program name


    More info: http://www.cedps.net/wiki/index.php/LoggingBestPractices#Python

    reserved -- list of reserved names,
    omitname -- list of reserved names, output only values ('ts', 'event',)
    levels -- dict of levels and description
    t   tsR   R
   t   statust   gidt   progt   FATALs1   Component cannot continue, or system is unusable.t   ALERTs!   Action must be taken immediately.t   CRITICALs$   Critical conditions (on the system).R   s3   Errors in the component; not errors from elsewhere.R%   s*   Problems that are recovered from, usually.t   NOTICEs!   Normal but significant condition.t   INFOsK   Informational messages that would be useful to a deployer or administrator.R   sP   Lower level information concerning program logic decisions, internal state, etc.t   TRACEsJ   Finest granularity, similar to "stepping through" the component or system.c         K   sI   | p |  j  ƒ  | d <| j d ƒ p. t j ƒ  | d <t j |  | ƒ d  S(   NR'   R)   (   t   GLDatet   gett   ost   getpidt   dictR   (   R   t   dateR   (    (    s3   /usr/lib/python2.7/dist-packages/wstools/logging.pyR   “   s    c            s%  d d l  m } | ƒ  } d } ˆ j ‰  ˆ j } ˆ j } xÑ t t ‡ f d †  ˆ  ƒ ƒ t t ‡  f d †  ˆ j ƒ  ƒ ƒ D] } ˆ | } | | k rÁ | j d ˆ j	 t
 | ƒ | ƒ ƒ q{ n  | ˆ  d k rà | | k rà n  | j d | ˆ j	 t
 | ƒ | ƒ f ƒ q{ W| j d	 ƒ | j ƒ  S(
   s	   
        iÿÿÿÿ(   t   StringIOt    c            s
   |  ˆ  k S(   N(    (   t   i(   R   (    s3   /usr/lib/python2.7/dist-packages/wstools/logging.pyR   ¢   s    c            s
   |  ˆ  k S(   N(    (   R9   (   t   reserved(    s3   /usr/lib/python2.7/dist-packages/wstools/logging.pyR   £   s    s   %s i   s   %s=%s s   
(   t	   cStringIOR7   R:   t   omitnamet   levelst   listt   filtert   keysR   t   formatt   typet   getvalue(   R   R7   R   t   nR<   R=   t   kt   v(    (   R:   R   s3   /usr/lib/python2.7/dist-packages/wstools/logging.pyt   __str__˜   s"    				)
$.R1   c           B   s   e  Z d  Z d d „ Z RS(   sñ   Grid logging Date Format
        all timestamps should all be in the same time zone (UTC).
        Grid timestamp value format that is a highly readable variant of the ISO8601 time standard [1]:

        YYYY-MM-DDTHH:MM:SS.SSSSSSZ

        c         C   sq   d d l  } | p | j  j ƒ  } | j | j | j | j | j | j | j | j	 pW d f } t
 j |  d | ƒ S(   sd   args -- datetime (year, month, day[, hour[, minute[, second[, microsecond[,tzinfo]]]]])
            iÿÿÿÿNt   Zs$   %04d-%02d-%02dT%02d:%02d:%02d.%06d%s(   t   datetimet   utcnowt   yeart   montht   dayt   hourt   minutet   secondt   microsecondt   tzinfot   strt   __new__(   R   R   RI   t   l(    (    s3   /usr/lib/python2.7/dist-packages/wstools/logging.pyRT   º   s
    $N(   R   R   R   t   NoneRT   (    (    (    s3   /usr/lib/python2.7/dist-packages/wstools/logging.pyR1   ²   s   c         C   s   d |  S(   Ns   %lf(    (   t   x(    (    s3   /usr/lib/python2.7/dist-packages/wstools/logging.pyR   Ä   s    c         C   s   |  S(   N(    (   RW   (    (    s3   /usr/lib/python2.7/dist-packages/wstools/logging.pyR   Ä   s    (   s   tss   events   levelR(   s   gidR*   (    N(   R   R   R   R:   R<   R5   R=   RV   R   RG   RS   R1   t   intt   floatt   longt   unicodeRA   (    (    (    s3   /usr/lib/python2.7/dist-packages/wstools/logging.pyR&   j   s"   		%c          K   s¾   d d l  } t t | j j d d ƒ ƒ ƒ s1 d S| j j d ƒ } | d k rS d Sy: | | j d ƒ  } t | } | | t t	 |    ƒ ƒ Wn* t
 k
 r¹ } t j d t |  ƒ IJn Xd S(   s  Send GLRecord, Distributed Logging Utilities
    If the scheme is passed as a keyword parameter
    the value is expected to be a callable function
    that takes 2 parameters: url, outputStr

    GRIDLOG_ON   -- turn grid logging on
    GRIDLOG_DEST -- provide URL destination
    iÿÿÿÿNt
   GRIDLOG_ONi    t   GRIDLOG_DESTs   ://s   *** gridLog failed -- %s(   R3   t   boolRX   t   environR2   RV   t   findt
   GLRegistryRS   R&   t	   ExceptionR    t   stderr(   R   R3   t   urlt   schemet   sendt   ex(    (    s3   /usr/lib/python2.7/dist-packages/wstools/logging.pyR$   È   s    	!
c   
      C   sµ   d d l  m  } m } m } |  j d ƒ d } |  j d | ƒ } | | k  r\ t |  ƒ } n  |  | | !} | j d ƒ d g d d	 !\ } }	 | | | ƒ j | | t |	 ƒ f ƒ d  S(
   Niÿÿÿÿ(   t   sockett   AF_INETt
   SOCK_DGRAMs   ://i   t   /t   :iP   i    i   (   Rh   Ri   Rj   R`   t   lent   splitt   sendtoRX   (
   Rd   t	   outputStrRh   Ri   Rj   t   idx1t   idx2t   netloct   hostt   port(    (    s3   /usr/lib/python2.7/dist-packages/wstools/logging.pyt   sendUDPã   s    #c         C   s$   t  |  j d ƒ d d ƒ | IJd  S(   Ns   ://i   s   a+(   t   openRn   (   Rd   Rp   (    (    s3   /usr/lib/python2.7/dist-packages/wstools/logging.pyt   writeToFileî   s    s   gridlog-udpt   filec           C   s   t  t ƒ t j d ƒ d S(   s   Use Basic Logger.
    i    N(   t   setLoggerClassR   R   (    (    (    s3   /usr/lib/python2.7/dist-packages/wstools/logging.pyt   setBasicLoggerõ   s    
c           C   s   t  t ƒ d S(   s+   Use GridLogger for all logging events.
    N(   Rz   R"   (    (    (    s3   /usr/lib/python2.7/dist-packages/wstools/logging.pyt   setGridLoggerü   s    c           C   s   t  t ƒ t j t ƒ d S(   s   Use Basic Logger.
    N(   Rz   R   R   R   (    (    (    s3   /usr/lib/python2.7/dist-packages/wstools/logging.pyt   setBasicLoggerWARN  s    
c           C   s   t  t ƒ t j t ƒ d S(   s   Use Basic Logger.
    N(   Rz   R   R   R   (    (    (    s3   /usr/lib/python2.7/dist-packages/wstools/logging.pyt   setBasicLoggerDEBUG	  s    
c         C   s   d S(   s   Set Logging Class.
    N(    (   t   loggingClass(    (    s3   /usr/lib/python2.7/dist-packages/wstools/logging.pyRz     s    c         C   s%   t  |  t ƒ s t d ƒ ‚ |  a d S(   s   Set Logging Class.
    s"   loggingClass must subclass ILoggerN(   t
   issubclassR   t   AssertionErrort   _LoggerClass(   R   (    (    s3   /usr/lib/python2.7/dist-packages/wstools/logging.pyRz     s    i    c         C   s   |  t  _ d S(   s   Set Global Logging Level.
    N(   R   R
   (   R
   (    (    s3   /usr/lib/python2.7/dist-packages/wstools/logging.pyR     s    c           C   s   t  j S(   N(   R   R
   (    (    (    s3   /usr/lib/python2.7/dist-packages/wstools/logging.pyt   getLevel#  s    c         C   s
   t  |  ƒ S(   s&   Return instance of Logging class.
    (   R‚   (   R   (    (    s3   /usr/lib/python2.7/dist-packages/wstools/logging.pyt	   getLogger'  s    (    (   R   t   identR3   R    R   R   R   R   R‚   R"   Ra   R5   R&   R$   Rv   Rx   R{   R|   R}   R~   Rz   R   Rƒ   R„   (    (    (    s3   /usr/lib/python2.7/dist-packages/wstools/logging.pyt   <module>   s2   *^			

							