Commit 491ef181 authored by ibuler's avatar ibuler

[Logging] 修改logger

parent 3c7b0d56
......@@ -6,7 +6,6 @@ import datetime
import os
import time
import threading
import logging
import socket
import json
......@@ -18,12 +17,13 @@ from .httpd import HttpServer
from .logger import create_logger
from .tasks import TaskHandler
from .recorder import get_command_recorder_class, get_replay_recorder_class
from .utils import get_logger
__version__ = '0.5.0'
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
logger = logging.getLogger(__file__)
logger = get_logger(__file__)
class Coco:
......
......@@ -2,7 +2,6 @@
# -*- coding: utf-8 -*-
#
import os
import logging
import socket
from flask_socketio import SocketIO, Namespace, emit, join_room, leave_room
from flask import Flask, send_from_directory, render_template, request, jsonify
......@@ -12,11 +11,12 @@ import uuid
from jms.models import User
from .models import Request, Client, WSProxy
from .proxy import ProxyServer
from .utils import get_logger
__version__ = '0.4.0'
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
logger = logging.getLogger(__file__)
logger = get_logger(__file__)
class BaseWebSocketHandler:
......
......@@ -2,22 +2,21 @@
# -*- coding: utf-8 -*-
#
import logging
import socket
import threading
import weakref
import os
from jms.models import Asset, AssetGroup
from . import char
from .utils import wrap_with_line_feed as wr, wrap_with_title as title, \
wrap_with_primary as primary, wrap_with_warning as warning, \
is_obj_attr_has, is_obj_attr_eq, sort_assets, TtyIOParser, \
ugettext as _
ugettext as _, get_logger
from .proxy import ProxyServer
logger = logging.getLogger(__file__)
logger = get_logger(__file__)
class InteractiveServer:
......
......@@ -2,13 +2,13 @@
# -*- coding: utf-8 -*-
#
import logging
import paramiko
import threading
import weakref
from .utils import get_logger
logger = logging.getLogger(__file__)
logger = get_logger(__file__)
class SSHInterface(paramiko.ServerInterface):
......
......@@ -4,43 +4,55 @@
import os
import logging
from logging import StreamHandler
from logging.handlers import TimedRotatingFileHandler
LOG_LEVELS = {
'DEBUG': logging.DEBUG,
'INFO': logging.INFO,
'WARN': logging.WARNING,
'WARNING': logging.WARNING,
'ERROR': logging.ERROR,
'FATAL': logging.FATAL,
'CRITICAL': logging.CRITICAL,
}
from logging.config import dictConfig
def create_logger(app):
level = app.config['LOG_LEVEL']
level = LOG_LEVELS.get(level, logging.INFO)
log_dir = app.config.get('LOG_DIR')
log_path = os.path.join(log_dir, 'coco.log')
main_setting = {
'handlers': ['console', 'file'],
'level': level,
'propagate': False,
}
config = dict(
version=1,
formatters={
"main": {
'format': '%(asctime)s [%(module)s %(levelname)s] %(message)s',
'datefmt': '%Y-%m-%d %H:%M:%S',
},
'simple': {
'format': '%(asctime)s [%(levelname)-8s] %(message)s',
'datefmt': '%Y-%m-%d %H:%M:%S',
}
},
handlers={
'null': {
'level': 'DEBUG',
'class': 'logging.NullHandler',
},
'console': {
'level': 'DEBUG',
'class': 'logging.StreamHandler',
'formatter': 'main'
},
'file': {
'level': 'DEBUG',
'class': 'logging.FileHandler',
'formatter': 'main',
'filename': log_path,
},
},
loggers={
'coco': main_setting,
'paramiko': main_setting,
}
)
dictConfig(config)
logger = logging.getLogger()
return logger
main_formatter = logging.Formatter(
fmt='%(asctime)s [%(module)s %(levelname)s] %(message)s',
datefmt='%Y-%m-%d %H:%M:%S'
)
# main_formatter = logging.Formatter(
# fmt='%(asctime)s [%(levelname)s] %(message)s',
# datefmt='%Y-%m-%d %H:%M:%S'
# )
console_handler = StreamHandler()
file_handler = TimedRotatingFileHandler(
filename=log_path, when='D', backupCount=10
)
for handler in [console_handler, file_handler]:
handler.setFormatter(main_formatter)
logger.addHandler(handler)
logger.setLevel(level)
logging.getLogger("requests").setLevel(logging.WARNING)
......@@ -2,14 +2,13 @@
# -*- coding: utf-8 -*-
import threading
import datetime
import logging
import weakref
from . import char
from . import utils
BUF_SIZE = 4096
logger = logging.getLogger(__file__)
logger = utils.get_logger(__file__)
class Request:
......
......@@ -4,7 +4,6 @@
import socket
import threading
import logging
import time
import weakref
import paramiko
......@@ -13,10 +12,10 @@ from paramiko.ssh_exception import SSHException
from .session import Session
from .models import Server
from .utils import wrap_with_line_feed as wr, wrap_with_warning as warning, \
get_private_key_fingerprint
get_private_key_fingerprint, get_logger
logger = logging.getLogger(__file__)
logger = get_logger(__file__)
TIMEOUT = 8
BUF_SIZE = 4096
......
......@@ -3,7 +3,6 @@
#
import abc
import logging
import threading
import time
import os
......@@ -13,9 +12,10 @@ import shutil
from jms_es_sdk import ESStore
from .utils import get_logger
from .alignment import MemoryQueue
logger = logging.getLogger(__file__)
logger = get_logger(__file__)
BUF_SIZE = 1024
......
......@@ -3,13 +3,14 @@
#
import threading
import uuid
import logging
import datetime
import selectors
import time
from .utils import get_logger
BUF_SIZE = 1024
logger = logging.getLogger(__file__)
logger = get_logger(__file__)
class Session:
......
......@@ -3,20 +3,16 @@
#
import os
import logging
import socket
import threading
import paramiko
import sys
import time
from .utils import ssh_key_gen
from .utils import ssh_key_gen, get_logger
from .interface import SSHInterface
from .interactive import InteractiveServer
from .models import Client, Request
logger = logging.getLogger(__file__)
logger = get_logger(__file__)
BACKLOG = 5
......@@ -90,8 +86,6 @@ class SSHServer:
def handle_chan(self, chan, request):
client = Client(chan, request)
print(chan)
print(request)
self.app.add_client(client)
self.dispatch(client)
......
......@@ -2,9 +2,10 @@
# -*- coding: utf-8 -*-
#
import weakref
import logging
logger = logging.getLogger(__file__)
from .utils import get_logger
logger = get_logger(__file__)
class TaskHandler:
......
......@@ -5,6 +5,7 @@
from __future__ import unicode_literals
import hashlib
import logging
import re
import os
import threading
......@@ -371,4 +372,8 @@ def compile_message():
pass
def get_logger(file_name):
return logging.getLogger('coco.'+file_name)
ugettext = _gettext()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment