Skip to content

Commit

Permalink
feat: Use XDG_STATE_HOME for "log file" default
Browse files Browse the repository at this point in the history
- Change: Change default value of "log file" config option to `"$XDG_STATE_HOME/termvisage/log"`.
- Change: Update "log file" documentation.
- Change: Update sample default config file.

Refs: #2
  • Loading branch information
AnonymouX47 committed Apr 19, 2023
1 parent 50c936e commit ab971d6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion default_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"checkers": null,
"getters": 4,
"grid renderers": 1,
"log file": "~/.termvisage/termvisage.log",
"log file": "~/.local/state/termvisage/log",
"max notifications": 2,
"max pixels": 4194304,
"multi": true,
Expand Down
8 changes: 5 additions & 3 deletions docs/source/config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ These are top-level fields whose values control various settings of the viewer.
.. confval:: log file
:synopsis: The file to which logs are written.
:type: string
:valid: An absolute path to a writable file
:default: ``"~/.termvisage/termvisage.log"``
:valid: A writable/creatable file path
:default: ``"{$XDG_STATE_HOME}/termvisage/log"``

If the file:

Expand All @@ -116,9 +116,11 @@ These are top-level fields whose values control various settings of the viewer.
Supports tilde expansion i.e a leading ``~`` (tilde) character is expanded to the
current user's home directory.

The environment variable ``$XDG_STATE_HOME`` defaults to ``~/.local/state`` if undefined.

.. warning::
Relative paths are allowed but this will cause the log file to be written (or
created) relative to the **current working directory** every time the process
created) relative to the **current working directory** every time a session
is started.

.. note:: Overridden by :option:`-l`.
Expand Down
6 changes: 5 additions & 1 deletion src/termvisage/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,11 @@ def update_context_nav(
"must be a non-negative integer",
),
"log file": Option(
path.join("~", ".termvisage", "termvisage.log"),
path.join(
os.environ.get("XDG_STATE_HOME", path.join("~", ".local", "state")),
"termvisage",
"log",
),
lambda x: isinstance(x, str) and is_writable(x),
"must be a string containing a writable/creatable file path",
),
Expand Down

0 comments on commit ab971d6

Please sign in to comment.