Browse Source

Replace print with logger

JoostSijm 3 years ago
parent
commit
55224bec6f
2 changed files with 15 additions and 12 deletions
  1. 7 4
      src/rival_regions_marketbot/__init__.py
  2. 8 8
      src/rival_regions_marketbot/__main__.py

+ 7 - 4
src/rival_regions_marketbot/__init__.py

@@ -25,11 +25,14 @@ STREAM_HANDLER = logging.StreamHandler()
 STREAM_HANDLER.setLevel(logging.INFO)
 
 # create formatter and add it to the handlers
-FORMATTER = logging.Formatter(
-    "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
+STREAM_FORMATTER = logging.Formatter(
+    "%(name)s - %(module)s - %(levelname)s - %(message)s"
 )
-STREAM_HANDLER.setFormatter(FORMATTER)
-FILE_HANDLER.setFormatter(FORMATTER)
+STREAM_HANDLER.setFormatter(STREAM_FORMATTER)
+FILE_FORMATTER = logging.Formatter(
+    "%(asctime)s - %(name)s - %(module)s - %(levelname)s - %(message)s"
+)
+FILE_HANDLER.setFormatter(FILE_FORMATTER)
 
 # add the handlers to logger
 LOGGER.addHandler(STREAM_HANDLER)

+ 8 - 8
src/rival_regions_marketbot/__main__.py

@@ -3,7 +3,7 @@
 import time
 from datetime import datetime
 
-from rival_regions_marketbot import marketbot
+from rival_regions_marketbot import LOGGER, marketbot
 
 
 while True:
@@ -71,17 +71,17 @@ while True:
         1,
     ]
 
+    LOGGER.info("Looping through resources")
     for index, item in enumerate(items):
-        print("Buy:  {}".format(item))
+        LOGGER.info("Buying: %s", item)
         marketbot.buy(items[index], buy_price[index])
-        print("Sell: {}".format(item))
+        LOGGER.info("Selling: %s", item)
         marketbot.sell(items[index], sell_price[index])
 
     SECONDS = 301
-    print(
-        "Current Time: {}, waiting for {} seconds".format(
-            datetime.now().strftime("%H:%M:%S"),
-            SECONDS,
-        )
+    LOGGER.info(
+        "Current Time: %s, waiting for %s seconds",
+        datetime.now().strftime("%H:%M:%S"),
+        SECONDS,
     )
     time.sleep(SECONDS)