ENH: Tweak naming of getF2BLogger, and ensure consistent use

pull/701/head
Steven Hiscocks 2014-06-10 20:36:19 +01:00
parent f7da091437
commit 4fc7f1a831
35 changed files with 80 additions and 80 deletions

View File

@ -30,9 +30,10 @@ from fail2ban.protocol import printFormatted
from fail2ban.client.csocket import CSocket
from fail2ban.client.configurator import Configurator
from fail2ban.client.beautifier import Beautifier
from fail2ban.helpers import getLogger
# Gets the instance of the logger.
logSys = logging.getLogger("fail2ban")
logSys = getLogger("fail2ban")
##
#

View File

@ -45,9 +45,9 @@ from fail2ban.client.filterreader import FilterReader
from fail2ban.server.filter import Filter
from fail2ban.server.failregex import RegexException
from fail2ban.helpers import FormatterWithTraceBack
from fail2ban.helpers import FormatterWithTraceBack, getLogger
# Gets the instance of the logger.
logSys = logging.getLogger("fail2ban")
logSys = getLogger("fail2ban")
def debuggexURL(sample, regex):
q = urllib.urlencode({ 're': regex.replace('<HOST>', '(?&.ipv4)'),

View File

@ -22,13 +22,14 @@ __author__ = "Cyril Jaquier"
__copyright__ = "Copyright (c) 2004 Cyril Jaquier"
__license__ = "GPL"
import getopt, sys, logging, os
import getopt, sys, os
from fail2ban.version import version
from fail2ban.server.server import Server
from fail2ban.helpers import getLogger
# Gets the instance of the logger.
logSys = logging.getLogger("fail2ban")
logSys = getLogger("fail2ban")
##
# \mainpage Fail2Ban

View File

@ -25,7 +25,7 @@ __copyright__ = "Copyright (c) 2004 Cyril Jaquier, 2012- Yaroslav Halchenko"
__license__ = "GPL"
import unittest, logging, sys, time, os
import unittest, sys, time, os
# Check if local fail2ban module exists, and use if it exists by
# modifying the path. This is such that tests can be used in dev
@ -35,7 +35,7 @@ if os.path.exists("fail2ban/__init__.py"):
from fail2ban.version import version
from fail2ban.tests.utils import gatherTests
from fail2ban.helpers import FormatterWithTraceBack
from fail2ban.helpers import FormatterWithTraceBack, getLogger
from fail2ban.server.mytime import MyTime
from optparse import OptionParser, Option
@ -70,7 +70,7 @@ parser = get_opt_parser()
#
# Logging
#
logSys = logging.getLogger("fail2ban")
logSys = getLogger("fail2ban")
# Numerical level of verbosity corresponding to a log "level"
verbosity = {'heavydebug': 4,

View File

@ -27,10 +27,10 @@ __license__ = "GPL"
import os
from .configreader import ConfigReader, DefinitionInitConfigReader
from ..helpers import getF2BLogger
from ..helpers import getLogger
# Gets the instance of the logger.
logSys = getF2BLogger(__name__)
logSys = getLogger(__name__)
class ActionReader(DefinitionInitConfigReader):

View File

@ -22,10 +22,10 @@ __copyright__ = "Copyright (c) 2004 Cyril Jaquier, 2013- Yaroslav Halchenko"
__license__ = "GPL"
from ..exceptions import UnknownJailException, DuplicateJailException
from ..helpers import getF2BLogger
from ..helpers import getLogger
# Gets the instance of the logger.
logSys = getF2BLogger(__name__)
logSys = getLogger(__name__)
##
# Beautify the output of the client.

View File

@ -25,7 +25,7 @@ __copyright__ = 'Copyright (c) 2007 Yaroslav Halchenko'
__license__ = 'GPL'
import os, sys
from ..helpers import getF2BLogger
from ..helpers import getLogger
if sys.version_info >= (3,2): # pragma: no cover
@ -61,7 +61,7 @@ else: # pragma: no cover
from ConfigParser import SafeConfigParser
# Gets the instance of the logger.
logSys = getF2BLogger(__name__)
logSys = getLogger(__name__)
__all__ = ['SafeConfigParserWithIncludes']

View File

@ -28,10 +28,10 @@ import glob, os
from ConfigParser import NoOptionError, NoSectionError
from .configparserinc import SafeConfigParserWithIncludes
from ..helpers import getF2BLogger
from ..helpers import getLogger
# Gets the instance of the logger.
logSys = getF2BLogger(__name__)
logSys = getLogger(__name__)
class ConfigReader(SafeConfigParserWithIncludes):

View File

@ -26,10 +26,10 @@ __license__ = "GPL"
from .fail2banreader import Fail2banReader
from .jailsreader import JailsReader
from ..helpers import getF2BLogger
from ..helpers import getLogger
# Gets the instance of the logger.
logSys = getF2BLogger(__name__)
logSys = getLogger(__name__)
class Configurator:

View File

@ -25,10 +25,10 @@ __copyright__ = "Copyright (c) 2004 Cyril Jaquier"
__license__ = "GPL"
from .configreader import ConfigReader
from ..helpers import getF2BLogger
from ..helpers import getLogger
# Gets the instance of the logger.
logSys = getF2BLogger(__name__)
logSys = getLogger(__name__)
class Fail2banReader(ConfigReader):

View File

@ -28,10 +28,10 @@ import os, shlex
from .configreader import ConfigReader, DefinitionInitConfigReader
from ..server.action import CommandAction
from ..helpers import getF2BLogger
from ..helpers import getLogger
# Gets the instance of the logger.
logSys = getF2BLogger(__name__)
logSys = getLogger(__name__)
class FilterReader(DefinitionInitConfigReader):

View File

@ -30,10 +30,10 @@ import json
from .configreader import ConfigReader
from .filterreader import FilterReader
from .actionreader import ActionReader
from ..helpers import getF2BLogger
from ..helpers import getLogger
# Gets the instance of the logger.
logSys = getF2BLogger(__name__)
logSys = getLogger(__name__)
class JailReader(ConfigReader):

View File

@ -26,10 +26,10 @@ __license__ = "GPL"
from .configreader import ConfigReader
from .jailreader import JailReader
from ..helpers import getF2BLogger
from ..helpers import getLogger
# Gets the instance of the logger.
logSys = getF2BLogger(__name__)
logSys = getLogger(__name__)
class JailsReader(ConfigReader):

View File

@ -108,7 +108,7 @@ class FormatterWithTraceBack(logging.Formatter):
record.tbc = record.tb = self._tb()
return logging.Formatter.format(self, record)
def getF2BLogger(name):
def getLogger(name):
"""Get logging.Logger instance with Fail2Ban logger name convention
"""
return logging.getLogger("fail2ban.%s" % name.rpartition(".")[-1])
@ -116,6 +116,6 @@ def getF2BLogger(name):
def fail2ban_excepthook(exctype, value, traceback):
"""Except hook used to log unhandled exceptions to Fail2Ban log
"""
logging.getLogger("fail2ban").critical(
getLogger("fail2ban").critical(
"Unhandled exception in Fail2Ban:", exc_info=True)
return sys.__excepthook__(exctype, value, traceback)

View File

@ -26,10 +26,10 @@ import threading, re
from abc import ABCMeta
from collections import MutableMapping
from ..helpers import getF2BLogger
from ..helpers import getLogger
# Gets the instance of the logger.
logSys = getF2BLogger(__name__)
logSys = getLogger(__name__)
# Create a lock for running system commands
_cmd_lock = threading.Lock()
@ -136,8 +136,7 @@ class ActionBase(object):
def __init__(self, jail, name):
self._jail = jail
self._name = name
self._logSys = logging.getLogger(
"fail2ban.%s" % self.__class__.__name__)
self._logSys = getLogger("fail2ban.%s" % self.__class__.__name__)
def start(self):
"""Executed when the jail/action is started.

View File

@ -41,10 +41,10 @@ from .banmanager import BanManager
from .jailthread import JailThread
from .action import ActionBase, CommandAction, CallingMap
from .mytime import MyTime
from ..helpers import getF2BLogger
from ..helpers import getLogger
# Gets the instance of the logger.
logSys = getF2BLogger(__name__)
logSys = getLogger(__name__)
class Actions(JailThread, Mapping):
"""Handles jail actions.

View File

@ -27,10 +27,10 @@ __license__ = "GPL"
from pickle import dumps, loads, HIGHEST_PROTOCOL
import asyncore, asynchat, socket, os, sys, traceback, fcntl
from ..helpers import getF2BLogger,formatExceptionInfo
from ..helpers import getLogger,formatExceptionInfo
# Gets the instance of the logger.
logSys = getF2BLogger(__name__)
logSys = getLogger(__name__)
if sys.version_info >= (3,):
# b"" causes SyntaxError in python <= 2.5, so below implements equivalent

View File

@ -28,10 +28,10 @@ from threading import Lock
from .ticket import BanTicket
from .mytime import MyTime
from ..helpers import getF2BLogger
from ..helpers import getLogger
# Gets the instance of the logger.
logSys = getF2BLogger(__name__)
logSys = getLogger(__name__)
##
# Banning Manager.

View File

@ -31,10 +31,10 @@ from threading import Lock
from .mytime import MyTime
from .ticket import FailTicket
from ..helpers import getF2BLogger
from ..helpers import getLogger
# Gets the instance of the logger.
logSys = getF2BLogger(__name__)
logSys = getLogger(__name__)
if sys.version_info >= (3,):
sqlite3.register_adapter(

View File

@ -24,10 +24,10 @@ __license__ = "GPL"
from threading import Lock
from .datetemplate import DatePatternRegex, DateTai64n, DateEpoch
from ..helpers import getF2BLogger
from ..helpers import getLogger
# Gets the instance of the logger.
logSys = getF2BLogger(__name__)
logSys = getLogger(__name__)
class DateDetector(object):
"""Manages one or more date templates to find a date within a log line.

View File

@ -28,9 +28,9 @@ import re
from abc import abstractmethod
from .strptime import reGroupDictStrptime, timeRE
from ..helpers import getF2BLogger
from ..helpers import getLogger
logSys = getF2BLogger(__name__)
logSys = getLogger(__name__)
class DateTemplate(object):

View File

@ -24,10 +24,10 @@ __author__ = "Cyril Jaquier"
__copyright__ = "Copyright (c) 2004 Cyril Jaquier"
__license__ = "GPL"
from ..helpers import getF2BLogger
from ..helpers import getLogger
# Gets the instance of the logger.
logSys = getF2BLogger(__name__)
logSys = getLogger(__name__)
class FailData:

View File

@ -29,10 +29,10 @@ import logging
from .faildata import FailData
from .ticket import FailTicket
from ..helpers import getF2BLogger
from ..helpers import getLogger
# Gets the instance of the logger.
logSys = getF2BLogger(__name__)
logSys = getLogger(__name__)
class FailManager:

View File

@ -31,10 +31,10 @@ from .datetemplate import DatePatternRegex, DateEpoch, DateTai64n
from .mytime import MyTime
from .failregex import FailRegex, Regex, RegexException
from .action import CommandAction
from ..helpers import getF2BLogger
from ..helpers import getLogger
# Gets the instance of the logger.
logSys = getF2BLogger(__name__)
logSys = getLogger(__name__)
##
# Log reader class.

View File

@ -30,10 +30,10 @@ import gamin
from .failmanager import FailManagerEmpty
from .filter import FileFilter
from .mytime import MyTime
from ..helpers import getF2BLogger
from ..helpers import getLogger
# Gets the instance of the logger.
logSys = getF2BLogger(__name__)
logSys = getLogger(__name__)
##
# Log reader class.

View File

@ -29,10 +29,10 @@ import time, os
from .failmanager import FailManagerEmpty
from .filter import FileFilter
from .mytime import MyTime
from ..helpers import getF2BLogger
from ..helpers import getLogger
# Gets the instance of the logger.
logSys = getF2BLogger(__name__)
logSys = getLogger(__name__)
##
# Log reader class.

View File

@ -32,7 +32,7 @@ import pyinotify
from .failmanager import FailManagerEmpty
from .filter import FileFilter
from .mytime import MyTime
from ..helpers import getF2BLogger
from ..helpers import getLogger
if not hasattr(pyinotify, '__version__') \
@ -49,7 +49,7 @@ except Exception, e:
% str(e))
# Gets the instance of the logger.
logSys = getF2BLogger(__name__)
logSys = getLogger(__name__)
##
# Log reader class.

View File

@ -32,10 +32,10 @@ if LooseVersion(getattr(journal, '__version__', "0")) < '204':
from .failmanager import FailManagerEmpty
from .filter import JournalFilter
from .mytime import MyTime
from ..helpers import getF2BLogger
from ..helpers import getLogger
# Gets the instance of the logger.
logSys = getF2BLogger(__name__)
logSys = getLogger(__name__)
##
# Journal reader class.

View File

@ -26,10 +26,10 @@ __license__ = "GPL"
import Queue, logging
from .actions import Actions
from ..helpers import getF2BLogger
from ..helpers import getLogger
# Gets the instance of the logger.
logSys = getF2BLogger(__name__)
logSys = getLogger(__name__)
class Jail:
"""Fail2Ban jail, which manages a filter and associated actions.

View File

@ -32,10 +32,10 @@ from .filter import FileFilter, JournalFilter
from .transmitter import Transmitter
from .asyncserver import AsyncServer, AsyncServerException
from .. import version
from ..helpers import getF2BLogger, fail2ban_excepthook
from ..helpers import getLogger, fail2ban_excepthook
# Gets the instance of the logger.
logSys = getF2BLogger(__name__)
logSys = getLogger(__name__)
try:
from .database import Fail2BanDb
@ -339,7 +339,7 @@ class Server:
def setLogLevel(self, value):
try:
self.__loggingLock.acquire()
logging.getLogger("fail2ban").setLevel(
getLogger("fail2ban").setLevel(
getattr(logging, value.upper()))
except AttributeError:
raise ValueError("Invalid log level")
@ -392,7 +392,7 @@ class Server:
return False
# Removes previous handlers -- in reverse order since removeHandler
# alter the list in-place and that can confuses the iterable
logger = logging.getLogger("fail2ban")
logger = getLogger("fail2ban")
for handler in logger.handlers[::-1]:
# Remove the handler.
logger.removeHandler(handler)
@ -429,7 +429,7 @@ class Server:
def flushLogs(self):
if self.__logTarget not in ['STDERR', 'STDOUT', 'SYSLOG']:
for handler in logging.getLogger("fail2ban").handlers:
for handler in getLogger("fail2ban").handlers:
try:
handler.doRollover()
logSys.info("rollover performed on %s" % self.__logTarget)
@ -438,7 +438,7 @@ class Server:
logSys.info("flush performed on %s" % self.__logTarget)
return "rolled over"
else:
for handler in logging.getLogger("fail2ban").handlers:
for handler in getLogger("fail2ban").handlers:
handler.flush()
logSys.info("flush performed on %s" % self.__logTarget)
return "flushed"

View File

@ -24,10 +24,10 @@ __author__ = "Cyril Jaquier"
__copyright__ = "Copyright (c) 2004 Cyril Jaquier"
__license__ = "GPL"
from ..helpers import getF2BLogger
from ..helpers import getLogger
# Gets the instance of the logger.
logSys = getF2BLogger(__name__)
logSys = getLogger(__name__)
class Ticket:

View File

@ -27,10 +27,10 @@ __license__ = "GPL"
import time
import json
from ..helpers import getF2BLogger
from ..helpers import getLogger
# Gets the instance of the logger.
logSys = getF2BLogger(__name__)
logSys = getLogger(__name__)
class Transmitter:

View File

@ -32,7 +32,7 @@ import datetime
from glob import glob
from StringIO import StringIO
from ..helpers import formatExceptionInfo, mbasename, TraceBack, FormatterWithTraceBack
from ..helpers import formatExceptionInfo, mbasename, TraceBack, FormatterWithTraceBack, getLogger
from ..server.datetemplate import DatePatternRegex
@ -159,7 +159,7 @@ class TestsUtilsTest(unittest.TestCase):
# and both types of traceback at once
fmt = ' %(tb)s | %(tbc)s : %(message)s'
logSys = logging.getLogger("fail2ban_tests")
logSys = getLogger("fail2ban_tests")
out = logging.StreamHandler(strout)
out.setFormatter(Formatter(fmt))
logSys.addHandler(out)

View File

@ -30,14 +30,13 @@ import tempfile
import os
import locale
import sys
import logging
from ..server.failregex import Regex, FailRegex, RegexException
from ..server.server import Server
from ..server.jail import Jail
from ..server.jailthread import JailThread
from .utils import LogCaptureTestCase
from ..helpers import getF2BLogger
from ..helpers import getLogger
try:
from ..server import filtersystemd
@ -725,7 +724,7 @@ class TransmitterLogging(TransmitterBase):
os.close(f)
self.server.setLogLevel("WARNING")
self.assertEqual(self.transm.proceed(["set", "logtarget", fn]), (0, fn))
l = logging.getLogger('fail2ban')
l = getLogger('fail2ban')
l.warning("Before file moved")
try:
f2, fn2 = tempfile.mkstemp("fail2ban.log")
@ -806,7 +805,7 @@ class _BadThread(JailThread):
class LoggingTests(LogCaptureTestCase):
def testGetF2BLogger(self):
testLogSys = getF2BLogger("fail2ban.some.string.with.name")
testLogSys = getLogger("fail2ban.some.string.with.name")
self.assertEqual(testLogSys.parent.name, "fail2ban")
self.assertEqual(testLogSys.name, "fail2ban.name")

View File

@ -30,9 +30,9 @@ import unittest
from StringIO import StringIO
from ..server.mytime import MyTime
from ..helpers import getF2BLogger
from ..helpers import getLogger
logSys = getF2BLogger(__name__)
logSys = getLogger(__name__)
def mtimesleep():
# no sleep now should be necessary since polling tracks now not only
@ -187,7 +187,7 @@ class LogCaptureTestCase(unittest.TestCase):
# For extended testing of what gets output into logging
# system, we will redirect it to a string
logSys = logging.getLogger("fail2ban")
logSys = getLogger("fail2ban")
# Keep old settings
self._old_level = logSys.level
@ -200,7 +200,7 @@ class LogCaptureTestCase(unittest.TestCase):
def tearDown(self):
"""Call after every test case."""
# print "O: >>%s<<" % self._log.getvalue()
logSys = logging.getLogger("fail2ban")
logSys = getLogger("fail2ban")
logSys.handlers = self._old_handlers
logSys.level = self._old_level