Minor text changes to log message limitation

This commit is contained in:
Justin Mayer 2014-04-14 16:18:07 -04:00
commit 7e06912bca
5 changed files with 21 additions and 21 deletions

View file

@ -157,24 +157,24 @@ For logging messages that are not repeated, use the usual Python way:
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
# when needed # when needed
logger.warning('A warning that could occur only once") logger.warning("A warning that would usually occur only once")
However, if you want to log messages that may occur several times, instead of However, if you want to log messages that may occur several times, instead of
a string, gives a tuple to the logging method, with two arguments: a string, give a tuple to the logging method, with two arguments:
1. The message to log for this very execution 1. The message to log for the initial execution
2. A generic message that will appear if the previous one would occur to many 2. A generic message that will appear if the previous one would occur too many
times. times.
For example, if you want to log missing resources, use the following code: For example, if you want to log missing resources, use the following code:
for ressource in ressources: for resource in resources:
if ressource.is_missing: if resource.is_missing:
logger.warning(( logger.warning((
'The resource {r} is missing'.format(r=ressource.name), 'The resource {r} is missing'.format(r=resource.name),
'Other resources were missing')) 'Other resources were missing'))
The logs will be displayed as follows: The log messages will be displayed as follows:
WARNING: The resource prettiest_cat.jpg is missing WARNING: The resource prettiest_cat.jpg is missing
WARNING: The resource best_cat_ever.jpg is missing WARNING: The resource best_cat_ever.jpg is missing

View file

@ -88,7 +88,7 @@ Setting name (default value)
here or a single string representing one locale. here or a single string representing one locale.
When providing a list, all the locales will be tried When providing a list, all the locales will be tried
until one works. until one works.
`LOG_FILTER` (``[]``) A list of tuples containing the logging level (up to warning) `LOG_FILTER` (``[]``) A list of tuples containing the logging level (up to ``warning``)
and the message to be ignored. and the message to be ignored.
For example: ``[(logging.WARN, 'TAG_SAVE_AS is set to False')]`` For example: ``[(logging.WARN, 'TAG_SAVE_AS is set to False')]``
`READERS` (``{}``) A dictionary of file extensions / Reader classes for Pelican to `READERS` (``{}``) A dictionary of file extensions / Reader classes for Pelican to
@ -701,15 +701,15 @@ adding the following to your configuration::
Logging Logging
======= =======
Sometimes, useless lines of log appears while the generation occurs. Finding Sometimes, a long list of warnings may appear during site generation. Finding
**the** meaningful error message in the middle of tons of annoying log outputs the **meaningful** error message in the middle of tons of annoying log output
can be quite tricky. To be able to filter out all useless log messages, Pelican can be quite tricky. In order to filter out redundant log messages, Pelican
comes with the ``LOG_FILTER`` setting. comes with the ``LOG_FILTER`` setting.
``LOG_FILTER`` should be a list of tuples ``(level, msg)``, each of them being ``LOG_FILTER`` should be a list of tuples ``(level, msg)``, each of them being
composed of the logging level (up to warning) and the message to be ignored. composed of the logging level (up to ``warning``) and the message to be ignored.
Simply populate the list with the logs you want to hide and they will be Simply populate the list with the log messages you want to hide, and they will
filtered out. be filtered out.
For example: ``[(logging.WARN, 'TAG_SAVE_AS is set to False')]`` For example: ``[(logging.WARN, 'TAG_SAVE_AS is set to False')]``

View file

@ -241,7 +241,7 @@ class Content(object):
else: else:
logger.warning(("Unable to find {fn}, skipping url" logger.warning(("Unable to find {fn}, skipping url"
" replacement".format(fn=value), " replacement".format(fn=value),
"Other ressources were not found" "Other resources were not found"
" and their urls not replaced")) " and their urls not replaced"))
elif what == 'category': elif what == 'category':
origin = Category(path, self.settings).url origin = Category(path, self.settings).url

View file

@ -78,7 +78,7 @@ class LimitFilter(logging.Filter):
group_count = defaultdict(int) group_count = defaultdict(int)
def filter(self, record): def filter(self, record):
# don't limit levels over warnings # don't limit log messages for anything above "warning"
if record.levelno > logging.WARN: if record.levelno > logging.WARN:
return record return record
# extract group # extract group
@ -105,7 +105,7 @@ class LimitFilter(logging.Filter):
class LimitLogger(logging.Logger): class LimitLogger(logging.Logger):
""" """
A logger which add LimitFilter automatically A logger which adds LimitFilter automatically
""" """
limit_filter = LimitFilter() limit_filter = LimitFilter()

View file

@ -171,15 +171,15 @@ def get_settings_from_file(path, default_settings=DEFAULT_CONFIG):
def configure_settings(settings): def configure_settings(settings):
"""Provide optimizations, error checking and warnings for the given """Provide optimizations, error checking, and warnings for the given
settings. settings.
Set up the logs to be ignored as well. Also, specify the log messages to be ignored.
""" """
if not 'PATH' in settings or not os.path.isdir(settings['PATH']): if not 'PATH' in settings or not os.path.isdir(settings['PATH']):
raise Exception('You need to specify a path containing the content' raise Exception('You need to specify a path containing the content'
' (see pelican --help for more information)') ' (see pelican --help for more information)')
# set up logs to be ignored # specify the log messages to be ignored
LimitFilter.ignore.update(set(settings.get('LOG_FILTER', LimitFilter.ignore.update(set(settings.get('LOG_FILTER',
DEFAULT_CONFIG['LOG_FILTER']))) DEFAULT_CONFIG['LOG_FILTER'])))