Esempio n. 1
0
class Logger(log.ContextualLogger):
    logger = log.get_logger('msrplib')

    def __init__(self, prefix=None, log_traffic=False):
        super(Logger, self).__init__(logger=self.logger)
        self.prefix = prefix or ''
        self.log_traffic = log_traffic

    def apply_context(self, message):
        return '{}{}'.format(self.prefix, message) if message != '' else ''

    def received_chunk(self, data, transport):
        if self.log_traffic:
            address_line = '{local.host}:{local.port} <-- {remote.host}:{remote.port}'.format(
                local=transport.getHost(), remote=transport.getPeer())
            self.info('{} {}\n\n{}'.format(
                datetime.datetime.now(), address_line,
                data.chunk_header + data.data + data.chunk_footer))

    def sent_chunk(self, data, transport):
        if self.log_traffic:
            address_line = '{local.host}:{local.port} --> {remote.host}:{remote.port}'.format(
                local=transport.getHost(), remote=transport.getPeer())
            self.info('{} {}\n\n{}'.format(
                datetime.datetime.now(), address_line,
                data.encoded_header + data.data + data.encoded_footer))

    def received_illegal_data(self, data, transport):
        if self.log_traffic:
            address_line = '{local.host}:{local.port} <-- {remote.host}:{remote.port}'.format(
                local=transport.getHost(), remote=transport.getPeer())
            self.info('[Bad Message] {} {}\n\n{}'.format(
                datetime.datetime.now(), address_line, data))
Esempio n. 2
0
 def __init__(self):
     self.logger = log.get_logger('weblog')
     self.logger.setLevel(log.level.INFO)
     if Logging.directory:
         if not os.path.exists(Logging.directory):
             try:
                 makedirs(Logging.directory)
             except OSError as e:
                 raise RuntimeError('Cannot create logging directory {}: {}'.format(Logging.directory, e))
         self.filename = os.path.join(Logging.directory, 'access.log')
         formatter = log.Formatter()
         formatter.prefix_format = ''
         handler = FileHandler(self.filename)
         handler.setFormatter(formatter)
         self.logger.addHandler(handler)
         self.logger.propagate = False
     else:
         self.filename = None
Esempio n. 3
0
 def __init__(self, session):
     super(SessionLogger, self).__init__(
         logger=log.get_logger())  # use the main logger as backend
     self.session_id = session.call_id
Esempio n. 4
0
from __future__ import absolute_import

from application import log

# Use a named logger for sipsimple logging
log = log.get_logger('sipsimple')
Esempio n. 5
0
# Copyright (C) 2008-2012 AG Projects. See LICENSE for details

import random

from application import log
from eventlib.twistedutil.protocol import GreenTransportBase
from twisted.internet.error import ConnectionDone

from msrplib import protocol, MSRPError
from msrplib.trafficlog import Logger


log = log.get_logger('msrplib')


class ChunkParseError(MSRPError):
    """Failed to parse incoming chunk"""


class MSRPTransactionError(MSRPError):
    def __init__(self, comment=None, code=None):
        if comment is not None:
            self.comment = comment
        if code is not None:
            self.code = code
        if not hasattr(self, 'code'):
            raise TypeError("must provide 'code'")

    def __str__(self):
        if hasattr(self, 'comment'):
            return '%s %s' % (self.code, self.comment)
Esempio n. 6
0
 def __init__(self, name):
     super(ProtocolLogger, self).__init__(
         logger=log.get_logger())  # use the main logger as backend
     self.name = name
Esempio n. 7
0
        else:
            self.filename = None

    def log_access(self, request, response):
        web_transaction = _LoggedTransaction(request, response)
        if web_transaction.response_code == 200:
            print(web_transaction.access_info)

        if response.code in Logging.log_request:
            self.logger.info(web_transaction.access_info)
            request_content = web_transaction.request_content[0:500]
            if request_content:
                self.logger.info("\n")
                self.logger.info("Request from %s: %s" % (web_transaction.remote_host, request.uri))
                self.logger.info("---")
                self.logger.info(request_content)

        if response.code in Logging.log_response:
            self.logger.info(web_transaction.access_info)
            response_content = web_transaction.response_content[0:500]
            if response_content:
                self.logger.info("\n")
                self.logger.info("Response: %d" % web_transaction.response_code)
                self.logger.info("---")
                self.logger.info(response_content)


root_logger = log.get_logger()
root_logger.name = 'server'
web_logger = WEBLogger()