Skip to content

Commit

Permalink
fix: [24]Unify logger and correct logging settings (#2397) (#2402)
Browse files Browse the repository at this point in the history
pr: #2397

Signed-off-by: yangxuan <[email protected]>
  • Loading branch information
XuanYang-cn authored Dec 13, 2024
1 parent 8fa110b commit 218f4b3
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 44 deletions.
3 changes: 1 addition & 2 deletions pymilvus/bulk_writer/buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@
BulkFileType,
)

logger = logging.getLogger("bulk_buffer")
logger.setLevel(logging.DEBUG)
logger = logging.getLogger(__name__)


class Buffer:
Expand Down
3 changes: 1 addition & 2 deletions pymilvus/bulk_writer/bulk_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@

from pymilvus.exceptions import MilvusException

logger = logging.getLogger("bulk_import")
logger.setLevel(logging.DEBUG)
logger = logging.getLogger(__name__)


def _http_headers(api_key: str):
Expand Down
3 changes: 1 addition & 2 deletions pymilvus/bulk_writer/local_bulk_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
BulkFileType,
)

logger = logging.getLogger("local_bulk_writer")
logger.setLevel(logging.DEBUG)
logger = logging.getLogger(__name__)


class LocalBulkWriter(BulkWriter):
Expand Down
3 changes: 1 addition & 2 deletions pymilvus/bulk_writer/remote_bulk_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@
)
from .local_bulk_writer import LocalBulkWriter

logger = logging.getLogger("remote_bulk_writer")
logger.setLevel(logging.DEBUG)
logger = logging.getLogger(__name__)


class RemoteBulkWriter(LocalBulkWriter):
Expand Down
1 change: 0 additions & 1 deletion pymilvus/milvus_client/milvus_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
from .index import IndexParams

logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)


class MilvusClient:
Expand Down
65 changes: 30 additions & 35 deletions pymilvus/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,44 +59,39 @@ def format(self, record: str):
return self.format_col(message_str, level_name=record.levelname)


LOG_LEVEL = "WARNING"

LOGGING = {
"version": 1,
"disable_existing_loggers": False,
"handlers": {
"console": {
"class": "logging.StreamHandler",
"level": LOG_LEVEL,
def init_log(log_level: str):
logging_config = {
"version": 1,
"disable_existing_loggers": False,
"formatters": {
"default": {
"format": "%(asctime)s [%(levelname)s][%(funcName)s]: %(message)s (%(filename)s:%(lineno)s)",
},
"colorful_console": {
"format": "%(asctime)s | %(levelname)s: %(message)s (%(filename)s:%(lineno)s) (%(process)s)",
"()": ColorfulFormatter,
},
},
},
"loggers": {
"milvus": {
"handlers": ["console"],
"level": LOG_LEVEL,
"handlers": {
"console": {
"class": "logging.StreamHandler",
"formatter": "colorful_console",
},
"no_color_console": {
"class": "logging.StreamHandler",
"formatter": "default",
},
},
},
}

if LOG_LEVEL == "DEBUG":
LOGGING["formatters"] = {
"colorful_console": {
"format": "[%(asctime)s-%(levelname)s-%(name)s]: %(message)s (%(filename)s:%(lineno)s)",
"()": ColorfulFormatter,
"loggers": {
"pymilvus": {"handlers": ["no_color_console"], "level": log_level, "propagate": False},
"pymilvus.milvus_client": {
"handlers": ["no_color_console"],
"level": "INFO",
"propagate": False,
},
},
}
LOGGING["handlers"]["milvus_console"] = {
"class": "logging.StreamHandler",
"formatter": "colorful_console",
}
LOGGING["loggers"]["milvus"] = {
"handlers": ["milvus_console"],
"level": LOG_LEVEL,
}
logging.config.dictConfig(logging_config)

logging.config.dictConfig(LOGGING)

DEBUG_LOG_LEVEL = "debug"
INFO_LOG_LEVEL = "info"
WARN_LOG_LEVEL = "warn"
ERROR_LOG_LEVEL = "error"
init_log("WARNING")

0 comments on commit 218f4b3

Please sign in to comment.