-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from Klaynight-dev/Klaynight-dev-patch-4
Logs update
- Loading branch information
Showing
5 changed files
with
197 additions
and
687 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,24 @@ | ||
# logs.py | ||
|
||
import os | ||
from datetime import datetime | ||
|
||
def create_log_directory(): | ||
log_directory = 'data/logs/' | ||
if not os.path.exists(log_directory): | ||
os.makedirs(log_directory) | ||
|
||
def get_log_filename(): | ||
now = datetime.now() | ||
log_directory = 'data/logs/' | ||
return f"{log_directory}{now.strftime('%Y-%m-%d_%H')}.log" | ||
|
||
def log_action(action, success=True, error_message=None): | ||
log_filename = get_log_filename() | ||
with open(log_filename, 'a') as log_file: | ||
log_file.write(f"Timestamp: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}\n") | ||
log_file.write(f"Action: {action}\n") | ||
log_file.write(f"Success: {'Yes' if success else 'No'}\n") | ||
if not success and error_message: | ||
log_file.write(f"Error: {error_message}\n") | ||
log_file.write("\n") | ||
|
||
# logs.py | ||
|
||
import os | ||
from datetime import datetime | ||
|
||
def create_log_directory(): | ||
log_directory = 'data/logs/' | ||
if not os.path.exists(log_directory): | ||
os.makedirs(log_directory) | ||
|
||
def get_log_filename(): | ||
now = datetime.now() | ||
log_directory = 'data/logs/' | ||
return f"{log_directory}{now.strftime('%Y-%m-%d_%H')}_log.txt" | ||
|
||
def log_action(action, success=True, error_message=None): | ||
log_filename = get_log_filename() | ||
with open(log_filename, 'a') as log_file: | ||
log_file.write(f"Timestamp: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}\n") | ||
log_file.write(f"Action: {action}\n") | ||
log_file.write(f"Success: {'Yes' if success else 'No'}\n") | ||
if not success and error_message: | ||
log_file.write(f"Error: {error_message}\n") | ||
log_file.write("\n") |
Oops, something went wrong.