Skip to content

Commit

Permalink
Merge pull request tableau#103 from evaliula/master
Browse files Browse the repository at this point in the history
added two configurable rolling log handlers
  • Loading branch information
0golovatyi authored Jun 22, 2018
2 parents 34ebad3 + fa0d88c commit 5005e2a
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 10 deletions.
9 changes: 9 additions & 0 deletions tabpy-client/tabpy_client/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@

import json as json

from common.tabpy_logging import (
PYLogging,
log_error,
log_info,
log_debug,
log_warning,
)
PYLogging.initialize(_logger)

class ResponseError(Exception):
"""Raised when we get an unexpected response."""

Expand Down
3 changes: 2 additions & 1 deletion tabpy-server/tabpy_server/common/config.py.template
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ TABPY_QUERY_OBJECT_PATH = '/tmp/query_objects'
TABPY_PORT = 9004
TABPY_SERVER_VERSION = 'Alpha'
TABPY_STATE_PATH = './'
TABPY_BIND_IP = '0.0.0.0'
TABPY_BIND_IP = '0.0.0.0'
TABPY_LOG_LEVEL = 'INFO'
2 changes: 1 addition & 1 deletion tabpy-server/tabpy_server/common/endpoint_file_mgr.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from common.tabpy_logging import PYLogging, log_error, log_info, log_debug, log_warning

import logging
logging.basicConfig(level=logging.ERROR)

logger = logging.getLogger(__name__)
PYLogging.initialize(logger)

Expand Down
2 changes: 1 addition & 1 deletion tabpy-server/tabpy_server/common/messages.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import simplejson
import json as simplejson
import abc
from abc import ABCMeta
from collections import namedtuple
Expand Down
28 changes: 26 additions & 2 deletions tabpy-server/tabpy_server/common/tabpy_logging.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,32 @@
import simplejson
class PYLogging(object):
import json as simplejson
import logging
from logging import handlers
import tempfile
import os

if os.path.isfile('./common/config.py'):
import common.config as config
LOG_LEVEL = config.TABPY_LOG_LEVEL
else:
LOG_LEVEL = "INFO"

class PYLogging(object):
@classmethod
def initialize(cls, logger):
cls.logger = logger
cls.logger.setLevel = logging.getLevelName(LOG_LEVEL)

# create formatter
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
temp_dir = tempfile.gettempdir()

fh = handlers.RotatingFileHandler(filename=os.path.join(temp_dir, "tabpy_log.log"),
maxBytes=10000000, backupCount=5)
fh.setLevel(LOG_LEVEL)
fh.setFormatter(formatter)

# add fh to logger
logger.addHandler(fh)


def log_error(msg, **kwargs):
Expand Down
3 changes: 1 addition & 2 deletions tabpy-server/tabpy_server/management/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from StringIO import StringIO
except ImportError:
from io import StringIO
import simplejson
import json as simplejson
from threading import Lock
from time import time
import sys
Expand All @@ -16,7 +16,6 @@
from common.tabpy_logging import PYLogging, log_error, log_info, log_debug, log_warning

import logging
logging.basicConfig(level=logging.ERROR)
logger = logging.getLogger(__name__)
PYLogging.initialize(logger)

Expand Down
1 change: 0 additions & 1 deletion tabpy-server/tabpy_server/management/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

from common.tabpy_logging import PYLogging, log_error, log_info, log_debug, log_warning
import logging
logging.basicConfig(level=logging.ERROR)
logger = logging.getLogger(__name__)
PYLogging.initialize(logger)

Expand Down
1 change: 0 additions & 1 deletion tabpy-server/tabpy_server/psws/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from common.tabpy_logging import PYLogging, log_error, log_info, log_debug, log_warning

import logging
logging.basicConfig(level=logging.ERROR)
logger = logging.getLogger(__name__)
PYLogging.initialize(logger)

Expand Down
2 changes: 1 addition & 1 deletion tabpy-server/tabpy_server/psws/python_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
)

import logging
logging.basicConfig(level=logging.ERROR)
logger = logging.getLogger(__name__)

PYLogging.initialize(logger)

if sys.version_info.major == 3:
Expand Down

0 comments on commit 5005e2a

Please sign in to comment.