Example #1
0
    def __init__(self,
                 address="/dev/log",
                 facility=SysLogHandler.LOG_LOCAL1,
                 socktype=socket.SOCK_DGRAM,
                 log_callback=None):
        """
        Init
        :param address: tuple ('ip', port) or string "target"
        :type address:  str, tuple
        :param facility: log facility
        :type facility: int
        :param socktype: Type of socket
        :type socktype: int
        :param log_callback: Callback for unit test
        """

        # To avoid some warnings
        self.socket = None
        self.address = None

        # Store
        self._log_callback = log_callback
        self.socktype = socktype

        # Base call
        SysLogHandler.__init__(self, address, facility)
Example #2
0
 def __init__(self, session=None, port=None, inputname='', input=None,
              announce=False, authorize=True, **kwargs):
     #TODO: avoid duplication with __init__ above
     if inputname:
         # raise if no session
         input = session.get_input_by_name(inputname)
     if input:
         self.inputobj = input
         try:
             port = input.port
             self.inputname = input.name
         except AttributeError:
             raise ValueError("This doesn't look like a syslog input")
         if authorize:
             if port == 514:
                 # raise if no session
                 session._api_help('api/inputs/%s/add514' % input.id)
             else:
                 session._api_help('api/inputs/%s/adddevice' % input.id,
                                  method='POST')
         if ('tcp' in input.service['name'] and sys.version_info >= (2, 7)
                 and not 'socktype' in kwargs):
             kwargs['socktype'] = socket.SOCK_STREAM
     self.port = port
     session = session or LogglySession
     SysLogHandler.__init__(self, address=(session.proxy, port),
                            **kwargs)
Example #3
0
 def __init__(self,
              address=('localhost', SYSLOG_UDP_PORT),
              facility=SysLogHandler.LOG_USER,
              socktype=socket.SOCK_DGRAM,
              MTU=1400):
     SysLogHandler.__init__(self, address, facility, socktype)
     self.MTU = MTU
Example #4
0
    def __init__(self):
        socket = "/dev/log"
        if os.path.exists("/var/run/syslog"):
            # syslog socket path on mac osx
            socket = "/var/run/syslog"

        SysLogHandler.__init__(self, address=socket)
Example #5
0
	def __init__(self,*args, **kwargs):
		SysLogHandler.__init__(self,*args, **kwargs)
		self.queue = multiprocessing.Queue(-1)

		t = threading.Thread(target=self.receive)
		t.daemon = True
		t.start()
Example #6
0
 def __init__(self,
              session=None,
              port=None,
              inputname='',
              input=None,
              announce=False,
              authorize=True,
              **kwargs):
     #TODO: avoid duplication with __init__ above
     if inputname:
         # raise if no session
         input = session.get_input_by_name(inputname)
     if input:
         self.inputobj = input
         try:
             port = input.port
             self.inputname = input.name
         except AttributeError:
             raise ValueError("This doesn't look like a syslog input")
         if authorize:
             if port == 514:
                 # raise if no session
                 session._api_help('api/inputs/%s/add514' % input.id)
             else:
                 session._api_help('api/inputs/%s/adddevice' % input.id,
                                   method='POST')
     self.port = port
     session = session or LogglySession
     SysLogHandler.__init__(self, address=(session.proxy, port), **kwargs)
Example #7
0
 def __init__(self, *args, **kwargs):
     self.app_name = get_app_name()
     self.fallback = False
     self.fallback_stream = kwargs.pop('fallback_stream', sys.stderr)
     try:
         SysLogHandler.__init__(self, *args, **kwargs)
     except socket.error:
         self.fallback = True
         self._fallback_logging("Unable to connect to syslog. "
                                "Falling back to file stream logging")
Example #8
0
 def __init__(self,
              address=('localhost', SYSLOG_UDP_PORT),
              facility=SysLogHandler.LOG_USER,
              tag=''):
     self.tag = tag
     SysLogHandler.__init__(self, address, facility)
Example #9
0
 def __init__(self, address=('localhost', 514), facility=SysLogHandler.LOG_USER,
              add_bom=True):
     SysLogHandler.__init__(self, address, facility)
     self._add_bom = add_bom
 def __init__(self,
              address=('localhost', SYSLOG_UDP_PORT),
              facility=SysLogHandler.LOG_USER,
              tag=''):
     self.tag = tag
     SysLogHandler.__init__(self, address, facility)
Example #11
0
 def __init__(self, app_name, address):
     SysLogHandler.__init__(self, address)
     self.app_name = app_name
Example #12
0
 def __init__(self, app, *args, **kwargs):
     self.binary_name = _get_binary_name()
     self.app = app
     SysLogHandler.__init__(self, *args, **kwargs)
Example #13
0
    def __init__(
        self, address=('localhost', SYSLOG_UDP_PORT),
            facility=SysLogHandler.LOG_USER,
            socktype=None,
            encoding="utf-8"):
        """
        Initialize the PbSysLogHandler.

        To log to a local syslogd, "PbSysLogHandler(address = "/dev/log")"
        can be used.

        If facility is not specified, LOG_USER is used.

        @param address: either the network socket of the syslog daemon
                        (if given as tuple) or the filename of the UNIX socket
                        of the syslog daemon (if given as str).
        @type address: tuple or str
        @param facility: syslog facility to use
        @type facility: int
        @param socktype: the socket type (socket.SOCK_DGRAM or
                         socket.SOCK_STREAM) to use.
                         Not used in Python2 <= 2.6 and Python3 <= 3.1.
        @type socktype: int
        @param encoding: the character set to use to encode unicode messages
        @type encoding: str

        """

        # Initialisation of the parent object
        do_socktype = False
        do_ux_socket = False

        if sys.version_info[0] > 2:
            if sys.version_info[1] > 1:
                do_socktype = True
        else:
            if sys.version_info[1] > 6:
                do_socktype = True

        if isinstance(address, str):
            if not os.path.exists(address):
                raise OSError(errno.ENOENT, "File doesn't exists", address)
            mode = os.stat(address).st_mode
            if not stat.S_ISSOCK(mode):
                raise OSError(
                    errno.EPERM, "File is not a UNIX socket file", address)
            if not os.access(address, os.W_OK):
                raise OSError(
                    errno.EPERM, "No write access to socket", address)

            do_ux_socket = True

        if do_socktype:
            if do_ux_socket:
                SysLogHandler.__init__(self, address, facility, None)
            else:
                SysLogHandler.__init__(self, address, facility, socktype)
        else:
            SysLogHandler.__init__(self, address, facility)

        self.encoding = encoding
        """
Example #14
0
 def __init__(self, msg_max_length=STD_MSG_LENGTH_LIMIT, *args, **kwargs):
     if msg_max_length >= self.MIN_MSG_LENGTH_LIMIT:
         self.max_length = msg_max_length
     else:
         self.max_length = self.STD_MSG_LENGTH_LIMIT
     SysLogHandler.__init__(self, *args, **kwargs)
Example #15
0
 def __init__(self, msg_max_length=STD_MSG_LENGTH_LIMIT, *args, **kwargs):
     if msg_max_length >= self.MIN_MSG_LENGTH_LIMIT:
         self.max_length = msg_max_length
     else:
         self.max_length = self.STD_MSG_LENGTH_LIMIT
     SysLogHandler.__init__(self, *args, **kwargs)
Example #16
0
 def __init__(self,
              address=('localhost', logging.handlers.SYSLOG_UDP_PORT),
              facility=SysLogHandler.LOG_USER,
              socktype=None):
     SysLogHandler.__init__(self, address, facility, socktype)
     self.include_priority = True
Example #17
0
 def __init__(self, address=('localhost', SYSLOG_UDP_PORT),
              facility=SysLogHandler.LOG_USER, socktype=socket.SOCK_DGRAM, MTU=1400):
     SysLogHandler.__init__(self, address, facility, socktype)
     self.MTU = MTU