Skip to content

Commit

Permalink
Merge pull request #90 from small-thinking/update-logger
Browse files Browse the repository at this point in the history
Update logger
  • Loading branch information
yxjiang authored Jun 15, 2024
2 parents 434e25a + fa2e774 commit 0881196
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
16 changes: 11 additions & 5 deletions polymind/core/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import logging
import os
from enum import Enum
from typing import Any
from typing import Optional

from colorama import Fore, ansi
from dotenv import load_dotenv
Expand Down Expand Up @@ -33,20 +33,26 @@ def __le__(self, other):
def __gt__(self, other):
return self.value > other.value

def __str__(self) -> str:
return self.name

def __repr__(self) -> str:
return self.name

def __new__(cls, *args, **kwargs):
if cls._instance is None:
cls._instance = super().__new__(cls)
return cls._instance

def __init__(self, logger_name: str, verbose: bool = True, level: Any = logging.INFO):
def __init__(self, logger_name: str, verbose: bool = True, level: Optional[LoggingLevel] = None):
if not hasattr(self, "logger"):
load_dotenv(override=True)
self.logging_level = Logger.LoggingLevel[os.getenv("LOGGING_LEVEL", "TOOL")]
self.logging_level = level if level else Logger.LoggingLevel[os.getenv("LOGGING_LEVEL", "TOOL")]
self.logger = logging.getLogger(logger_name)
self.logger.setLevel(level=level)
self.logger.setLevel(level=self.logging_level.value)
self.formatter = logging.Formatter("%(asctime)s %(levelname)s %(message)s (%(filename)s:%(lineno)d)")
self.console_handler = logging.StreamHandler()
self.console_handler.setLevel(level=level)
self.console_handler.setLevel(level=self.logging_level.value)
self.console_handler.setFormatter(self.formatter)
self.logger.addHandler(self.console_handler)

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "polymind"
version = "0.0.50" # Update this version before publishing to PyPI
version = "0.0.51" # Update this version before publishing to PyPI
description = "PolyMind is a customizable collaborative multi-agent framework for collective intelligence and distributed problem solving."
authors = ["TechTao"]
license = "MIT License"
Expand Down

0 comments on commit 0881196

Please sign in to comment.