Add more logging and exception
This commit is contained in:
parent
cb10bb3a4d
commit
ce1c82a192
8 changed files with 56 additions and 19 deletions
|
@ -5,7 +5,7 @@ import requests
|
|||
from logstash_async.transport import HttpTransport
|
||||
from logstash_async.handler import AsynchronousLogstashHandler
|
||||
|
||||
host = 'logs.robo4you.at'
|
||||
host = 'logstash.robo4you.at'
|
||||
port = 443
|
||||
|
||||
logstash_logger = logging.getLogger('logstash')
|
||||
|
@ -16,7 +16,7 @@ transport = HttpTransport(
|
|||
port,
|
||||
username="robo",
|
||||
password="competition",
|
||||
timeout=10.0,
|
||||
timeout=60.0,
|
||||
)
|
||||
|
||||
asynchronousLogstashHandler = AsynchronousLogstashHandler(
|
||||
|
@ -54,19 +54,25 @@ class StreamToLogger(object):
|
|||
asynchronousLogstashHandler.flush()
|
||||
|
||||
try:
|
||||
requests.head(f"http://{host}:{port}")
|
||||
logstash_logger.addHandler(asynchronousLogstashHandler)
|
||||
r = requests.head(f"http://{host}:{port}")
|
||||
if r.status_code == 400:
|
||||
logstash_logger.addHandler(asynchronousLogstashHandler)
|
||||
|
||||
sl = StreamToLogger(logging.INFO)
|
||||
sys.stdout = sl
|
||||
sl = StreamToLogger(logging.INFO)
|
||||
sys.stdout = sl
|
||||
else:
|
||||
print(f"Could not connect to {host} -> {r.status_code}!")
|
||||
|
||||
except requests.exceptions.ConnectionError as identifier:
|
||||
print(f"Could not connect to {host}!")
|
||||
pass
|
||||
|
||||
class Logging(object):
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@staticmethod
|
||||
def get_logger() -> logging.Logger:
|
||||
return logstash_logger
|
||||
|
||||
@staticmethod
|
||||
def set_debug():
|
||||
logstash_logger.setLevel(logging.DEBUG)
|
||||
|
|
Reference in a new issue