Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 25 additions & 8 deletions src/main.py
Comment thread
Raihan93-coder marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
################################################################################

import argparse, logging, sys, multiprocessing, tempfile
from datetime import datetime
import packages.buskill

################################################################################
Expand All @@ -42,6 +43,19 @@
#BUSKILL_VERSION = '0.1'
from buskill_version import BUSKILL_VERSION

################################################################################
# FUNCTIONS #
################################################################################

def start_logging(file_name):
logging.basicConfig(
filename = file_name,
filemode = 'a',
format = '%(asctime)s,%(msecs)d %(name)s %(levelname)s %(message)s',
datefmt = '%H:%M:%S',
level = logging.DEBUG
)

################################################################################
# MAIN BODY #
################################################################################
Expand All @@ -54,15 +68,18 @@

# TODO: disable logging by default; enable it with an argument
# TODO: be able to override the path to the log file with an env var or argument value; make these just the defaults
log_file_path = os.path.join( tempfile.gettempdir(), 'buskill.log' )

logging.basicConfig(
filename = log_file_path,
filemode = 'a',
format = '%(asctime)s,%(msecs)d %(name)s %(levelname)s %(message)s',
datefmt = '%H:%M:%S',
level = logging.DEBUG
)
try:
log_file_path = os.path.join( tempfile.gettempdir() , 'buskill.log' )
start_logging(log_file_path)
except PermissionError:
# adding a fallback log to avoid PermissionError
# This creates a new file that appends the timestamp to the log file
timestamp = datetime.now().strftime('%Y%m%d_%H%M%S')
log_file_path = os.path.join( tempfile.gettempdir() , f'buskill.{timestamp}.log')

start_logging(log_file_path)

msg = "==============================================================================="
print( msg ); logging.info( msg )
msg = "INFO: Writing to log file '" +str(log_file_path)+ "'"
Expand Down
1 change: 0 additions & 1 deletion src/packages/buskill/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,6 @@ def __init__(self):

# create a data dir in some safe place where we have write access
self.setupDataDir()

# path to buskill's config file
self.CONF_FILE = os.path.join( self.DATA_DIR, "config.ini" )

Expand Down
Loading