"logfile" accepts environment variables

This commit is contained in:
Matthieu Coudron 2016-08-29 14:54:07 +02:00
parent 2eba2fd9ac
commit 33764e349e
2 changed files with 3 additions and 2 deletions

View File

@ -212,7 +212,7 @@ Setting a specific logfile
~~~~~~~~~~~~~~~~~~~~~~~~~~
When instantiating your ``Status`` object, the path to a log file can be
specified. If this is done, then log messages will be sent to that file and not
specified (it accepts environment variables). If this is done, then log messages will be sent to that file and not
to an ``.i3pystatus-<pid-of-thread>`` file in your home directory. This is
useful in that it helps keep your home directory from becoming cluttered with
files containing errors.
@ -221,7 +221,7 @@ files containing errors.
from i3pystatus import Status
status = Status(logfile='/home/username/var/i3pystatus.log')
status = Status(logfile='$HOME/var/i3pystatus.log')
Changing log format
~~~~~~~~~~~~~~~~~~~

View File

@ -70,6 +70,7 @@ class Status:
if logfile:
for handler in logger.handlers:
logger.removeHandler(handler)
logfile = os.path.expandvars(logfile)
handler = logging.FileHandler(logfile, delay=True)
logger.addHandler(handler)
logger.setLevel(logging.CRITICAL)