Changeset 1858 for trunk/python/logging.py
- Timestamp:
- 08/05/10 11:46:40 (14 years ago)
- 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"] 2 4 3 5 from asap.env import is_casapy … … 10 12 11 13 12 class _asaplog(object): 13 """Wrapper object to allow for both casapy and asap logging""" 14 class 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 """ 14 23 def __init__(self): 15 24 self._enabled = False … … 25 34 """Post the messages to the logger. This will clear the buffered 26 35 logs. 36 37 Parameters: 38 39 level: The log level (severity). One of INFO, WARN, ERROR. 40 27 41 """ 28 42 if not self._enabled: … … 41 55 42 56 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 """ 44 66 from asap import rcParams 45 67 if self._enabled: … … 58 80 self._enabled = flag 59 81 60 asaplog = _asaplog() 82 asaplog = AsapLogger() 83 """Default asap logger""" 61 84 62 85 def 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 """ 63 96 @wraps_dec(f) 64 97 def wrap_it(*args, **kw): … … 69 102 70 103 def print_log(level='INFO'): 71 """Alias for asaplog.post ."""104 """Alias for asaplog.post(level)""" 72 105 asaplog.post(level)
Note: See TracChangeset
for help on using the changeset viewer.