Skip to content

mongodb logs readable #35

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions polytope_server/common/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@
# Mapping Python logging levels to syslog severity levels
LOGGING_TO_SYSLOG_SEVERITY = {
logging.CRITICAL: 2, # LOG_CRIT
logging.ERROR: 3, # LOG_ERR
logging.WARNING: 4, # LOG_WARNING
logging.INFO: 6, # LOG_INFO
logging.DEBUG: 7, # LOG_DEBUG
logging.NOTSET: 7, # LOG_DEBUG (default)
logging.ERROR: 3, # LOG_ERR
logging.WARNING: 4, # LOG_WARNING
logging.INFO: 6, # LOG_INFO
logging.DEBUG: 7, # LOG_DEBUG
logging.NOTSET: 7, # LOG_DEBUG (default)
}

# Indexable fields
INDEXABLE_FIELDS = {"request_id": str}
DEFAULT_LOGGING_MODE = "json"
DEFAULT_LOGGING_MODE = "prettyprint" # Changed from "json" to "prettyprint" or "console"
DEFAULT_LOGGING_LEVEL = "INFO"


Expand Down Expand Up @@ -121,11 +121,10 @@ def format(self, record):
if self.mode == "logserver":
return self.format_for_logserver(record, result)
elif self.mode == "prettyprint":
return json.dumps(result, indent=2)
return json.dumps(result, indent=2, ensure_ascii=False) # Added ensure_ascii=False for correct Unicode display
else:
return json.dumps(result, indent=None)


def setup(config, source_name):
logger = logging.getLogger()
logger.name = source_name
Expand All @@ -140,4 +139,7 @@ def setup(config, source_name):
logger.addHandler(handler)
logger.setLevel(level)

# Lower the logging level for pymongo
logging.getLogger('pymongo').setLevel(logging.WARNING)

logger.info("Logging Initialized")
Loading