Skip to content

Commit

Permalink
refactor: remove ntlogger (#2138)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yongxuanzhang authored and deepankarm committed Mar 10, 2021
1 parent 19dcfd0 commit e3f8983
Showing 1 changed file with 0 additions and 87 deletions.
87 changes: 0 additions & 87 deletions jina/logging/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import logging.handlers
import os
import platform
import re
import sys
from typing import Optional

Expand All @@ -16,92 +15,6 @@
from ..jaml import JAML


class NTLogger:
"""A compatible logger for Windows system, colors are all removed to keep compatible."""

def __init__(self, context: str, log_level: 'LogVerbosity' = LogVerbosity.INFO):
"""
Create a compatible logger for Windows system, colors are all removed to keep compatible.
:param context: The name prefix of each log.
:param log_level: Level of log.
"""
self.context = self._planify(context)
self.log_level = log_level

@staticmethod
def _planify(msg):
return re.sub(r'\u001b\[.*?[@-~]', '', msg)

def info(self, msg: str, **kwargs):
"""
Log info-level message.
:param kwargs: Keyword arguments.
:param msg: Context of log.
"""
if self.log_level <= LogVerbosity.INFO:
sys.stdout.write(f'{self.context}[I]:{self._planify(msg)}')

def critical(self, msg: str, **kwargs):
"""
Log critical-level message.
:param kwargs: Keyword arguments.
:param msg: Context of log.
"""
if self.log_level <= LogVerbosity.CRITICAL:
sys.stdout.write(f'{self.context}[C]:{self._planify(msg)}')

def debug(self, msg: str, **kwargs):
"""
Log debug-level message.
:param kwargs: Keyword arguments.
:param msg: Content of log.
"""
if self.log_level <= LogVerbosity.DEBUG:
sys.stdout.write(f'{self.context}[D]:{self._planify(msg)}')

def error(self, msg: str, **kwargs):
"""
Log error-level message.
:param kwargs: Keyword arguments.
:param msg: Context of log.
"""
if self.log_level <= LogVerbosity.ERROR:
sys.stdout.write(f'{self.context}[E]:{self._planify(msg)}')

def warning(self, msg: str, **kwargs):
"""
Log warning-level message.
:param kwargs: Keyword arguments.
:param msg: Context of log.
"""
if self.log_level <= LogVerbosity.WARNING:
sys.stdout.write(f'{self.context}[W]:{self._planify(msg)}')

def success(self, msg: str, **kwargs):
"""
Log success-level message.
:param msg: Context of log.
:param kwargs: Keyword arguments.
"""
if self.log_level <= LogVerbosity.SUCCESS:
sys.stdout.write(f'{self.context}[S]:{self._planify(msg)}')


class PrintLogger(NTLogger):
"""Print the message."""

@staticmethod
def _planify(msg):
return msg


class SysLogHandlerWrapper(logging.handlers.SysLogHandler):
"""
Override the priority_map :class:`SysLogHandler`.
Expand Down

0 comments on commit e3f8983

Please sign in to comment.