Skip to content
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

bug: Cannot get logging to work with monitoring resource #4770

Open
AugustasMacys opened this issue Jun 3, 2024 · 0 comments
Open

bug: Cannot get logging to work with monitoring resource #4770

AugustasMacys opened this issue Jun 3, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@AugustasMacys
Copy link

Describe the bug

I am experiencing an issue with the logging configuration not being applied when using the monitoring resource in a BentoML service. Despite specifying the logging configuration file in the log_config_file parameter, the loggers are not picking up the configurations as expected. The only way I can get the logging configuration to apply correctly is by manually loading the configuration file and setting up the loggers within the service initialization.

To reproduce

  1. Provide a file with 2 services: 1 working, another not working. I expect them both to work:
    issue_logging_service.py
from __future__ import annotations

import logging
import os
import bentoml

import logging.config
import yaml

@bentoml.service(
    resources={"cpu": "2",
               "memory": "4Gi"},
    monitoring={
        "enabled": True,
        "log_config_file": "configuration_log.yaml",
    }
)
class SimpleLoggingServiceWorking:

    def __init__(self):
        config_path = os.path.join(os.path.dirname(__file__), 'configuration_log.yaml')
        print(f"Configuration file path: {config_path}")

        with open(config_path, 'r') as f:
            config = yaml.safe_load(f.read())
            logging.config.dictConfig(config)

        self.logger = logging.getLogger("WordClassifierModel")

    @bentoml.api()
    def predict(self) -> bool:
        print('*' * 100)
        self.logger.info("/predict endpoint started")
        print(self.logger.name)
        print(self.logger.level)
        print(self.logger.parent)
        print(f"Logger Handlers: {self.logger.handlers}")

        self.logger.info("/predict endpoint finished")
        return True

@bentoml.service(
    resources={"cpu": "2",
               "memory": "4Gi"},
    monitoring={
        "enabled": True,
        "log_config_file": "configuration_log.yaml",
    }
)
class SimpleLoggingServiceNotWorking:

    def __init__(self):
        # Should take from configuration_log
        self.logger = logging.getLogger("WordClassifierModel")

    @bentoml.api(input_spec=dict)
    def predict(self, **data) -> bool:
        print('*' * 100)
        self.logger.info("/predict endpoint started")
        print(self.logger.name)
        print(self.logger.level)
        print(self.logger.parent)
        print(f"Logger Handlers: {self.logger.handlers}")

        self.logger.info("/predict endpoint finished")
        return True

This is configuration_log.yaml:

    version: 1
    disable_existing_loggers: True
    formatters:
      console:
        format: '[%(asctime)s] %(levelname)s - %(message)s'
    handlers:
      console:
        class: logging.StreamHandler
        level: INFO
        formatter: console
        stream: ext://sys.stdout
    loggers:
      bentoml:
        handlers: [console]
        level: INFO
        propagate: false
      LiLT-WordClassifier-Service:
        handlers: [console]
        level: INFO
        propagate: false
      WordClassifierModel:
        handlers: [console]
        level: INFO
        propagate: false

and finally bentofile.yaml:

  service: "issue_logging_service.py:SimpleLoggingServiceWorking"
  # service: "issue_logging_service.py:SimpleLoggingServiceNotWorking"
  
  include:
  - "*.py"
  - "configuration_log.yaml"

Expected behavior

When I do bentoml build and then bentoml serve --development --reload I expect to see this:

  [2024-06-03 13:20:01,860] INFO - /predict endpoint started
  WordClassifierModel
  20
  <RootLogger root (WARNING)>
  Logger Handlers: [<StreamHandler <stdout> (INFO)>]
  [2024-06-03 13:20:01,860] INFO - /predict endpoint finished

But I only see it if I explicitly load logging yaml file to dictionary. When I try to do it only with monitor resource I see no lines in the stream. That is SimpleLoggingServiceNotWorking does not output it to stream:

  [2024-06-03 13:20:01,860] INFO - /predict endpoint started
  [2024-06-03 13:20:01,860] INFO - /predict endpoint finished

Environment

Environment variable

BENTOML_DEBUG=''
BENTOML_QUIET=''
BENTOML_BUNDLE_LOCAL_BUILD=''
BENTOML_DO_NOT_TRACK=''
BENTOML_CONFIG=''
BENTOML_CONFIG_OPTIONS=''
BENTOML_PORT=''
BENTOML_HOST=''
BENTOML_API_WORKERS=''

System information

bentoml: 1.2.16
python: 3.10.14
platform: Linux-5.15.146.1-microsoft-standard-WSL2-x86_64-with-glibc2.35

@AugustasMacys AugustasMacys added the bug Something isn't working label Jun 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant