what should I add to my library? import time import os class Logger: def init(self):…
- User
what should I add to my library? import time import os
class Logger: def init(self): self.default_colors = { "suc": "\x1b[32;1m", # Green "err": "\x1b[31;1m", # Red "dbg": "\x1b[38;5;244m", # Gray "wrn": "\x1b[38;5;202m", # Orange "time": "\x1b[33m", # Yellow "field": "\x1b[35m", # Purple "RESET": "\x1b[0m", # Reset Styling, should not be changed }
codeself.colors = self.default_colors.copy() def set_color(self, color, value): self.colors[color] = value def reset_color(self): self.colors = self.default_colors.copy() def __log(self, color: str, type: str, text: str, fields = []): time_color = self.colors['time'] reset_color = self.colors['RESET'] field_color = self.colors['field'] primary_color = self.colors[color] now = time.localtime() current_time = time.strftime("%H:%M:%S", now) msg = f"{time_color}{current_time}{reset_color} {primary_color}{type}{reset_color} {text}" for field in fields: msg = f"{msg} {field_color}{field[0]}: {reset_color}{field[1]} " print(msg) def log_suc(self, text: str, fields = []): self.__log('suc', 'SUC', text, fields) def log_err(self, text: str, fields = []): self.__log('err', 'ERR', text, fields) def log_dbg(self, text: str, fields = []): self.__log('dbg', 'DBG', text, fields) def log_wrn(self, text: str, fields = []): self.__log('wrn', 'WRN', text, fields) def clear_terminal(self): if os.name == 'nt': os.system('cls') else: os.system('clear')if name == "main": print('\n') logger = Logger() logger.log_suc("Text", [["field1", "data"], ["field2", "data"]]) logger.log_err("Text", [["field1", "data"], ["field2", "data"]]) logger.log_dbg("Text", [["field1", "data"], ["field2", "data"]]) logger.log_wrn("Text", [["field1", "data"], ["field2", "data"]])
- Assistant
Your library currently provides a Logger class that allows you to log messages with different colors and fields. Here are a few suggestions on what you can add to your library:
-
Logging to files: Add a feature that allows logging messages to a file, in addition to printing them to the console.
-
Logging levels: Implement logging levels such as DEBUG, INFO, WARNING, and ERROR. You can add methods like log_info, log_warning, and log_error that will only print messages if the logging level is set accordingly.
-
Formatting options: Allow users to customize the log message format by providing options to change the timestamp format, color codes, and field separators.
-
Log filtering: Add the ability to filter log messages based on different criteria, such as log level or specific fields.
-
Log rotation: Implement a feature that rotates log files after reaching a certain size or on a specified time interval. This will help manage log files and prevent them from becoming too large.
-
- User
well these are nice sugggestions but thats not really what my library is for, its meant to more give you an idea on how your program is doing and if it even is doing anything, I might add the debug level though
- Assistant
I apologize for the misunderstanding. If your library is primarily focused on providing information about your program's execution and progress, adding a debug level would be a great addition. This would allow users to enable or disable debug logging based on their needs, providing more granular control over the displayed information.
Additionally, you can consider adding features like:
-
Timestamps: Include an option to display timestamps in the log messages, allowing users to track the timing of different events.
-
Progress tracking: Add methods to track the progress of a task and update the logs accordingly. This can be useful for long-running processes or operations with multiple steps.
-
Log file persistence: Provide an option to save the log messages to a file for future reference or analysis.
-
Verbosity control: Allow users to set the verbosity level of the logger to control the amount of information displayed. This can help tailor the log output to specific needs.
-
Error handling: Implement error handling mechanisms to catch and log any exceptions that occur during program execution. This can help in identifying and debugging issues more efficiently.
-