示例#1
0
文件: logging.py 项目: schiebel/casa
 def __init__(self):
     self._enabled = True
     self._log = ""
     if is_casapy():
         from taskinit import casalog
         self.logger = casalog
     else:
         self.logger = LogSink()
         set_global_sink(self.logger)
示例#2
0
文件: logging.py 项目: schiebel/casa
 def __init__(self):
     self._enabled = True
     self._log = ""
     if is_casapy():
         from taskinit import casalog
         self.logger = casalog
     else:
         self.logger = LogSink()
         set_global_sink(self.logger)
示例#3
0
文件: logging.py 项目: schiebel/casa
class AsapLogger(object):
    """Wrapper object to allow for both casapy and asap logging.

    Inside casapy this will connect to `taskinit.casalog`. Otherwise it will
    create its own casa log sink.

    .. note:: Do not instantiate a new one - use the :obj:`asaplog` instead.

    """
    def __init__(self):
        self._enabled = True
        self._log = ""
        if is_casapy():
            from taskinit import casalog
            self.logger = casalog
        else:
            self.logger = LogSink()
            set_global_sink(self.logger)

    def post(self, level='INFO', origin=""):
        """Post the messages to the logger. This will clear the buffered
        logs.

        Parameters:

            level:  The log level (severity). One of INFO, WARN, ERROR.

        """
        if not self._enabled:
            return

        if not origin:
            origin = inspect.getframeinfo(inspect.currentframe().f_back)[2]
        logs = self._log.strip()
        if len(logs) > 0:
            if isinstance(self.logger, LogSink):
                #can't handle unicode in boost signature
                logs = str(logs)
            self.logger.post(logs, priority=level, origin=origin)
        if isinstance(self.logger, LogSink):
            logs = self.logger.pop().strip()
            if len(logs) > 0:
                if rcParams['verbose']:
                    print >>sys.stdout, logs
                    if hasattr(sys.stdout, "flush"):
                        sys.stdout.flush()
        self._log = ""

    def clear(self):
        if isinstance(self.logger, LogSink):
            logs = self.logger.pop()
            
    def push(self, msg, newline=True):
        """Push logs into the buffer. post needs to be called to send them.

        Parameters:

            msg:        the log message (string)

            newline:    should we terminate with a newline (default yes)

        """
        if self._enabled:
            sep = ""
            self._log = sep.join([self._log, msg])
            if newline:
                self._log += "\n"

    def enable(self, flag=True):
        """Enable (or disable) logging."""
        self._enabled = flag

    def disable(self, flag=False):
        """Disable (or enable) logging"""
        self._enabled = flag

    def is_enabled(self):
        return self._enabled
示例#4
0
文件: logging.py 项目: schiebel/casa
class AsapLogger(object):
    """Wrapper object to allow for both casapy and asap logging.

    Inside casapy this will connect to `taskinit.casalog`. Otherwise it will
    create its own casa log sink.

    .. note:: Do not instantiate a new one - use the :obj:`asaplog` instead.

    """
    def __init__(self):
        self._enabled = True
        self._log = ""
        if is_casapy():
            from taskinit import casalog
            self.logger = casalog
        else:
            self.logger = LogSink()
            set_global_sink(self.logger)

    def post(self, level='INFO', origin=""):
        """Post the messages to the logger. This will clear the buffered
        logs.

        Parameters:

            level:  The log level (severity). One of INFO, WARN, ERROR.

        """
        if not self._enabled:
            return

        if not origin:
            origin = inspect.getframeinfo(inspect.currentframe().f_back)[2]
        logs = self._log.strip()
        if len(logs) > 0:
            if isinstance(self.logger, LogSink):
                #can't handle unicode in boost signature
                logs = str(logs)
            self.logger.post(logs, priority=level, origin=origin)
        if isinstance(self.logger, LogSink):
            logs = self.logger.pop().strip()
            if len(logs) > 0:
                if rcParams['verbose']:
                    print >> sys.stdout, logs
                    if hasattr(sys.stdout, "flush"):
                        sys.stdout.flush()
        self._log = ""

    def clear(self):
        if isinstance(self.logger, LogSink):
            logs = self.logger.pop()

    def push(self, msg, newline=True):
        """Push logs into the buffer. post needs to be called to send them.

        Parameters:

            msg:        the log message (string)

            newline:    should we terminate with a newline (default yes)

        """
        if self._enabled:
            sep = ""
            self._log = sep.join([self._log, msg])
            if newline:
                self._log += "\n"

    def enable(self, flag=True):
        """Enable (or disable) logging."""
        self._enabled = flag

    def disable(self, flag=False):
        """Disable (or enable) logging"""
        self._enabled = flag

    def is_enabled(self):
        return self._enabled