Skip to content

Commit

Permalink
formatting logs
Browse files Browse the repository at this point in the history
  • Loading branch information
siyangqiu committed May 16, 2024
1 parent 87b3acf commit 4be7b29
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion agentops/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ def start_session(self, tags: Optional[List[str]] = None, config: Optional[Confi
self._session = None
return logger.warning("Cannot start session - No server response")

logger.info('View info on this session at https://app.agentops.ai/drilldown?session_id=%s',
logger.info('\x1b[34mView info on this session at https://app.agentops.ai/drilldown?session_id=%s\x1b[0m',
self._session.session_id)

return self._session.session_id
Expand Down
22 changes: 20 additions & 2 deletions agentops/log_config.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,28 @@
import logging

class AgentOpsFormatter(logging.Formatter):
blue = "\x1b[34m"
bold_red = "\x1b[31;1m"
reset = "\x1b[0m"
format = "🖇 AgentOps: %(message)s"

FORMATS = {
logging.DEBUG: "(DEBUG) " + format,
logging.INFO: format,
logging.WARNING: format,
logging.ERROR: format,
logging.CRITICAL: bold_red + format + reset,
}

def format(self, record):
log_fmt = self.FORMATS.get(record.levelno)
formatter = logging.Formatter(log_fmt)
return formatter.format(record)

logger = logging.getLogger("agentops")
logger.setLevel(logging.CRITICAL)

handler = logging.StreamHandler()
handler.setLevel(logging.DEBUG)
formatter = logging.Formatter('🖇 AgentOps: %(message)s')
handler.setFormatter(formatter)
handler.setFormatter(AgentOpsFormatter())
logger.addHandler(handler)

0 comments on commit 4be7b29

Please sign in to comment.