Commit db6fcb9b authored by Grégory Wisniewski's avatar Grégory Wisniewski

Use a named logger and define it in the root module.


git-svn-id: https://svn.erp5.org/repos/neo/branches/prototype3@1032 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 1b82f1e4
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
#
# Copyright (C) 2006-2009 Nexedi SA
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
import logging as logging_std
# default logger
logging = logging_std.getLogger('NEO')
PREFIX = '%(asctime)s %(levelname)-9s %(name)-8s'
SUFFIX = ' [%(module)14s:%(lineno)3d] %(message)s'
def setupLog(name='NEO', filename=None, verbose=False):
global logging
if verbose:
level = logging_std.DEBUG
else:
level = logging_std.INFO
format = PREFIX + SUFFIX
logging_std.basicConfig(filename=filename, level=level, format=format)
logging = logging_std.getLogger(name.upper())
......@@ -15,7 +15,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
import logging
from neo import logging
from neo.config import ConfigurationManager
from neo.node import NodeManager, MasterNode
......
......@@ -15,7 +15,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
import logging
from neo import logging
from neo.handler import EventHandler
from neo.node import StorageNode
......
......@@ -15,7 +15,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
import logging
from neo import logging
from time import sleep
from neo.handler import EventHandler
......
......@@ -15,7 +15,6 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
import logging
from thread import get_ident
from cPickle import dumps
from zlib import compress, decompress
......@@ -25,6 +24,10 @@ from time import sleep
from ZODB.POSException import UndoError, StorageTransactionError, ConflictError
from neo import setupLog
setupLog('CLIENT', verbose=True)
from neo import logging
from neo import protocol
from neo.event import EventManager
from neo.util import makeChecksum, dump
......@@ -235,9 +238,6 @@ class Application(object):
def __init__(self, master_nodes, name, connector, **kw):
# XXX: use a configuration entry
from neo import buildFormatString
fmt = buildFormatString('CLIENT')
logging.basicConfig(level=logging.DEBUG, format=fmt)
em = EventManager()
# Start polling thread
self.poll_thread = ThreadedPoll(em)
......
......@@ -15,7 +15,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
import logging
from neo import logging
from neo.client.handlers import BaseHandler, AnswerBaseHandler
from neo.protocol import MASTER_NODE_TYPE, STORAGE_NODE_TYPE, \
......
......@@ -15,7 +15,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
import logging
from neo import logging
from ZODB.TimeStamp import TimeStamp
from neo.client.handlers import BaseHandler, AnswerBaseHandler
......
......@@ -16,7 +16,7 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
from threading import Thread, Event
import logging
from neo import logging
class ThreadedPoll(Thread):
"""Polling thread."""
......
......@@ -16,7 +16,7 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
from ConfigParser import SafeConfigParser
import logging
from neo import logging
class ConfigurationManager:
"""This class provides support for parsing a configuration file."""
......
......@@ -15,7 +15,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
import logging
from neo import logging
from neo.locking import RLock
from neo import protocol
......
......@@ -17,7 +17,7 @@
import socket
import errno
import logging
from neo import logging
# Global connector registry.
# Fill by calling registerConnectorHandler.
......
......@@ -15,7 +15,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
import logging
from neo import logging
from select import select
from time import time
......
......@@ -15,7 +15,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
import logging
from neo import logging
from neo import protocol
from neo.protocol import PacketMalformedError, UnexpectedPacketError, \
......
......@@ -15,7 +15,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
import logging
from neo import logging
import os, sys
from time import time, gmtime
from struct import pack, unpack
......@@ -400,6 +400,7 @@ class Application(object):
# collect the last partition table available
while self.cluster_state == protocol.RECOVERING:
self.changeClusterState(protocol.VERIFYING)
em.poll(1)
logging.info('startup allowed')
......
......@@ -15,7 +15,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
import logging
from neo import logging
from neo import protocol
from neo.handler import EventHandler
......
......@@ -15,7 +15,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
import logging
from neo import logging
from neo import protocol
from neo.master.handlers import MasterHandler
......
......@@ -15,7 +15,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
import logging
from neo import logging
from neo import protocol
from neo.protocol import HIDDEN_STATE
......
......@@ -15,7 +15,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
import logging
from neo import logging
from neo import protocol
from neo.protocol import MASTER_NODE_TYPE, \
......
......@@ -15,7 +15,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
import logging
from neo import logging
from neo import protocol
from neo.master.handlers import MasterHandler
......
......@@ -15,7 +15,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
import logging
from neo import logging
from neo import protocol
from neo.master.handlers import MasterHandler
......
......@@ -15,7 +15,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
import logging
from neo import logging
from neo.protocol import MASTER_NODE_TYPE, \
RUNNING_STATE, BROKEN_STATE, DOWN_STATE
......
......@@ -15,7 +15,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
import logging
from neo import logging
from neo import protocol
from neo.protocol import CLIENT_NODE_TYPE
from neo.master.handlers import BaseServiceHandler
......
......@@ -15,7 +15,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
import logging
from neo import logging
from neo import protocol
from neo.protocol import UP_TO_DATE_STATE, FEEDING_STATE, \
......
......@@ -15,7 +15,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
import logging
from neo import logging
from neo.master.handlers import MasterHandler
from neo.exception import VerificationFailure
......
......@@ -16,7 +16,7 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
from time import time
import logging
from neo import logging
from neo import protocol
from neo.protocol import RUNNING_STATE, TEMPORARILY_DOWN_STATE, DOWN_STATE, \
......
......@@ -15,7 +15,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
import logging
from neo import logging
from neo.protocol import UP_TO_DATE_STATE, OUT_OF_DATE_STATE, FEEDING_STATE, \
DISCARDED_STATE, RUNNING_STATE, TEMPORARILY_DOWN_STATE, DOWN_STATE, \
......
......@@ -15,7 +15,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
import logging
from neo import logging
import sys
from collections import deque
......
......@@ -15,7 +15,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
import logging
from neo import logging
from neo.handler import EventHandler
from neo import protocol
......
......@@ -15,7 +15,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
import logging
from neo import logging
from neo import protocol
from neo.storage.handlers import BaseClientAndStorageOperationHandler
......
......@@ -15,7 +15,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
import logging
from neo import logging
from neo.storage.handlers import BaseMasterHandler
from neo.protocol import BROKEN_STATE, STORAGE_NODE_TYPE, DOWN_STATE, \
......
......@@ -15,7 +15,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
import logging
from neo import logging
from neo.storage.handlers import BaseStorageHandler
from neo import protocol
......
......@@ -15,7 +15,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
import logging
from neo import logging
from neo.storage.handlers import BaseMasterHandler
from neo.protocol import TEMPORARILY_DOWN_STATE
......
......@@ -15,7 +15,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
import logging
from neo import logging
from neo import protocol
from neo.storage.handlers import BaseMasterHandler
......
......@@ -16,7 +16,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
import logging
from neo import logging
from neo.storage.handlers import BaseStorageHandler
from neo import protocol
......
......@@ -15,7 +15,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
import logging
from neo import logging
from neo.storage.handlers import BaseMasterHandler
from neo import protocol
......
......@@ -18,7 +18,7 @@
import MySQLdb
from MySQLdb import OperationalError
from MySQLdb.constants.CR import SERVER_GONE_ERROR, SERVER_LOST
import logging
from neo import logging
from array import array
import string
from struct import pack, unpack
......
......@@ -15,7 +15,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
import logging
from neo import logging
from random import choice
from neo.storage.handlers import replication
......
......@@ -19,7 +19,7 @@ import os
import unittest
import tempfile
import MySQLdb
import logging
from neo import logging
from mock import Mock
from neo import protocol
......
......@@ -16,7 +16,7 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
import unittest
import logging
from neo import logging
import threading
from mock import Mock, ReturnValues
from neo.tests import NeoTestBase
......
......@@ -23,12 +23,10 @@ from persistent import Persistent
from persistent.mapping import PersistentMapping
import transaction
from neo.client.Storage import Storage
import os
import sys
import signal
import MySQLdb
import logging
import tempfile
import traceback
......@@ -204,11 +202,13 @@ 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
from neo import setupLog
client_log = os.path.join(temp_dir, 'c.log')
format = buildFormatString('CLIENT')
logging.basicConfig(filename=client_log, level=logging.DEBUG, format=format)
setupLog('CLIENT', filename=client_log, verbose=True)
from neo import logging
from neo.client.Storage import Storage
class ZODBTests(unittest.TestCase):
......
......@@ -17,7 +17,7 @@
import os
import unittest
import logging
from neo import logging
from mock import Mock
from struct import pack, unpack
from neo.tests import NeoTestBase
......
......@@ -17,7 +17,7 @@
import os
import unittest
import logging
from neo import logging
from mock import Mock
from struct import pack, unpack
from neo.tests import NeoTestBase
......
......@@ -17,7 +17,7 @@
import os
import unittest
import logging
from neo import logging
from mock import Mock
from struct import pack, unpack
from neo.tests import NeoTestBase
......
......@@ -17,7 +17,7 @@
import os
import unittest
import logging
from neo import logging
from mock import Mock
from struct import pack, unpack
from neo.tests import NeoTestBase
......
......@@ -17,7 +17,7 @@
import os
import unittest
import logging
from neo import logging
from mock import Mock
from struct import pack, unpack
import neo
......
......@@ -17,7 +17,7 @@
import os
import unittest
import logging
from neo import logging
from struct import pack, unpack
from mock import Mock
from collections import deque
......
......@@ -17,7 +17,7 @@
import os
import unittest
import logging
from neo import logging
from mock import Mock
from neo.tests import NeoTestBase
from neo import protocol
......
......@@ -17,7 +17,7 @@
import os
import unittest
import logging
from neo import logging
from struct import pack, unpack
from mock import Mock
from collections import deque
......
......@@ -17,7 +17,7 @@
import os
import unittest
import logging
from neo import logging
from struct import pack, unpack
from mock import Mock
from collections import deque
......
......@@ -17,7 +17,7 @@
import os
import unittest
import logging
from neo import logging
import MySQLdb
from mock import Mock
from neo.protocol import *
......
......@@ -17,7 +17,7 @@
import os
import unittest
import logging
from neo import logging
from mock import Mock
from neo.tests import NeoTestBase
from neo import protocol
......
......@@ -17,7 +17,7 @@
import os
import unittest
import logging
from neo import logging
from mock import Mock
from neo.tests import NeoTestBase
from neo.master.app import MasterNode
......
......@@ -19,9 +19,8 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
from optparse import OptionParser
from neo.admin.app import Application
from neo import buildFormatString
import logging
from neo import setupLog
parser = OptionParser()
parser.add_option('-v', '--verbose', action = 'store_true',
help = 'print verbose messages')
......@@ -30,16 +29,12 @@ parser.add_option('-s', '--section', help = 'specify a configuration section')
parser.add_option('-l', '--logfile', help = 'specify a logging file')
(options, args) = parser.parse_args()
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=format)
else:
logging.basicConfig(filename=logfile, level=logging.INFO, format=format)
logfile = options.logfile or None
setupLog(section, logfile, options.verbose)
from neo.admin.app import Application
app = Application(config, section)
app.run()
......@@ -19,10 +19,7 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
from optparse import OptionParser
from neo.master.app import Application
from neo import buildFormatString
import logging
from neo import setupLog
parser = OptionParser()
parser.add_option('-v', '--verbose', action = 'store_true',
......@@ -32,16 +29,12 @@ parser.add_option('-s', '--section', help = 'specify a configuration section')
parser.add_option('-l', '--logfile', help = 'specify a logging file')
(options, args) = parser.parse_args()
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=format)
else:
logging.basicConfig(filename=logfile, level=logging.WARNING, format=format)
logfile = options.logfile or None
setupLog(section, logfile, options.verbose)
from neo.master.app import Application
app = Application(config, section)
app.run()
......@@ -19,9 +19,7 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
from optparse import OptionParser
from neo.storage.app import Application
from neo import buildFormatString
import logging
from neo import setupLog
parser = OptionParser()
......@@ -34,16 +32,12 @@ parser.add_option('-R', '--reset', action = 'store_true',
help = 'remove an existing database if any')
(options, args) = parser.parse_args()
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=format)
else:
logging.basicConfig(filename=logfile, level=logging.WARNING, format=format)
logfile = options.logfile or None
setupLog(section, logfile, options.verbose)
from neo.storage.app import Application
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