mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
Minor text changes to log message limitation
This commit is contained in:
parent
66a16b560f
commit
7e06912bca
5 changed files with 21 additions and 21 deletions
|
|
@ -157,24 +157,24 @@ For logging messages that are not repeated, use the usual Python way:
|
|||
logger = logging.getLogger(__name__)
|
||||
|
||||
# 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
|
||||
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
|
||||
2. A generic message that will appear if the previous one would occur to many
|
||||
1. The message to log for the initial execution
|
||||
2. A generic message that will appear if the previous one would occur too many
|
||||
times.
|
||||
|
||||
For example, if you want to log missing resources, use the following code:
|
||||
|
||||
for ressource in ressources:
|
||||
if ressource.is_missing:
|
||||
for resource in resources:
|
||||
if resource.is_missing:
|
||||
logger.warning((
|
||||
'The resource {r} is missing'.format(r=ressource.name),
|
||||
'The resource {r} is missing'.format(r=resource.name),
|
||||
'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 best_cat_ever.jpg is missing
|
||||
|
|
|
|||
|
|
@ -88,7 +88,7 @@ Setting name (default value)
|
|||
here or a single string representing one locale.
|
||||
When providing a list, all the locales will be tried
|
||||
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.
|
||||
For example: ``[(logging.WARN, 'TAG_SAVE_AS is set to False')]``
|
||||
`READERS` (``{}``) A dictionary of file extensions / Reader classes for Pelican to
|
||||
|
|
@ -701,15 +701,15 @@ adding the following to your configuration::
|
|||
Logging
|
||||
=======
|
||||
|
||||
Sometimes, useless lines of log appears while the generation occurs. Finding
|
||||
**the** meaningful error message in the middle of tons of annoying log outputs
|
||||
can be quite tricky. To be able to filter out all useless log messages, Pelican
|
||||
Sometimes, a long list of warnings may appear during site generation. Finding
|
||||
the **meaningful** error message in the middle of tons of annoying log output
|
||||
can be quite tricky. In order to filter out redundant log messages, Pelican
|
||||
comes with the ``LOG_FILTER`` setting.
|
||||
|
||||
``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.
|
||||
Simply populate the list with the logs you want to hide and they will be
|
||||
filtered out.
|
||||
composed of the logging level (up to ``warning``) and the message to be ignored.
|
||||
Simply populate the list with the log messages you want to hide, and they will
|
||||
be filtered out.
|
||||
|
||||
For example: ``[(logging.WARN, 'TAG_SAVE_AS is set to False')]``
|
||||
|
||||
|
|
|
|||
|
|
@ -241,7 +241,7 @@ class Content(object):
|
|||
else:
|
||||
logger.warning(("Unable to find {fn}, skipping url"
|
||||
" replacement".format(fn=value),
|
||||
"Other ressources were not found"
|
||||
"Other resources were not found"
|
||||
" and their urls not replaced"))
|
||||
elif what == 'category':
|
||||
origin = Category(path, self.settings).url
|
||||
|
|
|
|||
|
|
@ -78,7 +78,7 @@ class LimitFilter(logging.Filter):
|
|||
group_count = defaultdict(int)
|
||||
|
||||
def filter(self, record):
|
||||
# don't limit levels over warnings
|
||||
# don't limit log messages for anything above "warning"
|
||||
if record.levelno > logging.WARN:
|
||||
return record
|
||||
# extract group
|
||||
|
|
@ -105,7 +105,7 @@ class LimitFilter(logging.Filter):
|
|||
|
||||
class LimitLogger(logging.Logger):
|
||||
"""
|
||||
A logger which add LimitFilter automatically
|
||||
A logger which adds LimitFilter automatically
|
||||
"""
|
||||
|
||||
limit_filter = LimitFilter()
|
||||
|
|
|
|||
|
|
@ -171,15 +171,15 @@ def get_settings_from_file(path, default_settings=DEFAULT_CONFIG):
|
|||
|
||||
|
||||
def configure_settings(settings):
|
||||
"""Provide optimizations, error checking and warnings for the given
|
||||
"""Provide optimizations, error checking, and warnings for the given
|
||||
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']):
|
||||
raise Exception('You need to specify a path containing the content'
|
||||
' (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',
|
||||
DEFAULT_CONFIG['LOG_FILTER'])))
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue