Commit 9a7e39d9 authored by Grégory Wisniewski's avatar Grégory Wisniewski

Add application name (configuration section) in log messages to help debugging

when mixing all application logs: 'cat *.log | sort | less' is helpfull.


git-svn-id: https://svn.erp5.org/repos/neo/branches/prototype3@865 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 669eb3ac
DEFAULT_LOG_FORMAT = '%(asctime)s [%(module)12s:%(lineno)3d] %(levelname)8s: %(message)s'
DEFAULT_FORMAT = ' [%(module)14s:%(lineno)3d] %(levelname)8s: %(message)s'
def buildFormatString(app_name):
app_name = '%-8s' % app_name.upper()
return '%(asctime)s - ' + app_name + DEFAULT_FORMAT
......@@ -20,7 +20,6 @@ import logging
from neo.client.app import Application
from neo.client.exception import NEOStorageConflictError, NEOStorageNotFoundError
from neo import DEFAULT_LOG_FORMAT
class Storage(BaseStorage.BaseStorage,
ConflictResolution.ConflictResolvingStorage):
......@@ -31,7 +30,6 @@ class Storage(BaseStorage.BaseStorage,
def __init__(self, master_nodes, name, connector, read_only=False, **kw):
BaseStorage.BaseStorage.__init__(self, name)
self._is_read_only = read_only
logging.basicConfig(level=logging.DEBUG, format=DEFAULT_LOG_FORMAT)
self.app = Application(master_nodes, name, connector)
def load(self, oid, version=None):
......
......@@ -217,8 +217,10 @@ class Application(object):
"""The client node application."""
def __init__(self, master_nodes, name, connector, **kw):
logging.basicConfig(level = logging.DEBUG)
logging.debug('master node address are %s' %(master_nodes,))
# XXX: use a configuration entry
from neo import buildFormatString
format = buildFormatString('CLIENT')
logging.basicConfig(level=logging.DEBUG, format=format)
em = EventManager()
# Start polling thread
self.poll_thread = ThreadedPoll(em)
......@@ -234,6 +236,7 @@ class Application(object):
self.primary_master_node = None
self.trying_master_node = None
# XXX: this code duplicates neo.config.ConfigurationManager.getMasterNodeList
logging.debug('master node address are %s' % (master_nodes,))
self.master_node_list = master_node_list = []
for node in master_nodes.split():
if not node:
......
......@@ -204,9 +204,11 @@ s1_log = os.path.join(temp_dir, 's1.log')
s2_log = os.path.join(temp_dir, 's2.log')
s3_log = os.path.join(temp_dir, 's3.log')
s4_log = os.path.join(temp_dir, 's4.log')
# override logging default handler
from neo import buildFormatString
client_log = os.path.join(temp_dir, 'c.log')
from neo import DEFAULT_LOG_FORMAT
logging.basicConfig(filename=client_log, level=logging.DEBUG, format=DEFAULT_LOG_FORMAT)
format = buildFormatString('CLIENT')
logging.basicConfig(filename=client_log, level=logging.DEBUG, format=format)
class ZODBTests(unittest.TestCase):
......
......@@ -20,7 +20,7 @@
from optparse import OptionParser
from neo.admin.app import Application
from neo import DEFAULT_LOG_FORMAT
from neo import buildFormatString
import logging
parser = OptionParser()
parser.add_option('-v', '--verbose', action = 'store_true',
......@@ -35,10 +35,11 @@ config = options.config or 'neo.conf'
section = options.section or 'admin'
logfile = options.logfile or None
format = buildFormatString(section)
if options.verbose:
logging.basicConfig(filename=logfile, level=logging.DEBUG, format=DEFAULT_LOG_FORMAT)
logging.basicConfig(filename=logfile, level=logging.DEBUG, format=format)
else:
logging.basicConfig(filename=logfile, level=logging.INFO, format=DEFAULT_LOG_FORMAT)
logging.basicConfig(filename=logfile, level=logging.INFO, format=format)
app = Application(config, section)
app.run()
......@@ -20,7 +20,7 @@
from optparse import OptionParser
from neo.neoctl.app import Application
from neo import DEFAULT_LOG_FORMAT
from neo import buildFormatString
import logging
parser = OptionParser()
parser.add_option('-v', '--verbose', action = 'store_true',
......@@ -36,10 +36,11 @@ port = options.port or 5555
ip = options.ip or '127.0.0.1'
handler = options.handler or "SocketConnector"
format = buildFormatString('neoctl')
if options.verbose:
logging.basicConfig(level=logging.DEBUG, format=DEFAULT_LOG_FORMAT)
logging.basicConfig(level=logging.DEBUG, format=format)
else:
logging.basicConfig(level=logging.INFO, format=DEFAULT_LOG_FORMAT)
logging.basicConfig(level=logging.INFO, format=format)
app = Application(ip, port, handler)
......
......@@ -20,7 +20,7 @@
from optparse import OptionParser
from neo.master.app import Application
from neo import DEFAULT_LOG_FORMAT
from neo import buildFormatString
import logging
......@@ -37,10 +37,11 @@ config = options.config or 'neo.conf'
section = options.section or 'master'
logfile = options.logfile or None
format = buildFormatString(section)
if options.verbose:
logging.basicConfig(filename=logfile, level=logging.DEBUG, format=DEFAULT_LOG_FORMAT)
logging.basicConfig(filename=logfile, level=logging.DEBUG, format=format)
else:
logging.basicConfig(filename=logfile, level=logging.WARNING, format=DEFAULT_LOG_FORMAT)
logging.basicConfig(filename=logfile, level=logging.WARNING, format=format)
app = Application(config, section)
app.run()
......@@ -20,7 +20,7 @@
from optparse import OptionParser
from neo.storage.app import Application
from neo import DEFAULT_LOG_FORMAT
from neo import buildFormatString
import logging
......@@ -39,10 +39,11 @@ config = options.config or 'neo.conf'
section = options.section or 'storage'
logfile = options.logfile or None
format = buildFormatString(section)
if options.verbose:
logging.basicConfig(filename=logfile, level=logging.DEBUG, format=DEFAULT_LOG_FORMAT)
logging.basicConfig(filename=logfile, level=logging.DEBUG, format=format)
else:
logging.basicConfig(filename=logfile, level=logging.WARNING, format=DEFAULT_LOG_FORMAT)
logging.basicConfig(filename=logfile, level=logging.WARNING, format=format)
app = Application(config, section, options.reset)
app.run()
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