Skip to content

Commit

Permalink
got rid of an extra config file in favor of a dict config. made conso…
Browse files Browse the repository at this point in the history
…le logging the default. fixed flake8 suggestions
  • Loading branch information
Matthew Zizzi committed Sep 7, 2014
1 parent 6b25494 commit 775af7c
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 14 deletions.
8 changes: 6 additions & 2 deletions server/linux_x11/config.py.example
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ ENABLE_XSEL = False
# input issues. Obviously this setting does not apply when ENABLE_XSEL = True.
XDOTOOL_DELAY = 0

# Server log file. To enable file based logging please copy
# logging.config.example to logging.config and edit as noted.
# Server log file path
#LOG_FILE = '/path/to/server.log'

# Logger verbosity settings. See the following for a list of levels:
# https://docs.python.org/2/library/logging.html#levels
#CONSOLE_LOG_LEVEL = 'DEBUG'
#FILE_LOG_LEVEL = 'DEBUG'
48 changes: 48 additions & 0 deletions server/linux_x11/server_logging.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
DEFAULT_CONFIG = {
'version': 1,
'formatters': {
'generic': {
'format': '%(asctime)s [%(levelname)-6s] [%(name)-s] %(message)s'
}
},
'handlers': {
'console': {
'class': 'logging.StreamHandler',
'level': 'DEBUG',
'formatter': 'generic'
}
},
'loggers': {
'root': {
'level': 'DEBUG',
'handlers': [],
'propagate': True
},
'server': {
'level': 'DEBUG',
'handlers': ['console']
}
}
}


def make_logging_config(aenea_config):
log_file = getattr(aenea_config, 'LOG_FILE', None)
console_level = getattr(aenea_config, 'CONSOLE_LOG_LEVEL', 'DEBUG')
file_level = getattr(aenea_config, 'FILE_LOG_LEVEL', 'DEBUG')

logging_config = DEFAULT_CONFIG.copy()
logging_config['handlers']['console']['level'] = console_level

if log_file is not None:
logging_config['handlers']['file'] = {
'class': 'logging.handlers.RotatingFileHandler',
'formatter': 'generic',
'level': file_level,
'filename': log_file,
'mode': 'a',
'backupCount': 3
}
logging_config['loggers']['server']['handlers'].append('file')

return logging_config
20 changes: 8 additions & 12 deletions server/linux_x11/server_x11.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,13 @@
setattr(config, 'XDOTOOL_DELAY', 0)

import logging.config
import server_logging

try:
log_file = '/dev/null' if not hasattr(config, 'LOG_FILE') else config.LOG_FILE
logging.config.fileConfig(
os.path.join(os.path.dirname(__file__), 'logging.config'),
defaults={'log_file': log_file},
disable_existing_loggers=False
)
logging_config = server_logging.make_logging_config(config)
logging.config.dictConfig(logging_config)
except Exception, e:
print 'Failed to load logging configuration. Please copy ' \
'logging.config.example to logging.config for server' \
' logging support.'
print 'Failed to initialize logging support. Error: %s' % e

import logging
logger = logging.getLogger('server')
Expand Down Expand Up @@ -365,6 +361,7 @@ def write_text(text, paste=False, _xdotool=None):
arguments='type --file - --delay %d' % config.XDOTOOL_DELAY
)


def click_mouse(
button,
direction='click',
Expand All @@ -390,7 +387,7 @@ def click_mouse(
button = int(button)

command = ('%s %s %s %s' %
(_MOUSE_CLICKS[direction], delay, repeat, button))
(_MOUSE_CLICKS[direction], delay, repeat, button))

if _xdotool is not None:
_xdotool.append(command)
Expand Down Expand Up @@ -503,11 +500,10 @@ def setup_server(host, port):
ctx = get_context()
try:
import pprint
pprint.pprint(ctx)
logger.info(pprint.pformat(ctx))
except ImportError, e:
logger.error('failed to pretty print context. error:%s' % e)


else:
if '-d' in sys.argv or '--daemon' in sys.argv:
if os.fork() == 0:
Expand Down

0 comments on commit 775af7c

Please sign in to comment.