Add timestamp and formatting to S3 plugin log (#15083)

* add date/time to log output

* minor comment fix

* configurable log_level
This commit is contained in:
Earle Lowe 2023-04-19 12:03:37 -07:00 committed by GitHub
parent e2b16d4d3c
commit 7f0c338a27
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View File

@ -1,5 +1,6 @@
instance-1:
log_filename: "s3_plugin.log"
log_level: INFO
server_files_location: "/Users/test/.chia/mainnet/data_layer/db/server_files_location_testnet10"
port: 8998
aws_credentials:

View File

@ -277,6 +277,19 @@ def make_app(config: Dict[str, Any], instance_name: str) -> web.Application:
f", and secret_access_key. Missing config key: {e.args[0]!r}"
)
log_level = config.get("log_level", "INFO")
log.setLevel(log_level)
fh = logging.FileHandler(config.get("log_filename", "s3_plugin.log"))
fh.setLevel(log_level)
# create formatter and add it to the handlers
file_log_formatter = logging.Formatter(
fmt="%(asctime)s.%(msecs)03d %(name)s %(levelname)s %(message)s", datefmt="%Y-%m-%dT%H:%M:%S"
)
fh.setFormatter(file_log_formatter)
# add the handlers to logger
log.addHandler(fh)
stores = read_store_ids_from_config(config)
s3_client = S3Plugin(
@ -295,7 +308,6 @@ def make_app(config: Dict[str, Any], instance_name: str) -> web.Application:
app.add_routes([web.post("/add_missing_files", s3_client.add_missing_files)])
app.add_routes([web.post("/plugin_info", s3_client.plugin_info)])
app.add_routes([web.post("/healthz", s3_client.healthz)])
logging.basicConfig(level=logging.INFO, filename=config.get("log_filename", "s3_plugin.log"))
log.info(f"Starting s3 plugin {instance_name} on port {config['port']}")
return app