- Notifications
You must be signed in to change notification settings - Fork11.2k
Added structured logging to systemd journal.#7115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:master
Are you sure you want to change the base?
Changes from1 commit
a9a18b54c2dc383c4987da375de7cbff8ebc9997ebda5646de488db0f8953a8File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -170,6 +170,7 @@ These settings can be used to configure the logging: | ||
| * :setting:`LOG_DATEFORMAT` | ||
| * :setting:`LOG_STDOUT` | ||
| * :setting:`LOG_SHORT_NAMES` | ||
| * :setting:`LOG_TO_SYSTEMD` | ||
| ||
| The first couple of settings define a destination for log messages. If | ||
| :setting:`LOG_FILE` is set, messages sent through the root logger will be | ||
| @@ -194,6 +195,18 @@ If :setting:`LOG_SHORT_NAMES` is set, then the logs will not display the Scrapy | ||
| component that prints the log. It is unset by default, hence logs contain the | ||
| Scrapy component responsible for that log output. | ||
| If :setting:`LOG_TO_SYSTEMD` is set to ``True``, Scrapy will send logs to the | ||
| systemd journal using ``systemd.journal.JournalHandler`` as its logging handler. | ||
| This requires the external Python package ``systemd`` to be installed (minimum | ||
| version 234 recommended). You can install it via pip:: | ||
| pip install systemd | ||
| This feature is opt-in and disabled by default. When enabled, Scrapy will raise an | ||
| ``ImportError`` if the ``systemd`` package is not found. Use this setting when | ||
| running Scrapy under systemd to utilize ``journalctl`` for log management and | ||
| filtering. | ||
| ||
| Command-line options | ||
| -------------------- | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -22,13 +22,6 @@ | ||
| from scrapy.crawler import Crawler | ||
| from scrapy.logformatter import LogFormatterResult | ||
| logger = logging.getLogger(__name__) | ||
| @@ -172,11 +165,9 @@ def _get_handler(settings: Settings) -> logging.Handler: | ||
| encoding = settings.get("LOG_ENCODING") | ||
| handler = logging.FileHandler(filename, mode=mode, encoding=encoding) | ||
| elif settings.getbool("LOG_ENABLED"): | ||
| if settings.getbool("LOG_TO_SYSTEMD", False): | ||
| # Opt-in systemd journal logging, will raise if systemd.journal is missing | ||
| import systemd.journal | ||
| ||
| handler = systemd.journal.JournalHandler() | ||
| else: | ||
| handler = logging.StreamHandler() | ||