Changeset View
Changeset View
Standalone View
Standalone View
swh/fuse/cli.py
# Copyright (C) 2020 The Software Heritage developers | # Copyright (C) 2020 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
import asyncio | import asyncio | ||||
from contextlib import ExitStack | from contextlib import ExitStack | ||||
import logging | |||||
import os | import os | ||||
# WARNING: do not import unnecessary things here to keep cli startup time under | # WARNING: do not import unnecessary things here to keep cli startup time under | ||||
# control | # control | ||||
from pathlib import Path | from pathlib import Path | ||||
from typing import Any, Dict | from typing import Any, Dict | ||||
import click | import click | ||||
▲ Show 20 Lines • Show All 85 Lines • ▼ Show 20 Lines | \b | ||||
$ grep printf swhfs/archive/swh:1:cnt:c839dea9e8e6f0528b468214348fee8669b305b2 | $ grep printf swhfs/archive/swh:1:cnt:c839dea9e8e6f0528b468214348fee8669b305b2 | ||||
printf("Hello, World!"); | printf("Hello, World!"); | ||||
$ | $ | ||||
""" | """ | ||||
from swh.fuse import fuse | from swh.fuse import fuse | ||||
# TODO: set default logging settings when --log-config is not passed | |||||
# DEFAULT_LOG_PATH = Path(".local/swh/fuse/mount.log") | |||||
with ExitStack() as stack: | with ExitStack() as stack: | ||||
if not foreground: | if not foreground: | ||||
# TODO: temporary fix until swh.core has the proper logging utilities | |||||
# Disable logging config before daemonizing, and reset it once | |||||
# daemonized to be sure to not close file handlers | |||||
logging.shutdown() | |||||
# Stay in the current working directory when spawning daemon | # Stay in the current working directory when spawning daemon | ||||
zack: I don't get this. Aren't you here just throwing away the logging config that you had initially… | |||||
Not Done Inline ActionsFor now, yes. Once swh.core.logger has a function to "reenact the same configuration" (which isn't currently possible, as we're calling the logging setup directly in the swh entry point, and "losing" the config information), then this should be using that. olasd: For now, yes.
Once swh.core.logger has a function to "reenact the same configuration" (which… | |||||
cwd = os.getcwd() | cwd = os.getcwd() | ||||
stack.enter_context(DaemonContext(working_directory=cwd)) | stack.enter_context(DaemonContext(working_directory=cwd)) | ||||
logging.config.dictConfig( | |||||
{ | |||||
"version": 1, | |||||
"handlers": { | |||||
"syslog": { | |||||
"class": "logging.handlers.SysLogHandler", | |||||
"address": "/dev/log", | |||||
}, | |||||
}, | |||||
"root": {"level": ctx.obj["log_level"], "handlers": ["syslog"],}, | |||||
} | |||||
) | |||||
asyncio.run(fuse.main(swhids, path, ctx.obj["config"])) | asyncio.run(fuse.main(swhids, path, ctx.obj["config"])) |
I don't get this. Aren't you here just throwing away the logging config that you had initially inherited from swh.core.cli?
AFAICT what you should do instead is re-enact the same configuration after daemonizing. Otherwise how could the user define a logging configuration at all?