Commit f6d38d37 by Bach Dániel

fix logging

parent 3cf8491e
import logging
from logging.handlers import NTEventLogHandler
import os
import servicemanager
import socket
import sys
import win32event
import win32service
import win32serviceutil
......@@ -9,12 +11,14 @@ import win32serviceutil
from agent import main as agent_main, reactor
logger = logging.getLogger()
fh = logging.FileHandler(
os.path.join(os.path.dirname(__file__), "agent-service.log"))
fh = NTEventLogHandler(
"CIRCLE Agent", dllname=os.path.dirname(__file__))
formatter = logging.Formatter(
"%(asctime)s - %(name)s [%(levelname)s] %(message)s")
fh.setFormatter(formatter)
logger.addHandler(fh)
level = os.environ.get('LOGLEVEL', 'INFO')
logger.setLevel(level)
logger.info("%s loaded", __file__)
......
......@@ -13,7 +13,7 @@ import platform
import sys
import tarfile
from os.path import expanduser, join, exists
from os import mkdir
from os import mkdir, environ
from glob import glob
from StringIO import StringIO
from base64 import decodestring
......@@ -25,7 +25,11 @@ from utils import SerialLineReceiverBase
from ssh import PubKey
logging.basicConfig()
logger = logging.getLogger()
level = environ.get('LOGLEVEL', 'INFO')
logger.setLevel(level)
SSH_DIR = expanduser('~cloud/.ssh')
AUTHORIZED_KEYS = join(SSH_DIR, 'authorized_keys')
......
......@@ -2,8 +2,7 @@ from twisted.protocols.basic import LineReceiver
import json
import logging
root_logger = logging.getLogger()
root_logger.setLevel(logging.DEBUG)
logger = logging.getLogger()
class SerialLineReceiverBase(LineReceiver, object):
......@@ -31,17 +30,17 @@ class SerialLineReceiverBase(LineReceiver, object):
args = {}
command = data.get('command', None)
response = data.get('response', None)
logging.debug('[serial] valid json: %s' % (data, ))
logger.debug('[serial] valid json: %s' % (data, ))
except (ValueError, KeyError) as e:
logging.error('[serial] invalid json: %s (%s)' % (data, e))
logger.error('[serial] invalid json: %s (%s)' % (data, e))
return
if command is not None and isinstance(command, unicode):
logging.debug('received command: %s (%s)' % (command, args))
logger.debug('received command: %s (%s)' % (command, args))
try:
self.handle_command(command, args)
except Exception as e:
logging.exception(u'Unhandled exception: ')
logger.exception(u'Unhandled exception: ')
elif response is not None and isinstance(response, unicode):
logging.debug('received reply: %s (%s)' % (response, args))
logger.debug('received reply: %s (%s)' % (response, args))
self.handle_response(response, args)
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 sign in to comment