@@ -9,10 +9,6 @@ import re | |||||
import subprocess | import subprocess | ||||
import traceback | import traceback | ||||
import logging | |||||
from logging import NullHandler | |||||
logger = logging.getLogger('hyde.engine') | |||||
logger.addHandler(NullHandler()) | |||||
class LessCSSPlugin(Plugin): | class LessCSSPlugin(Plugin): | ||||
""" | """ | ||||
@@ -78,8 +74,8 @@ class LessCSSPlugin(Plugin): | |||||
try: | try: | ||||
subprocess.check_output([str(less), str(source), str(target)]) | subprocess.check_output([str(less), str(source), str(target)]) | ||||
except subprocess.CalledProcessError, error: | except subprocess.CalledProcessError, error: | ||||
logger.error(traceback.format_exc()) | |||||
logger.error(error.output) | |||||
self.logger.error(traceback.format_exc()) | |||||
self.logger.error(error.output) | |||||
raise self.template.exception_class( | raise self.template.exception_class( | ||||
"Cannot process less css. Error occurred when " | "Cannot process less css. Error occurred when " | ||||
"processing [%s]" % resource.source_file) | "processing [%s]" % resource.source_file) | ||||
@@ -6,11 +6,6 @@ from hyde.model import Expando | |||||
from hyde.plugin import Plugin | from hyde.plugin import Plugin | ||||
import yaml | import yaml | ||||
import logging | |||||
from logging import NullHandler | |||||
logger = logging.getLogger('hyde.engine') | |||||
logger.addHandler(NullHandler()) | |||||
class Metadata(Expando): | class Metadata(Expando): | ||||
""" | """ | ||||
@@ -77,13 +72,13 @@ class MetaPlugin(Plugin): | |||||
the resource. Load meta data by looking for the marker. | the resource. Load meta data by looking for the marker. | ||||
Once loaded, remove the meta area from the text. | Once loaded, remove the meta area from the text. | ||||
""" | """ | ||||
logger.info("Trying to load metadata from resource [%s]" % resource) | |||||
self.logger.info("Trying to load metadata from resource [%s]" % resource) | |||||
yaml_finder = re.compile( | yaml_finder = re.compile( | ||||
r"^\s*(?:---|===)\s*\n((?:.|\n)+?)\n\s*(?:---|===)\s*\n", | r"^\s*(?:---|===)\s*\n((?:.|\n)+?)\n\s*(?:---|===)\s*\n", | ||||
re.MULTILINE) | re.MULTILINE) | ||||
match = re.match(yaml_finder, text) | match = re.match(yaml_finder, text) | ||||
if not match: | if not match: | ||||
logger.info("No metadata found in resource [%s]" % resource) | |||||
self.logger.info("No metadata found in resource [%s]" % resource) | |||||
data = {} | data = {} | ||||
else: | else: | ||||
text = text[match.end():] | text = text[match.end():] | ||||
@@ -96,7 +91,7 @@ class MetaPlugin(Plugin): | |||||
else: | else: | ||||
resource.meta.update(data) | resource.meta.update(data) | ||||
self.__update_standard_attributes__(resource) | self.__update_standard_attributes__(resource) | ||||
logger.info("Successfully loaded metadata from resource [%s]" | |||||
self.logger.info("Successfully loaded metadata from resource [%s]" | |||||
% resource) | % resource) | ||||
return text | return text | ||||
@@ -10,11 +10,6 @@ from functools import partial | |||||
from itertools import ifilter, izip, tee | from itertools import ifilter, izip, tee | ||||
from operator import attrgetter | from operator import attrgetter | ||||
import logging | |||||
from logging import NullHandler | |||||
logger = logging.getLogger('hyde.engine') | |||||
logger.addHandler(NullHandler()) | |||||
def pairwalk(iterable): | def pairwalk(iterable): | ||||
a, b = tee(iterable) | a, b = tee(iterable) | ||||
next(b, None) | next(b, None) | ||||
@@ -110,7 +105,7 @@ class SorterPlugin(Plugin): | |||||
return | return | ||||
for name, settings in config.sorter.__dict__.items(): | for name, settings in config.sorter.__dict__.items(): | ||||
logger.info("Adding sort methods for [%s]" % name) | |||||
self.logger.info("Adding sort methods for [%s]" % name) | |||||
sort_method_name = 'walk_resources_sorted_by_%s' % name | sort_method_name = 'walk_resources_sorted_by_%s' % name | ||||
add_method(Node, sort_method_name, sort_method, settings) | add_method(Node, sort_method_name, sort_method, settings) | ||||
match_method_name = 'is_%s' % name | match_method_name = 'is_%s' % name | ||||
@@ -7,17 +7,17 @@ for common operations to provide a single interface. | |||||
""" | """ | ||||
import codecs | import codecs | ||||
import logging | |||||
from logging import NullHandler | |||||
import mimetypes | import mimetypes | ||||
import os | import os | ||||
import shutil | import shutil | ||||
from distutils import dir_util | from distutils import dir_util | ||||
import functools | import functools | ||||
# pylint: disable-msg=E0611 | |||||
logger = logging.getLogger('fs') | |||||
logger.addHandler(NullHandler()) | |||||
from hyde.logging import getLoggerWithNullHandler | |||||
logger = getLoggerWithNullHandler('fs') | |||||
# pylint: disable-msg=E0611 | |||||
__all__ = ['File', 'Folder'] | __all__ = ['File', 'Folder'] | ||||
@@ -8,11 +8,8 @@ from hyde.template import Template | |||||
from contextlib import contextmanager | from contextlib import contextmanager | ||||
import logging | |||||
from logging import NullHandler | |||||
logger = logging.getLogger('hyde.engine') | |||||
logger.addHandler(NullHandler()) | |||||
from hyde.logging import getLoggerWithNullHandler | |||||
logger = getLoggerWithNullHandler('hyde.engine') | |||||
class Generator(object): | class Generator(object): | ||||
@@ -5,10 +5,8 @@ import sys | |||||
from hyde.exceptions import HydeException | from hyde.exceptions import HydeException | ||||
import logging | |||||
from logging import NullHandler | |||||
logger = logging.getLogger('hyde.engine') | |||||
logger.addHandler(NullHandler()) | |||||
from hyde.logging import getLoggerWithNullHandler | |||||
logger = getLoggerWithNullHandler('hyde.engine') | |||||
plugins = {} | plugins = {} | ||||
templates = {} | templates = {} | ||||
@@ -0,0 +1,25 @@ | |||||
""" | |||||
Module for python 2.6 compatibility. | |||||
""" | |||||
import logging | |||||
try: | |||||
from logging import NullHandler | |||||
except: | |||||
class NullHandler(logging.Handler): | |||||
""" | |||||
NOOP handler for libraries. | |||||
""" | |||||
def emit(self, record): | |||||
""" | |||||
/dev/null | |||||
""" | |||||
pass | |||||
def getLoggerWithNullHandler(logger_name): | |||||
""" | |||||
Gets the logger initialized with the `logger_name` | |||||
and a NullHandler. | |||||
""" | |||||
logger = logging.getLogger(logger_name) | |||||
logger.addHandler(NullHandler()) |
@@ -5,6 +5,8 @@ Contains definition for a plugin protocol and other utiltities. | |||||
import abc | import abc | ||||
from hyde import loader | from hyde import loader | ||||
from hyde.logging import getLoggerWithNullHandler | |||||
class Plugin(object): | class Plugin(object): | ||||
""" | """ | ||||
The plugin protocol | The plugin protocol | ||||
@@ -14,6 +16,8 @@ class Plugin(object): | |||||
def __init__(self, site): | def __init__(self, site): | ||||
super(Plugin, self).__init__() | super(Plugin, self).__init__() | ||||
self.site = site | self.site = site | ||||
self.logger = getLoggerWithNullHandler(self.__class__.__name__) | |||||
def template_loaded(self, template): | def template_loaded(self, template): | ||||
""" | """ | ||||
@@ -12,7 +12,6 @@ from hyde.site import Site | |||||
from hyde.generator import Generator | from hyde.generator import Generator | ||||
import logging | import logging | ||||
logger = logging.getLogger('hyde.server') | logger = logging.getLogger('hyde.server') | ||||
import sys | import sys | ||||
@@ -7,12 +7,11 @@ from hyde.exceptions import HydeException | |||||
from hyde.fs import FS, File, Folder | from hyde.fs import FS, File, Folder | ||||
from hyde.model import Config | from hyde.model import Config | ||||
import logging | |||||
from logging import NullHandler | |||||
logger = logging.getLogger('hyde.engine') | |||||
logger.addHandler(NullHandler()) | |||||
from hyde.logging import getLoggerWithNullHandler | |||||
logger = getLoggerWithNullHandler('hyde.engine') | |||||
class Processable(object): | class Processable(object): | ||||
""" | """ | ||||
A node or resource. | A node or resource. | ||||
@@ -5,6 +5,8 @@ Abstract classes and utilities for template engines | |||||
""" | """ | ||||
from hyde.exceptions import HydeException | from hyde.exceptions import HydeException | ||||
from hyde.logging import getLoggerWithNullHandler | |||||
class Template(object): | class Template(object): | ||||
""" | """ | ||||
Interface for hyde template engines. To use a different template engine, | Interface for hyde template engines. To use a different template engine, | ||||
@@ -13,6 +15,7 @@ class Template(object): | |||||
def __init__(self, sitepath): | def __init__(self, sitepath): | ||||
self.sitepath = sitepath | self.sitepath = sitepath | ||||
self.logger = getLoggerWithNullHandler(self.__class__.__name__) | |||||
def configure(self, config): | def configure(self, config): | ||||
""" | """ | ||||