summaryrefslogtreecommitdiff
path: root/write.py
diff options
context:
space:
mode:
authorlittleblack111 <littleblack11111@gmail.com>2023-10-16 18:52:53 +0800
committerlittleblack111 <littleblack11111@gmail.com>2023-10-16 18:52:53 +0800
commit3b2405bad9072f4341761c767efc078185d9d0c7 (patch)
tree22897bc29b7eadfe8781aa342db4540a4f52266a /write.py
parent15eacd04eb3ba0c4b6fe7502f30d1c9e2055bf6f (diff)
init
Diffstat (limited to 'write.py')
-rw-r--r--write.py46
1 files changed, 46 insertions, 0 deletions
diff --git a/write.py b/write.py
new file mode 100644
index 0000000..d1537aa
--- /dev/null
+++ b/write.py
@@ -0,0 +1,46 @@
+from stdlib import *
+from sys import argv
+from datetime import datetime
+
+def convert_PRIORITY(priority) -> str:
+ try:
+ priority = int(priority[1])
+ if priority == 1:
+ priority = "DEBUG"
+ elif priority == 2:
+ priority = "INFO"
+ elif priority == 3:
+ priority = "WARNING"
+ elif priority == 4:
+ priority = "ERROR"
+ elif priority == 5:
+ priority = "CRITICAL"
+ elif priority == 6:
+ priority = "FATAL"
+ except ValueError:
+ if priority not in ["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"]:
+ raise ValueError("Invalid argument")
+
+ return priority
+
+
+# main function(process)
+def log_message(priority: int, message: str):
+ priority = convert_PRIORITY(priority)
+ current_date = datetime.now()
+ return f"[{current_date.date()} {current_date.strftime('%A')} {current_date.hour:02d}:{current_date.minute:02d}] [{priority}]: {message}"
+
+# main function(ui)
+def main():
+ priority = ainputf("Priority of log messages: ")
+
+ # check if priority is valid
+
+ message = ainputf("Message to log: ")
+
+ aprintf(log_message(priority, message))
+
+if __name__ == "__main__" and not len(argv) == 3:
+ main()
+elif len(argv) == 3:
+ print(log_message(argv[1], argv[2])) \ No newline at end of file