Skip to content

Commit

Permalink
write logs to XDG_STATE_HOME
Browse files Browse the repository at this point in the history
  • Loading branch information
azuline committed Oct 16, 2023
1 parent f8d7cfc commit 37f13c1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,10 @@ remixer ::= ' remixed by ' name
name ::= string ';' name | string
```

## Metadata Management

TODO

## New Releases

TODO
Expand Down Expand Up @@ -221,11 +225,7 @@ TODO; example unit files to schedule Rosé with systemd.

## Logging

TODO

## Metadata Management

TODO
Logs are written to stdout and to `${XDG_STATE_HOME:-$HOME/.local/state}/rose/rose.log`.

# Architecture

Expand Down
14 changes: 14 additions & 0 deletions rose/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import logging
import os
import sys
from pathlib import Path

logger = logging.getLogger()
logger.setLevel(logging.INFO)

STATE_HOME = Path(os.environ.get("XDG_STATE_HOME", "~/.local/state")).expanduser() / "rose"
STATE_HOME.mkdir(parents=True, exist_ok=True)
LOGFILE = STATE_HOME / "rose.log"

# Add a logging handler for stdout unless we are testing. Pytest
# captures logging output on its own.
if "pytest" not in sys.modules: # pragma: no cover
Expand All @@ -14,3 +20,11 @@
stream_handler = logging.StreamHandler(sys.stdout)
stream_handler.setFormatter(stream_formatter)
logger.addHandler(stream_handler)

file_formatter = logging.Formatter(
"[%(asctime)s] [%(name)s:%(lineno)s] %(levelname)s: %(message)s",
datefmt="%H:%M:%S",
)
file_handler = logging.FileHandler(LOGFILE)
file_handler.setFormatter(file_formatter)
logger.addHandler(file_handler)

0 comments on commit 37f13c1

Please sign in to comment.