mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
Move rich's console to log.py
This commit is contained in:
parent
7d492bad67
commit
a52922bfb5
3 changed files with 8 additions and 10 deletions
|
|
@ -13,11 +13,9 @@ from collections.abc import Iterable
|
||||||
from pkgutil import extend_path
|
from pkgutil import extend_path
|
||||||
__path__ = extend_path(__path__, __name__)
|
__path__ = extend_path(__path__, __name__)
|
||||||
|
|
||||||
from rich.console import Console
|
|
||||||
from rich.logging import RichHandler
|
|
||||||
|
|
||||||
# pelican.log has to be the first pelican module to be loaded
|
# pelican.log has to be the first pelican module to be loaded
|
||||||
# because logging.setLoggerClass has to be called before logging.getLogger
|
# because logging.setLoggerClass has to be called before logging.getLogger
|
||||||
|
from pelican.log import console
|
||||||
from pelican.log import init as init_logging
|
from pelican.log import init as init_logging
|
||||||
from pelican.generators import (ArticlesGenerator, # noqa: I100
|
from pelican.generators import (ArticlesGenerator, # noqa: I100
|
||||||
PagesGenerator, SourceFileGenerator,
|
PagesGenerator, SourceFileGenerator,
|
||||||
|
|
@ -38,7 +36,6 @@ except Exception:
|
||||||
|
|
||||||
DEFAULT_CONFIG_NAME = 'pelicanconf.py'
|
DEFAULT_CONFIG_NAME = 'pelicanconf.py'
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
console = Console()
|
|
||||||
|
|
||||||
|
|
||||||
class Pelican:
|
class Pelican:
|
||||||
|
|
@ -502,8 +499,7 @@ def main(argv=None):
|
||||||
args = parse_arguments(argv)
|
args = parse_arguments(argv)
|
||||||
logs_dedup_min_level = getattr(logging, args.logs_dedup_min_level)
|
logs_dedup_min_level = getattr(logging, args.logs_dedup_min_level)
|
||||||
init_logging(level=args.verbosity, fatal=args.fatal,
|
init_logging(level=args.verbosity, fatal=args.fatal,
|
||||||
handler=RichHandler(console=console), name=__name__,
|
name=__name__, logs_dedup_min_level=logs_dedup_min_level)
|
||||||
logs_dedup_min_level=logs_dedup_min_level)
|
|
||||||
|
|
||||||
logger.debug('Pelican version: %s', __version__)
|
logger.debug('Pelican version: %s', __version__)
|
||||||
logger.debug('Python version: %s', sys.version.split()[0])
|
logger.debug('Python version: %s', sys.version.split()[0])
|
||||||
|
|
@ -544,5 +540,4 @@ def main(argv=None):
|
||||||
|
|
||||||
if args.verbosity == logging.DEBUG:
|
if args.verbosity == logging.DEBUG:
|
||||||
console.print_exception()
|
console.print_exception()
|
||||||
else:
|
|
||||||
sys.exit(getattr(e, 'exitcode', 1))
|
sys.exit(getattr(e, 'exitcode', 1))
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,15 @@
|
||||||
import logging
|
import logging
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
|
|
||||||
|
from rich.console import Console
|
||||||
from rich.logging import RichHandler
|
from rich.logging import RichHandler
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
'init'
|
'init'
|
||||||
]
|
]
|
||||||
|
|
||||||
|
console = Console()
|
||||||
|
|
||||||
|
|
||||||
class LimitFilter(logging.Filter):
|
class LimitFilter(logging.Filter):
|
||||||
"""
|
"""
|
||||||
|
|
@ -100,7 +103,7 @@ logging.setLoggerClass(FatalLogger)
|
||||||
logging.getLogger().__class__ = FatalLogger
|
logging.getLogger().__class__ = FatalLogger
|
||||||
|
|
||||||
|
|
||||||
def init(level=None, fatal='', handler=RichHandler(), name=None,
|
def init(level=None, fatal='', handler=RichHandler(console=console), name=None,
|
||||||
logs_dedup_min_level=None):
|
logs_dedup_min_level=None):
|
||||||
FatalLogger.warnings_fatal = fatal.startswith('warning')
|
FatalLogger.warnings_fatal = fatal.startswith('warning')
|
||||||
FatalLogger.errors_fatal = bool(fatal)
|
FatalLogger.errors_fatal = bool(fatal)
|
||||||
|
|
|
||||||
|
|
@ -811,7 +811,7 @@ class FileSystemWatcher:
|
||||||
if result.get('content') is None:
|
if result.get('content') is None:
|
||||||
reader_descs = sorted(
|
reader_descs = sorted(
|
||||||
{
|
{
|
||||||
'%s (%s)' % (type(r).__name__, ', '.join(r.file_extensions))
|
' | %s (%s)' % (type(r).__name__, ', '.join(r.file_extensions))
|
||||||
for r in self.reader_class(self.settings).readers.values()
|
for r in self.reader_class(self.settings).readers.values()
|
||||||
if r.enabled
|
if r.enabled
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue