Commit 2c449528 authored by Antoine Millet's avatar Antoine Millet
Browse files

[bug#3989] Implementation of "napkin logging specs".

parent 9a7113c4
Loading
Loading
Loading
Loading
+5 −11
Original line number Diff line number Diff line
@@ -28,7 +28,7 @@ DEFAULT_CONFIGURATION = {
    'pidfile': '',
    'umask': '0177',
    'port': 1984,
    'verbosity': 0,
    'debug': False,
    'account_db': None, # None = mandatory option
    'interface': '127.0.0.1',
    'ssl_cert': None,
@@ -60,14 +60,8 @@ class EncodingFormatter(logging.Formatter, object):
def run_server(options):

    # Setup logging facility:
    level = logging.ERROR
    verb = int(options['verbosity'])
    if verb:
        if verb == 1:
            level = logging.WARNING
        elif verb == 2:
    level = logging.INFO
        else:
    if options['debug'] in (True, 'yes', 'true'):
        level = logging.DEBUG

    logger = logging.getLogger()
@@ -106,9 +100,9 @@ def run_server(options):
    try:
        server.run()
    except Exception as err:
        logging.critical('Server failed: %s', err)
        import traceback
        traceback.print_exc(file=sys.stdout)
        logging.critical('Server fail: %s' % err)
        sys.exit(3)

if __name__ == '__main__':
+4 −2
Original line number Diff line number Diff line
@@ -55,12 +55,14 @@ class CCServer(object):
        sock.bind((address, port))
        sock.listen(CCServer.LISTEN_BACKLOG)

        logging.info('Server started to running')

        if certfile:
            logging.info('SSL Certificate: %s', certfile)
        if keyfile:
            logging.info('SSL Key: %s', certfile)

        logging.info('Started to listen on %s port %s', address, port)
        logging.info('Listening on %s:%s', address, port)

        self.objects = ObjectsDB(self)

@@ -184,7 +186,7 @@ class CCServer(object):
        Run the server mainloop.
        '''

        logging.info('Running manager mainloop')
        logging.debug('Running manager mainloop')
        self.manager.run()

    def get_connection(self, login):
+14 −3
Original line number Diff line number Diff line
@@ -93,6 +93,8 @@ class CCHandler(RpcHandler):
class OnlineCCHandler(CCHandler):

    def on_disconnect(self, conn):
        client = self._server.search_client_by_connection(conn)
        logging.info('Client %s disconnected', client.login)
        self._server.unregister(conn)

    def _check(self, conn, method, tql=None):
@@ -693,6 +695,7 @@ class WelcomeHandler(CCHandler):
        :thrown AuthenticationError: when authentication fail
        '''

        logmsg = 'Authentication error from %s: '
        conf = self._server.conf
        with conf:
            try:
@@ -701,21 +704,29 @@ class WelcomeHandler(CCHandler):
                raise AuthenticationError('Unknown login')
            else:
                if 'close' in self._server.conf.show(login)['tags']:
                    logging.warning(logmsg + 'account closed (%s)',
                                    conn.getpeername(), login)
                    raise AuthenticationError('Account is closed')

        if role is None:
            logging.info('New authentication from %s: failure',
                         login.encode('ascii', 'ignore'))
            logging.warning(logmsg + 'bad login/password (%s)',
                            conn.getpeername(), login)
            raise AuthenticationError('Bad login/password')
        else:
            if role not in WelcomeHandler.ROLES:
                logging.warning(logmsg + 'bad role in account config (%s)',
                                conn.getpeername(), login)
                raise BadRoleError('%r is not a legal role' % role)
            
            # If authentication is a success, try to register the client:
            try:
                self._server.register(login, role, conn)
            except AlreadyRegistered:
                logging.warning(logmsg + 'already connected (%s)',
                                conn.getpeername(), login)
                raise AuthenticationError('Already connected')
            conn.set_handler(WelcomeHandler.ROLES.get(role)(self._server))

            logging.info('Authentication success from %s with login %s',
                         conn.getpeername(), login)
            return role
+1 −1
Original line number Diff line number Diff line
@@ -164,7 +164,7 @@ class ObjectsDB(object):
        for msg in msgs:
            # Update tags if received from the peer:
            if msg.get('error') is not None:
                logging.error('Error from client while getting tags')
                logging.warning('Error from client while getting tags')
            else:
                returned = msg['return']
                obj = msg['data']