Skip to content

Commit

Permalink
log: refactor all to log.logging
Browse files Browse the repository at this point in the history
  • Loading branch information
naisanzaa committed Dec 22, 2023
1 parent 09dbb46 commit 43e7962
Show file tree
Hide file tree
Showing 97 changed files with 922 additions and 939 deletions.
6 changes: 4 additions & 2 deletions automon/helpers/assertions.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import re
from ast import literal_eval

from automon.log import Logging
from automon import log

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

log = Logging(__name__, Logging.DEBUG)


def make_tuple(obj: str) -> tuple:
Expand Down
6 changes: 3 additions & 3 deletions automon/helpers/asyncioWrapper/loop.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import asyncio

from automon.log import logger
from automon import log

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


def get_event_loop():
Expand Down
9 changes: 5 additions & 4 deletions automon/helpers/cpu.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import psutil

from automon.log import Logging
from automon import log

log = Logging('cpu', level=Logging.DEBUG)
logger = log.logging.getLogger(__name__)
logger.setLevel(log.DEBUG)


def cpu_usage(max_cpu_percentage=80):
"""Limit max cpu usage
"""
if psutil.cpu_percent() < max_cpu_percentage:
log.debug(f'[{cpu_usage.__name__}] {psutil.cpu_percent()}%')
logger.debug(f'[{cpu_usage.__name__}] {psutil.cpu_percent()}%')
return True
else:
log.debug(f'[{cpu_usage.__name__}] {psutil.cpu_percent()}%')
logger.debug(f'[{cpu_usage.__name__}] {psutil.cpu_percent()}%')
return False
11 changes: 6 additions & 5 deletions automon/helpers/grok/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
import warnings
import pandas as pd

from automon.log import Logging
from automon import log

logger = log.logging.getLogger(__name__)
logger.setLevel(log.ERROR)


class Grok:
def __init__(self):
self._log = Logging(name=Grok.__name__, level=Logging.DEBUG)

p = 'logstash-patterns-core/patterns'
l = f'{os.path.join(os.path.split(os.path.realpath(__file__))[0])}'
Expand Down Expand Up @@ -49,7 +51,7 @@ def expanded_dict(self, patterns: list) -> pd.DataFrame:
# if k not in big_dict.keys():
# big_dict[k] = v
# else:
# self._log.info(f'skipping existing, {k}')
# logger.info(f'skipping existing, {k}')

df = pd.DataFrame(pd.concat(patterns))
return df
Expand Down Expand Up @@ -202,7 +204,6 @@ class GrokLegacy:
'LOGLEVEL'] = '([Aa]lert|ALERT|[Tt]race|TRACE|[Dd]ebug|DEBUG|[Nn]otice|NOTICE|[Ii]nfo|INFO|[Ww]arn?(?:ing)?|WARN?(?:ING)?|[Ee]rr?(?:or)?|ERR?(?:OR)?|[Cc]rit?(?:ical)?|CRIT?(?:ICAL)?|[Ff]atal|FATAL|[Ss]evere|SEVERE|EMERG(?:ENCY)?|[Ee]merg(?:ency)?)'

def __init__(self):
self._log = Logging(GrokLegacy.__name__, Logging.DEBUG)

self.url = 'https://raw.githubusercontent.com/logstash-plugins/logstash-patterns-core/master/patterns/grok-patterns'
# self.file = f'{os.path.split(os.path.realpath(__file__))[0]}/grok-patterns.txt'
Expand All @@ -223,7 +224,7 @@ def __init__(self):
# else:
# section.append(line)
#
# self._log.debug(line)
# logger.debug(line)

# build dict from file

Expand Down
8 changes: 5 additions & 3 deletions automon/helpers/nest_asyncioWrapper/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@
import logging
import nest_asyncio

from automon.log import Logging
from automon import log

logging.getLogger("asyncio").setLevel(Logging.ERROR)
logger = log.logging.getLogger(__name__)
logger.setLevel(log.ERROR)

log.logging.getLogger("asyncio").setLevel(log.ERROR)


class AsyncStarter:

def __init__(self) -> asyncio.get_event_loop:
self._log = Logging(name=AsyncStarter.__name__, level=Logging.DEBUG)

self.event_loop = asyncio.get_event_loop()
self.maxqueue = 1000
Expand Down
9 changes: 5 additions & 4 deletions automon/helpers/networking.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import socket
from urllib.parse import urlparse

from automon.log import Logging
from automon import log

log = Logging(name='Networking', level=Logging.INFO)
logger = log.logging.getLogger(__name__)
logger.setLevel(log.INFO)


class Networking:
Expand All @@ -23,10 +24,10 @@ def check_connection(url, timeout: int = 1):
s.settimeout(timeout)
s.connect((host, port))
s.close()
log.debug(f'SUCCESS {url}')
logger.debug(f'SUCCESS {url}')
return True
except Exception as e:
log.error(f'{url} {e}', enable_traceback=False)
logger.error(f'{url} {e}')
return False

@staticmethod
Expand Down
2 changes: 1 addition & 1 deletion automon/helpers/sleeper.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def seconds(seconds: int) -> time.sleep:
"""Sleep for this many seconds"""

sleep = seconds
log.debug(f'{sleep}')
logger.debug(f'{sleep}')
return time.sleep(sleep)

@staticmethod
Expand Down
16 changes: 8 additions & 8 deletions automon/helpers/subprocessWrapper/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
from pprint import pprint
from subprocess import PIPE

from automon.log import logger
from automon import log
from automon.helpers.dates import Dates

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


class Run:
Expand Down Expand Up @@ -77,7 +77,7 @@ def run(self, command: str = None,
if sanitize_command:
command = self._command(self.command)

log.debug(f'[command] {command}')
logger.debug(f'[command] {command}')

try:
if inBackground:
Expand Down Expand Up @@ -116,17 +116,17 @@ def run(self, command: str = None,
self.returncode = self.call.returncode

if self.stdout:
log.debug(f'[stdout] {stdout}')
logger.debug(f'[stdout] {stdout}')

if self.stderr:
log.error(f'[stderr] {stderr}')
logger.error(f'[stderr] {stderr}')

if self.returncode == 0:
return True

except Exception as e:
self.stderr = f'{e}'.encode()
log.error(f'{e}')
logger.error(f'{e}')

return False

Expand All @@ -139,7 +139,7 @@ def _command(self, command: str) -> list:

for arg in split_command:
if '|' in arg:
log.warning(f'Pipes are not supported! {split_command}')
logger.warning(f'Pipes are not supported! {split_command}')

return self.command

Expand Down
File renamed without changes.
9 changes: 5 additions & 4 deletions automon/integrations/beautifulsoupWrapper/client.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from bs4 import BeautifulSoup

from automon.log import Logging
from automon import log

log = Logging(name='BeautifulSoupClient', level=Logging.DEBUG)
logger = log.logging.getLogger(__name__)
logger.setLevel(log.DEBUG)


class BeautifulSoupClient(object):
Expand All @@ -17,8 +18,8 @@ def read_markup(self, markup: str, features: str = 'lxml'):
markup=markup or self.markup,
features=features
)
log.info(f'read_markup success ({len(markup)} B)')
logger.info(f'read_markup success ({len(markup)} B)')
except Exception as e:
log.error(f'read_markup failed ({len(markup)} B): {e}')
logger.error(f'read_markup failed ({len(markup)} B): {e}')

return self
16 changes: 9 additions & 7 deletions automon/integrations/cryptocurrency/accounting.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import os

from automon.log import Logging
from automon import log

from .robinhood import Robinhood
from .coinbase import Coinbase
from .other import Other

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


class CryptoAccounting:

def __init__(self, csvs: str = None):
self._log = Logging(name=CryptoAccounting.__name__, level=Logging.DEBUG)

self.accounts = []

Expand All @@ -28,17 +30,17 @@ def __init__(self, csvs: str = None):
self.auto_detect(file_path)

def auto_detect(self, csv):
self._log.debug(f'supported exchanges: {self.supported_exchanges}')
logger.debug(f'supported exchanges: {self.supported_exchanges}')
for exchange in self.supported_exchanges:
self._log.debug(f'reading exchange: {exchange}')
logger.debug(f'reading exchange: {exchange}')
x = exchange(csv)
if x.is_match:
self._log.debug(f'exchange matched: {exchange}')
logger.debug(f'exchange matched: {exchange}')
if x not in self.accounts:
self._log.info(f'added {x}')
logger.info(f'added {x}')
self.accounts.append(x)
return True
self._log.debug(f'already added: {x}')
logger.debug(f'already added: {x}')
else:
o = Other(csv)
if o not in self.accounts:
Expand Down
6 changes: 4 additions & 2 deletions automon/integrations/cryptocurrency/coinbase.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from automon.log import Logging
from automon import log
from automon.integrations.datascience import Pandas

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


class Coinbase:
def __init__(self, csv):
self._log = Logging(name=Coinbase.__name__, level=Logging.DEBUG)

self.csv = None
self.df = None
Expand Down
16 changes: 8 additions & 8 deletions automon/integrations/cryptocurrency/other.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from automon.log import Logging
from automon import log
from automon.integrations.datascience import Pandas

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


class Other:
def __init__(self, csv):
self._log = Logging(name=Other.__name__, level=Logging.DEBUG)

self.csv = csv
self.df = OtherCSV(csv).df

Expand All @@ -14,15 +15,14 @@ def __repr__(self):

def __eq__(self, other):
if self.df.equals(other.df):
self._log.debug(f'same {other}')
logger.debug(f'same {other}')
return True
self._log.debug(f'different {other}')
logger.debug(f'different {other}')
return False


class OtherCSV:
def __init__(self, csv):
self._log = Logging(name=OtherCSV.__name__, level=Logging.DEBUG)

self.csv = csv
self.df = Pandas().read_csv(csv)
Expand All @@ -33,7 +33,7 @@ def __repr__(self):
def __eq__(self, other):
if isinstance(other, OtherCSV):
if self.df == other.df:
self._log.debug(f'same {other}')
logger.debug(f'same {other}')
return True
self._log.debug(f'different {other}')
logger.debug(f'different {other}')
return False
15 changes: 8 additions & 7 deletions automon/integrations/cryptocurrency/robinhood.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from automon.log import Logging
from automon import log
from automon.integrations.datascience import Pandas

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


class Robinhood:
def __init__(self, csv):
self._log = Logging(name=Robinhood.__name__, level=Logging.DEBUG)

self.csv = None
self.df = None
Expand All @@ -13,7 +15,7 @@ def __init__(self, csv):

r = RobinhoodCSV(csv)
if r.matches:
self._log.info(f'matched {r}')
logger.info(f'matched {r}')
self.is_match = True
self.csv = csv
self.df = r.df
Expand All @@ -39,14 +41,13 @@ def __init__(self, csv):
ASSET NAME,RECEIVED DATE,COST BASIS(USD),DATE SOLD,PROCEEDS
"""
self._log = Logging(name=RobinhoodCSV.__name__, level=Logging.DEBUG)

self.csv = csv
self.df = None
self.matches = None

if 'Provider: Robinhood Crypto LLC' in Pandas().read_csv(csv):
self._log.debug(f'matched {csv}')
logger.debug(f'matched {csv}')
self.matches = True

with open(csv) as f:
Expand All @@ -60,7 +61,7 @@ def __repr__(self):
def __eq__(self, other):
if isinstance(other, RobinhoodCSV):
if self.df == other.df:
self._log.debug(f'same {other}')
logger.debug(f'same {other}')
return True
self._log.debug(f'different {other}')
logger.debug(f'different {other}')
return False
8 changes: 5 additions & 3 deletions automon/integrations/datascience/pandas/dataframe.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import pandas

from automon.log import Logging
from automon import log

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


def DataFrame(*args, **kwargs) -> pandas.DataFrame:
log = Logging('DataFrame', level=Logging.ERROR)
df = pandas.DataFrame(*args, **kwargs)
log.debug(df)
logger.debug(df)
return df
Loading

0 comments on commit 43e7962

Please sign in to comment.