Skip to content

Commit

Permalink
Merge pull request openwallet-foundation#41 from baegjae/feature/igno…
Browse files Browse the repository at this point in the history
…re-status-ready-live

Ignore the logs of /status/ready and /status/live
  • Loading branch information
baegjae authored Feb 26, 2021
2 parents d7af1e7 + 63606d2 commit f86a87d
Showing 1 changed file with 48 additions and 1 deletion.
49 changes: 48 additions & 1 deletion aries_cloudagent/config/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import logging
from io import TextIOWrapper
from logging.config import fileConfig
from logging.config import fileConfig, dictConfig
from typing import TextIO

import pkg_resources
Expand Down Expand Up @@ -35,6 +35,18 @@ def load_resource(path: str, encoding: str = None) -> TextIO:
pass


class IgnoreFilter(logging.Filter):
def __init__(self, param=None):
self.param = param

def filter(self, record):
if self.param is None:
allow = True
else:
allow = self.param not in record.msg
return allow


class LoggingConfigurator:
"""Utility class used to configure logging and print an informative start banner."""

Expand Down Expand Up @@ -66,6 +78,41 @@ def configure(
logging.basicConfig(level=logging.WARNING)
logging.root.warning(f"Logging config file not found: {config_path}")

aiohttp_logging_config = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'standard': {
'format': '%(asctime)s %(name)s %(levelname)s %(message)s'
},
},
'filters': {
'ignore_ready': {
'()': IgnoreFilter,
'param': 'GET /status/ready HTTP',
},
'ignore_live': {
'()': IgnoreFilter,
'param': 'GET /status/live HTTP',
},
},
'handlers': {
'aiohttp_handler': {
'formatter': 'standard',
'class': 'logging.StreamHandler',
'filters': ['ignore_ready', 'ignore_live'],
},
},
'loggers': {
'aiohttp': {
'handlers': ['aiohttp_handler'],
'level': 'INFO',
'propagate': False
},
}
}
dictConfig(aiohttp_logging_config)

if log_file:
logging.root.handlers.clear()
logging.root.handlers.append(
Expand Down

0 comments on commit f86a87d

Please sign in to comment.