Source code for pymepix.core.log

# This file is part of Pymepix
#
# In all scientific work using Pymepix, please reference it as
#
# A. F. Al-Refaie, M. Johny, J. Correa, D. Pennicard, P. Svihra, A. Nomerotski, S. Trippel, and J. Küpper:
# "PymePix: a python library for SPIDR readout of Timepix3", J. Inst. 14, P10003 (2019)
# https://doi.org/10.1088/1748-0221/14/10/P10003
# https://arxiv.org/abs/1905.07999
#
# Pymepix is free software: you can redistribute it and/or modify it under the terms of the GNU
# General Public License as published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with this program. If not,
# see <https://www.gnu.org/licenses/>.


from abc import abstractmethod
import logging
import multiprocessing as mp

__all__ = ["Logger", "ProcessLogger"]

class PymepixLogger(object):
    """Base class for logging in pymepix

    This class wraps logging functionality and provides them to the derived classes
    providing info,debug,critical, error and warning methods

    Should not be used directly

    Parameters
    -----------
    name : str
        Name used for logging

    """

    

    def __init__(self, name):
        self._logger = self.getLogger(name)
        self._log_name = "pymepix.{}".format(name)

    @property
    def logName(self):
        return self._log_name

    @abstractmethod
    def getLogger(cls, name):
        pass 

    def info(self, message, *args, **kwargs):
        """ See :class:`logging.Logger` """
        self._logger.info(message, *args, **kwargs)

    def warning(self, message, *args, **kwargs):
        """ See :class:`logging.Logger` """
        self._logger.warning(message, *args, **kwargs)

    def debug(self, message, *args, **kwargs):
        """ See :class:`logging.Logger` """
        self._logger.debug(message, *args, **kwargs)

    def error(self, message, *args, **kwargs):
        """ See :class:`logging.Logger` """
        self._logger.error(message, *args, **kwargs)

    def critical(self, message, *args, **kwargs):
        """ See :class:`logging.Logger` """
        self._logger.critical(message, *args, **kwargs)


[docs]class Logger(PymepixLogger): """Standard logging using logger library Parameters ----------- name : str Name used for logging """ def __init__(self, name): PymepixLogger.__init__(self, name) self._logger = logging.getLogger(self.logName)
[docs] def getLogger(cls, name): return logging.getLogger("pymepix.{}".format(name))
[docs]class ProcessLogger(PymepixLogger): """Sends logs to queue to be processed by logging thread Parameters ----------- name : str Name used for logging """
[docs] def getLogger(self, name): return mp.get_logger()
def main(): pass if __name__ == "__main__": main() # Local Variables: # fill-column: 100 # truncate-lines: t # End: