Ignore:
Timestamp:
08/05/10 11:46:40 (14 years ago)
Author:
Malte Marquarding
Message:

Adde more API documentation

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/python/logging.py

    r1833 r1858  
    1 __all__ = ["asaplog", "print_log", "print_log_dec"]
     1"""This module presents a logging abstraction layer on top of casa.
     2"""
     3__all__ = ["asaplog", "print_log", "print_log_dec", "AsapLogger"]
    24
    35from asap.env import is_casapy
     
    1012
    1113
    12 class _asaplog(object):
    13     """Wrapper object to allow for both casapy and asap logging"""
     14class AsapLogger(object):
     15    """Wrapper object to allow for both casapy and asap logging.
     16
     17    Inside casapy this will connect to `taskinit.casalog`. Otherwise it will
     18    create its own casa log sink.
     19
     20    .. note:: Do instantiate a new one - use the :obj:`asaplog` instead.
     21   
     22    """
    1423    def __init__(self):
    1524        self._enabled = False
     
    2534        """Post the messages to the logger. This will clear the buffered
    2635        logs.
     36
     37        Parameters:
     38
     39            level:  The log level (severity). One of INFO, WARN, ERROR.
     40
    2741        """
    2842        if not self._enabled:
     
    4155
    4256    def push(self, msg, newline=True):
    43         """Push logs into the buffer. post needs to be called to send them."""
     57        """Push logs into the buffer. post needs to be called to send them.
     58
     59        Parameters:
     60
     61            msg:        the log message (string)
     62
     63            newline:    should we terminate with a newline (default yes)
     64
     65        """
    4466        from asap import rcParams
    4567        if self._enabled:
     
    5880        self._enabled = flag
    5981
    60 asaplog = _asaplog()
     82asaplog = AsapLogger()
     83"""Default asap logger"""
    6184
    6285def print_log_dec(f, level='INFO'):
     86    """Decorator which posts log at completion of the wrapped method.
     87    Example::
     88
     89        @print_log_dec
     90        def test(self):
     91            do_stuff()
     92            asaplog.push('testing...', False)
     93            do_more_stuff()
     94            asaplog.push('finished')
     95    """
    6396    @wraps_dec(f)
    6497    def wrap_it(*args, **kw):
     
    69102
    70103def print_log(level='INFO'):
    71     """Alias for asaplog.post."""
     104    """Alias for asaplog.post(level)"""
    72105    asaplog.post(level)
Note: See TracChangeset for help on using the changeset viewer.