mirror of
https://github.com/DictXiong/dotfiles.git
synced 2025-07-30 02:50:29 +08:00
use logging
This commit is contained in:
parent
5f398d57ea
commit
fe7fb96fc2
@ -1,13 +1,14 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
import os, uuid, socket, argparse, logging
|
||||||
|
|
||||||
|
namespace = uuid.UUID("cc23b903-1993-44eb-9c90-48bd841eeac3")
|
||||||
|
logging.basicConfig(level=logging.INFO, format="[%(filename)s:%(lineno)d %(levelname)s] %(message)s")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import requests
|
import requests
|
||||||
except ImportError:
|
except ImportError:
|
||||||
print("Please install requests module")
|
logging.fatal("Please install requests module")
|
||||||
exit(1)
|
|
||||||
import os, uuid, socket, argparse
|
|
||||||
|
|
||||||
namespace = uuid.UUID("cc23b903-1993-44eb-9c90-48bd841eeac3")
|
|
||||||
|
|
||||||
def get_uuid_raw() -> str:
|
def get_uuid_raw() -> str:
|
||||||
possible_uuid_files = [
|
possible_uuid_files = [
|
||||||
@ -53,17 +54,17 @@ if __name__ == "__main__":
|
|||||||
uuid = get_uuid()
|
uuid = get_uuid()
|
||||||
content=content.strip()
|
content=content.strip()
|
||||||
if not content:
|
if not content:
|
||||||
print("error: empty log content")
|
logging.error("empty log content")
|
||||||
exit(1)
|
exit(1)
|
||||||
resp = post_log(url, hostname, uuid, content)
|
resp = post_log(url, hostname, uuid, content)
|
||||||
if resp.status_code == 200:
|
if resp.status_code == 200:
|
||||||
print("200 ok")
|
logging.info("200 ok")
|
||||||
exit(0)
|
exit(0)
|
||||||
elif resp.status_code == 403:
|
elif resp.status_code == 403:
|
||||||
print("403 forbidden")
|
logging.error("403 forbidden")
|
||||||
print("you may need to register your hostname and uuid")
|
logging.info("you may need to register your hostname and uuid")
|
||||||
else:
|
else:
|
||||||
print("unknown error")
|
logging.error("unknown error ")
|
||||||
print(f"{resp.status_code}: {resp.text}")
|
logging.error(f"{resp.status_code}: {resp.text}")
|
||||||
print(f"hostname: {hostname}, uuid: {uuid}")
|
logging.info(f"hostname: {hostname}, uuid: {uuid}")
|
||||||
exit(1)
|
exit(1)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user