Logging with loguru (#708)

* logging

* requirements

* add loguru dependency

* restore it

* add loguru

* set log level in .env file

* remove service fee print

* set log level

* more logging

* more logging

* more logging

* pyament.checking_id

* fix
This commit is contained in:
calle
2022-07-07 14:30:16 +02:00
committed by GitHub
parent 847fd18796
commit 089313f613
40 changed files with 202 additions and 81 deletions
+4 -2
View File
@@ -5,6 +5,8 @@ import urllib.parse
from os import getenv
from typing import AsyncGenerator, Dict, Optional
from loguru import logger
import httpx
from websockets import connect
from websockets.exceptions import (
@@ -193,8 +195,8 @@ class EclairWallet(Wallet):
ConnectionClosedError,
ConnectionClosed,
) as ose:
print("OSE", ose)
logger.error("OSE", ose)
pass
print("lost connection to eclair's websocket, retrying in 5 seconds")
logger.error("lost connection to eclair's websocket, retrying in 5 seconds")
await asyncio.sleep(5)
+6 -5
View File
@@ -1,11 +1,12 @@
import asyncio
import json
import httpx
from os import getenv
from datetime import datetime, timedelta
from datetime import datetime
from typing import Optional, Dict, AsyncGenerator
import random
import string
from loguru import logger
from lnbits.helpers import urlsafe_short_hash
import hashlib
from ..bolt11 import encode, decode
@@ -20,7 +21,7 @@ from .base import (
class FakeWallet(Wallet):
async def status(self) -> StatusResponse:
print(
logger.info(
"FakeWallet funding source is for using LNbits as a centralised, stand-alone payment system with brrrrrr."
)
return StatusResponse(None, float("inf"))
+5 -1
View File
@@ -4,6 +4,8 @@ import httpx
from os import getenv
from typing import Optional, Dict, AsyncGenerator
from loguru import logger
from .base import (
StatusResponse,
InvoiceResponse,
@@ -144,5 +146,7 @@ class LNbitsWallet(Wallet):
except (OSError, httpx.ReadError, httpx.ConnectError, httpx.ReadTimeout):
pass
print("lost connection to lnbits /payments/sse, retrying in 5 seconds")
logger.error(
"lost connection to lnbits /payments/sse, retrying in 5 seconds"
)
await asyncio.sleep(5)
+7 -2
View File
@@ -11,6 +11,9 @@ import base64
import hashlib
from os import environ, error, getenv
from typing import Optional, Dict, AsyncGenerator
from loguru import logger
from .macaroon import load_macaroon, AESCipher
if imports_ok:
@@ -187,6 +190,8 @@ class LndWallet(Wallet):
checking_id = stringify_checking_id(i.r_hash)
yield checking_id
except error:
print(error)
logger.error(error)
print("lost connection to lnd InvoiceSubscription, please restart lnbits.")
logger.error(
"lost connection to lnd InvoiceSubscription, please restart lnbits."
)
+5 -1
View File
@@ -6,6 +6,8 @@ import base64
from os import getenv
from typing import Optional, Dict, AsyncGenerator
from loguru import logger
from lnbits import bolt11 as lnbits_bolt11
from .macaroon import load_macaroon, AESCipher
@@ -191,5 +193,7 @@ class LndRestWallet(Wallet):
except (OSError, httpx.ConnectError, httpx.ReadError):
pass
print("lost connection to lnd invoices stream, retrying in 5 seconds")
logger.error(
"lost connection to lnd invoices stream, retrying in 5 seconds"
)
await asyncio.sleep(5)
+3 -1
View File
@@ -6,6 +6,8 @@ from os import getenv
from http import HTTPStatus
from typing import Optional, Dict, AsyncGenerator
from loguru import logger
from .base import (
StatusResponse,
InvoiceResponse,
@@ -127,7 +129,7 @@ class LNPayWallet(Wallet):
try:
data = json.loads(text)
except json.decoder.JSONDecodeError:
print(f"got something wrong on lnpay webhook endpoint: {text[:200]}")
logger.error(f"got something wrong on lnpay webhook endpoint: {text[:200]}")
data = None
if (
type(data) is not dict
+5 -1
View File
@@ -4,6 +4,8 @@ import httpx
from os import getenv
from typing import Optional, Dict, AsyncGenerator
from loguru import logger
from .base import (
StatusResponse,
InvoiceResponse,
@@ -143,5 +145,7 @@ class LntxbotWallet(Wallet):
except (OSError, httpx.ReadError, httpx.ReadTimeout, httpx.ConnectError):
pass
print("lost connection to lntxbot /payments/stream, retrying in 5 seconds")
logger.error(
"lost connection to lntxbot /payments/stream, retrying in 5 seconds"
)
await asyncio.sleep(5)
+4 -2
View File
@@ -4,6 +4,8 @@ import base64
from hashlib import md5
import getpass
from loguru import logger
BLOCK_SIZE = 16
import getpass
@@ -103,5 +105,5 @@ if __name__ == "__main__":
macaroon = input("Enter macaroon: ")
macaroon = load_macaroon(macaroon)
macaroon = AESCipher(description="encryption").encrypt(macaroon.encode())
print("Encrypted macaroon:")
print(macaroon)
logger.info("Encrypted macaroon:")
logger.info(macaroon)
+3 -1
View File
@@ -8,6 +8,8 @@ from http import HTTPStatus
from os import getenv
from typing import Optional, AsyncGenerator
from loguru import logger
from .base import (
StatusResponse,
InvoiceResponse,
@@ -139,7 +141,7 @@ class OpenNodeWallet(Wallet):
x = hmac.new(self.auth["Authorization"].encode("ascii"), digestmod="sha256")
x.update(charge_id.encode("ascii"))
if x.hexdigest() != data["hashed_order"]:
print("invalid webhook, not from opennode")
logger.error("invalid webhook, not from opennode")
raise HTTPException(status_code=HTTPStatus.NO_CONTENT)
await self.queue.put(charge_id)
+3 -1
View File
@@ -5,6 +5,8 @@ import random
from os import getenv
from typing import Optional, AsyncGenerator
from loguru import logger
from .base import (
StatusResponse,
InvoiceResponse,
@@ -204,5 +206,5 @@ class SparkWallet(Wallet):
except (OSError, httpx.ReadError, httpx.ConnectError, httpx.ReadTimeout):
pass
print("lost connection to spark /stream, retrying in 5 seconds")
logger.error("lost connection to spark /stream, retrying in 5 seconds")
await asyncio.sleep(5)
+3 -1
View File
@@ -1,5 +1,7 @@
from typing import AsyncGenerator, Optional
from loguru import logger
from .base import (
InvoiceResponse,
PaymentResponse,
@@ -20,7 +22,7 @@ class VoidWallet(Wallet):
raise Unsupported("")
async def status(self) -> StatusResponse:
print(
logger.info(
"This backend does nothing, it is here just as a placeholder, you must configure an actual backend before being able to do anything useful with LNbits."
)
return StatusResponse(None, 0)