summaryrefslogtreecommitdiff
path: root/write.py
blob: d1537aa6708a93cb6429766d2003623fda227417 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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]))