diff --git a/lib/services/logger/logger.dart b/lib/services/logger/logger.dart index 6ba76ea19..e95eb2e2a 100644 --- a/lib/services/logger/logger.dart +++ b/lib/services/logger/logger.dart @@ -64,6 +64,11 @@ class AppLogger { if (kIsMacOS) { dir = join((await getLibraryDirectory()).path, "Logs"); } + + if (kIsLinux) { + dir = join(_getXdgStateHome(), "spotube"); + } + final file = File(join(dir, ".spotube_logs")); if (!await file.exists()) { await file.create(recursive: true); @@ -87,4 +92,18 @@ class AppLogger { ); } } + + static String _getXdgStateHome() { + // path_provider seems does not support XDG_STATE_HOME, + // which is the specification to store application logs on Linux. + // See https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html + // TODO: Use path_provider once it supports XDG_STATE_HOME + if (const bool.hasEnvironment("XDG_STATE_HOME")) { + String xdgStateHomeRaw = Platform.environment["XDG_STATE_HOME"] ?? ""; + if (xdgStateHomeRaw.isNotEmpty) { + return xdgStateHomeRaw; + } + } + return join(Platform.environment["HOME"] ?? "", ".local", "state"); + } }