Skip to content

Commit

Permalink
Use XDG Base Directory specification log path
Browse files Browse the repository at this point in the history
Also discourage from using a hidden log file in $HOME for hacking
  • Loading branch information
kynikos authored and flacjacket committed Mar 4, 2016
1 parent fd8686e commit 66d704b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
@@ -1,5 +1,7 @@
qtile x.x.x, released xxxx-xx-xx:
* file path changes (XDG Base Directory specification)
- the default log file path changed from ~/.qtile.log to
~/.local/share/qtile/qtile.log
- the cache directory changed from ~/.cache to ~/.cache/qtile
* features
- wlan widget shows when you are disconnected and uses a configurable
Expand Down
7 changes: 4 additions & 3 deletions CONTRIBUTING.md
Expand Up @@ -19,9 +19,10 @@ has two qualities:
Do not combine multiple problems even they seem to be similar. Write
different reports for each problem.

To give more information about your bug you can append logs from `~/.qtile.log`
or on occasionally events you can capture bugs with `xtrace` for this have a deeper
look on the documentation about [capturing an xtrace](http://qtile.readthedocs.org/en/latest/manual/hacking.html#capturing-an-xtrace)
To give more information about your bug you can append logs from
`~/.local/share/qtile/qtile.log` or on occasionally events you can capture bugs
with `xtrace` for this have a deeper look on the documentation about
[capturing an xtrace](http://qtile.readthedocs.org/en/latest/manual/hacking.html#capturing-an-xtrace)

Writing code
============
Expand Down
2 changes: 1 addition & 1 deletion docs/manual/hacking.rst
Expand Up @@ -89,7 +89,7 @@ Qtile's conversations with the X server. To capture one of these, create an

.. code-block:: bash
exec xtrace qtile >> ~/.qtile.log
exec xtrace qtile >> ~/qtile.log
This will put the xtrace output in Qtile's logfile as well. You can then
demonstrate the bug, and paste the contents of this file into the bug report.
Expand Down
11 changes: 10 additions & 1 deletion libqtile/log_utils.py
Expand Up @@ -66,7 +66,7 @@ def format(self, record):
return message + self.reset_seq


def init_log(log_level=WARNING, log_path='~/.%s.log', log_truncate=False,
def init_log(log_level=WARNING, log_path=True, log_truncate=False,
log_size=10000000, log_numbackups=1, log_color=True):
formatter = Formatter(
"%(asctime)s %(levelname)s %(name)s %(filename)s:%(funcName)s():L%(lineno)d %(message)s"
Expand All @@ -85,6 +85,15 @@ def init_log(log_level=WARNING, log_path='~/.%s.log', log_truncate=False,

# If we have a log path, we'll also setup a log file
if log_path:
if not isinstance(log_path, str):
data_directory = os.path.expandvars('$XDG_DATA_HOME')
if data_directory == '$XDG_DATA_HOME':
# if variable wasn't set
data_directory = os.path.expanduser("~/.local/share")
data_directory = os.path.join(data_directory, 'qtile')
if not os.path.exists(data_directory):
os.makedirs(data_directory)
log_path = os.path.join(data_directory, '%s.log')
try:
log_path %= 'qtile'
except TypeError: # Happens if log_path doesn't contain formatters.
Expand Down

0 comments on commit 66d704b

Please sign in to comment.