Skip to content

Commit

Permalink
moved sdk logger into another file and refactored logging
Browse files Browse the repository at this point in the history
  • Loading branch information
azurwastaken committed Jul 6, 2024
1 parent 759fdd7 commit 298b664
Show file tree
Hide file tree
Showing 34 changed files with 58 additions and 57 deletions.
2 changes: 1 addition & 1 deletion pragma-sdk/pragma_sdk/common/fetchers/fetchers/binance.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from pragma_sdk.common.fetchers.interface import FetcherInterfaceT
from pragma_sdk.common.fetchers.handlers.hop_handler import HopHandler

from pragma_utils.logger import get_stream_logger
from pragma_sdk.common.logging import get_stream_logger

logger = get_stream_logger()

Expand Down
2 changes: 1 addition & 1 deletion pragma-sdk/pragma_sdk/common/fetchers/fetchers/bitstamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from pragma_sdk.common.types.pair import Pair
from pragma_sdk.common.exceptions import PublisherFetchError
from pragma_sdk.common.fetchers.interface import FetcherInterfaceT
from pragma_utils.logger import get_stream_logger
from pragma_sdk.common.logging import get_stream_logger

logger = get_stream_logger()

Expand Down
2 changes: 1 addition & 1 deletion pragma-sdk/pragma_sdk/common/fetchers/fetchers/bybit.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from pragma_sdk.common.exceptions import PublisherFetchError
from pragma_sdk.common.fetchers.interface import FetcherInterfaceT
from pragma_sdk.common.fetchers.handlers.hop_handler import HopHandler
from pragma_utils.logger import get_stream_logger
from pragma_sdk.common.logging import get_stream_logger

logger = get_stream_logger()

Expand Down
2 changes: 1 addition & 1 deletion pragma-sdk/pragma_sdk/common/fetchers/fetchers/coinbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from pragma_sdk.common.exceptions import PublisherFetchError
from pragma_sdk.common.fetchers.interface import FetcherInterfaceT

from pragma_utils.logger import get_stream_logger
from pragma_sdk.common.logging import get_stream_logger

logger = get_stream_logger()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from pragma_sdk.common.types.pair import Pair
from pragma_sdk.common.exceptions import PublisherFetchError
from pragma_sdk.common.fetchers.interface import FetcherInterfaceT
from pragma_utils.logger import get_stream_logger
from pragma_sdk.common.logging import get_stream_logger

logger = get_stream_logger()

Expand Down
2 changes: 1 addition & 1 deletion pragma-sdk/pragma_sdk/common/fetchers/fetchers/gateio.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from pragma_sdk.common.exceptions import PublisherFetchError
from pragma_sdk.common.fetchers.interface import FetcherInterfaceT
from pragma_sdk.common.fetchers.handlers.hop_handler import HopHandler
from pragma_utils.logger import get_stream_logger
from pragma_sdk.common.logging import get_stream_logger

logger = get_stream_logger()

Expand Down
2 changes: 1 addition & 1 deletion pragma-sdk/pragma_sdk/common/fetchers/fetchers/gecko.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from pragma_sdk.common.exceptions import PublisherFetchError
from pragma_sdk.common.fetchers.interface import FetcherInterfaceT

from pragma_utils.logger import get_stream_logger
from pragma_sdk.common.logging import get_stream_logger

logger = get_stream_logger()

Expand Down
2 changes: 1 addition & 1 deletion pragma-sdk/pragma_sdk/common/fetchers/fetchers/huobi.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from pragma_sdk.common.exceptions import PublisherFetchError
from pragma_sdk.common.fetchers.interface import FetcherInterfaceT
from pragma_sdk.common.fetchers.handlers.hop_handler import HopHandler
from pragma_utils.logger import get_stream_logger
from pragma_sdk.common.logging import get_stream_logger

logger = get_stream_logger()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from pragma_sdk.common.fetchers.handlers.index_aggregator_handler import AssetQuantities
from pragma_sdk.common.exceptions import PublisherFetchError
from pragma_sdk.common.fetchers.interface import FetcherInterfaceT
from pragma_utils.logger import get_stream_logger
from pragma_sdk.common.logging import get_stream_logger

logger = get_stream_logger()

Expand Down
2 changes: 1 addition & 1 deletion pragma-sdk/pragma_sdk/common/fetchers/fetchers/kucoin.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from pragma_sdk.common.exceptions import PublisherFetchError
from pragma_sdk.common.fetchers.interface import FetcherInterfaceT
from pragma_sdk.common.fetchers.handlers.hop_handler import HopHandler
from pragma_utils.logger import get_stream_logger
from pragma_sdk.common.logging import get_stream_logger

logger = get_stream_logger()

Expand Down
2 changes: 1 addition & 1 deletion pragma-sdk/pragma_sdk/common/fetchers/fetchers/mexc.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from pragma_sdk.common.exceptions import PublisherFetchError
from pragma_sdk.common.fetchers.interface import FetcherInterfaceT
from pragma_sdk.common.fetchers.handlers.hop_handler import HopHandler
from pragma_utils.logger import get_stream_logger
from pragma_sdk.common.logging import get_stream_logger

logger = get_stream_logger()

Expand Down
2 changes: 1 addition & 1 deletion pragma-sdk/pragma_sdk/common/fetchers/fetchers/okx.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from pragma_sdk.common.exceptions import PublisherFetchError
from pragma_sdk.common.fetchers.interface import FetcherInterfaceT
from pragma_sdk.common.fetchers.handlers.hop_handler import HopHandler
from pragma_utils.logger import get_stream_logger
from pragma_sdk.common.logging import get_stream_logger

logger = get_stream_logger()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from pragma_sdk.common.exceptions import PublisherFetchError
from pragma_sdk.common.fetchers.interface import FetcherInterfaceT
from pragma_sdk.common.types.currency import Currency
from pragma_utils.logger import get_stream_logger
from pragma_sdk.common.logging import get_stream_logger

logger = get_stream_logger()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from pragma_sdk.common.types.pair import Pair
from pragma_sdk.common.exceptions import PublisherFetchError
from pragma_sdk.common.fetchers.interface import FetcherInterfaceT
from pragma_utils.logger import get_stream_logger
from pragma_sdk.common.logging import get_stream_logger

logger = get_stream_logger()

Expand Down
2 changes: 1 addition & 1 deletion pragma-sdk/pragma_sdk/common/fetchers/fetchers/upbit.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from pragma_sdk.common.types.pair import Pair
from pragma_sdk.common.exceptions import PublisherFetchError
from pragma_sdk.common.fetchers.interface import FetcherInterfaceT
from pragma_utils.logger import get_stream_logger
from pragma_sdk.common.logging import get_stream_logger

logger = get_stream_logger()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from pragma_sdk.common.types.pair import Pair
from pragma_sdk.common.exceptions import PublisherFetchError
from pragma_sdk.common.fetchers.interface import FetcherInterfaceT
from pragma_utils.logger import get_stream_logger
from pragma_sdk.common.logging import get_stream_logger

logger = get_stream_logger()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from pragma_sdk.common.exceptions import PublisherFetchError
from pragma_sdk.common.fetchers.interface import FetcherInterfaceT

from pragma_utils.logger import get_stream_logger
from pragma_sdk.common.logging import get_stream_logger

logger = get_stream_logger()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from pragma_sdk.common.types.pair import Pair
from pragma_sdk.common.exceptions import PublisherFetchError
from pragma_sdk.common.fetchers.interface import FetcherInterfaceT
from pragma_utils.logger import get_stream_logger
from pragma_sdk.common.logging import get_stream_logger

logger = get_stream_logger()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from pragma_sdk.common.types.entry import SpotEntry
from pragma_sdk.common.types.pair import Pair

from pragma_utils.logger import get_stream_logger
from pragma_sdk.common.logging import get_stream_logger

logger = get_stream_logger()

Expand Down
25 changes: 25 additions & 0 deletions pragma-sdk/pragma_sdk/common/logging.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import logging
from logging import Logger
from sys import stdout

logger = logging.getLogger(__name__)

def get_stream_logger() -> Logger:
"""
Return the logger with a stream handler.
Log format: "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
The logger level is set to DEBUG.
There can only be one stream handler.
"""

global logger

logger.setLevel(logging.DEBUG)
stream_handler = logging.StreamHandler(stdout)
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
stream_handler.setFormatter(formatter)
if logger.hasHandlers():
logger.handlers.clear()
logger.addHandler(stream_handler)

return logger
2 changes: 1 addition & 1 deletion pragma-sdk/pragma_sdk/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from asgiref.sync import async_to_sync

from pragma_utils.logger import get_stream_logger
from pragma_sdk.common.logging import get_stream_logger

logger = get_stream_logger()

Expand Down
2 changes: 1 addition & 1 deletion pragma-sdk/pragma_sdk/onchain/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from pragma_sdk.onchain.constants import CHAIN_IDS, CONTRACT_ADDRESSES
from pragma_sdk.onchain.types import Contract
from pragma_sdk.common.types.entry import Entry
from pragma_utils.logger import get_stream_logger
from pragma_sdk.common.logging import get_stream_logger
from pragma_sdk.onchain.mixins import (
NonceMixin,
OracleMixin,
Expand Down
2 changes: 1 addition & 1 deletion pragma-sdk/pragma_sdk/onchain/mixins/oracle.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from pragma_sdk.onchain.types import Contract
from pragma_sdk.common.types.entry import Entry, FutureEntry, SpotEntry
from pragma_utils.logger import get_stream_logger
from pragma_sdk.common.logging import get_stream_logger

from pragma_sdk.common.types.types import AggregationMode
from pragma_sdk.common.types.asset import Asset
Expand Down
2 changes: 1 addition & 1 deletion pragma-sdk/pragma_sdk/onchain/mixins/randomness.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from pragma_sdk.onchain.abis.abi import ABIS
from pragma_sdk.onchain.constants import RANDOMNESS_REQUEST_EVENT_SELECTOR
from pragma_sdk.onchain.types import Contract
from pragma_utils.logger import get_stream_logger
from pragma_sdk.common.logging import get_stream_logger
from pragma_sdk.onchain.types import (
VRFCancelParams,
VRFRequestParams,
Expand Down
2 changes: 1 addition & 1 deletion pragma-sdk/tests/integration/fixtures/clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

from tests.integration.fixtures.devnet import get_available_port

from pragma_utils.logger import get_stream_logger
from pragma_sdk.common.logging import get_stream_logger

logger = get_stream_logger()

Expand Down
2 changes: 1 addition & 1 deletion pragma-sdk/tests/integration/fixtures/fetchers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import json

import pytest
from pragma_utils.logger import get_stream_logger
from pragma_sdk.common.logging import get_stream_logger
from tests.integration.fetchers.fetcher_configs import (
FETCHER_CONFIGS,
FUTURE_FETCHER_CONFIGS,
Expand Down
2 changes: 1 addition & 1 deletion pragma-sdk/tests/integration/update_client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from starknet_py.contract import Contract, DeclareResult
from starknet_py.net.client_errors import ClientError

from pragma_utils.logger import get_stream_logger
from pragma_sdk.common.logging import get_stream_logger
from pragma_sdk.onchain.client import PragmaOnChainClient
from pragma_sdk.common.utils import str_to_felt
from tests.integration.utils import get_deployments, read_contract
Expand Down
2 changes: 1 addition & 1 deletion pragma-sdk/tests/integration/vrf_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from tests.integration.utils import ExtendedPragmaClient as PragmaClient
from tests.integration.utils import convert_to_wei, read_contract, wait_for_acceptance

from pragma_utils.logger import get_stream_logger
from pragma_sdk.common.logging import get_stream_logger

logger = get_stream_logger()

Expand Down
2 changes: 1 addition & 1 deletion pragma-sdk/tests/unit/api_client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import pytest
from aioresponses import aioresponses

from pragma_utils.logger import get_stream_logger
from pragma_sdk.common.logging import get_stream_logger
from pragma_sdk.offchain.client import PragmaAPIClient
from pragma_sdk.offchain.exceptions import PragmaAPIError
from tests.integration.constants import MOCK_DIR, SAMPLE_PAIRS
Expand Down
25 changes: 0 additions & 25 deletions pragma-utils/pragma_utils/logger.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,5 @@
import logging
from logging import Logger
from sys import stdout

logger = logging.getLogger(__name__)


def get_stream_logger() -> Logger:
"""
Return the logger with a stream handler.
Log format: "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
The logger level is set to DEBUG.
There can only be one stream handler.
"""

global logger

logger.setLevel(logging.DEBUG)
stream_handler = logging.StreamHandler(stdout)
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
stream_handler.setFormatter(formatter)
if logger.hasHandlers():
logger.handlers.clear()
logger.addHandler(stream_handler)

return logger


def setup_logging(logger: Logger, log_level: str) -> None:
"""
Expand Down
2 changes: 1 addition & 1 deletion pragma-utils/pragma_utils/retries.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from typing import Callable, Optional, TypeVar, Any, Awaitable

from pragma_utils.logger import get_stream_logger
from pragma_sdk.common.logging import get_stream_logger

logger = get_stream_logger()
T = TypeVar("T")
Expand Down
3 changes: 2 additions & 1 deletion price-pusher/price_pusher/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
from pragma_sdk.onchain.client import PragmaOnChainClient
from pragma_sdk.offchain.client import PragmaAPIClient

from pragma_utils.logger import (setup_logging, get_stream_logger)
from pragma_utils.logger import setup_logging
from pragma_sdk.common.logging import get_stream_logger
from pragma_utils.cli import load_private_key_from_cli_arg

from price_pusher.core.poller import PricePoller
Expand Down
2 changes: 1 addition & 1 deletion stagecoach/jobs/publishers/checkpoint/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import boto3

from pragma_sdk.common.assets import get_asset_spec_for_pair_id_by_type
from pragma_utils.logger import get_stream_logger
from pragma_sdk.common.logging import get_stream_logger
from pragma_sdk.common.utils import currency_pair_to_pair_id
from pragma_sdk.onchain.client import PragmaOnChainClient

Expand Down
2 changes: 1 addition & 1 deletion stagecoach/jobs/randomness/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import boto3

from pragma_sdk.onchain.client import PragmaOnChainClient
from pragma_utils.logger import get_stream_logger
from pragma_sdk.common.logging import get_stream_logger

START_BLOCK = int(os.environ.get("START_BLOCK", 0))
NETWORK = os.environ.get("NETWORK", "sepolia")
Expand Down

0 comments on commit 298b664

Please sign in to comment.