Skip to content

Commit

Permalink
Change default logfile path for cli
Browse files Browse the repository at this point in the history
In b3e8ff1 default logfile was changed
to the same directory where the cli executable is. This is a wrong
approach as dexbot can be installed in multiple ways. System-wide
install will put the binary into /usr/bin/dexbot-cli. Applicateion must
not try to log into /usr/bin/.

This change makes logging consistent with GUI, which stores the log into
user data directory, like ~/.local/share/dexbot/dexbot.log

Closes: Codaone#490, Codaone#540
  • Loading branch information
bitphage committed Apr 25, 2019
1 parent dc1b79d commit f3ad499
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions dexbot/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@

import click
from ruamel import yaml
from appdirs import user_data_dir

from bitshares import BitShares
from bitshares.instance import set_shared_bitshares_instance
from bitshares.exceptions import WrongMasterPasswordException

from dexbot import VERSION, APP_NAME, AUTHOR
from dexbot.config import Config

log = logging.getLogger(__name__)
Expand Down Expand Up @@ -47,8 +50,12 @@ def new_func(ctx, *args, **kwargs):
# Logging to a file
filename = ctx.obj.get('logfile')
if not filename:
# By default, log to a file located where the script is
filename = os.path.join(os.path.dirname(sys.argv[0]), 'dexbot.log')
# By default, log to a user data dir
data_dir = user_data_dir(APP_NAME, AUTHOR)
filename = os.path.join(data_dir, 'dexbot.log')
# Print logfile using main logger
logging.getLogger("dexbot").info('Dexbot version {}, logfile: {}'.format(VERSION, filename))

fh = logging.FileHandler(filename)
fh.setFormatter(formatter2)
logger.addHandler(fh)
Expand Down

0 comments on commit f3ad499

Please sign in to comment.