Update application file logging error handling (#1776)

* Update application logging configuration instructions
* Update error notification handling when unable to write to required logfile due to access permission issues
This commit is contained in:
abraunegg 2022-01-02 10:22:23 +11:00 committed by GitHub
parent 9e87e870ab
commit 61c8652449
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 4 deletions

View file

@ -223,13 +223,26 @@ The requested client activity log will instead be located in the users home dire
On many systems this can be achieved by
```text
mkdir /var/log/onedrive
chown root.users /var/log/onedrive
chmod 0775 /var/log/onedrive
sudo mkdir /var/log/onedrive
sudo chown root.users /var/log/onedrive
sudo chmod 0775 /var/log/onedrive
```
All log files will be in the format of `%username%.onedrive.log`, where `%username%` represents the user who ran the client.
Additionally, you need to ensure that your user account is part of the 'users' group:
```
cat /etc/group | grep users
```
If your user is not part of this group, then you need to add your user to this group:
```
sudo usermod -a -G users <your-user-name>
```
You then need to 'logout' of all sessions / SSH sessions to login again to have the new group access applied.
**Note:**
To use a different log directory rather than the default above, add the following as a configuration option to `~/.config/onedrive/config`:
```text

View file

@ -13,6 +13,7 @@ version(Notifications) {
// enable verbose logging
long verbose;
bool writeLogFile = false;
bool logFileWriteFailFlag = false;
private bool doNotifications;
@ -35,7 +36,7 @@ void init(string logDir)
// we got an error ..
writeln("\nUnable to access ", logFilePath);
writeln("Please manually create '",logFilePath, "' and set appropriate permissions to allow write access");
writeln("The requested client activity log will instead be located in the users home directory\n");
writeln("The requested client activity log will instead be located in your users home directory\n");
}
}
}
@ -169,6 +170,17 @@ private void logfileWriteLine(T...)(T args)
// We cannot open the log file in logFilePath location for writing
// The user is not part of the standard 'users' group (GID 100)
// Change logfile to ~/onedrive.log putting the log file in the users home directory
if (!logFileWriteFailFlag) {
// write out error message that we cant log to the requested file
writeln("\nUnable to write activity log to ", logFileName);
writeln("Please set appropriate permissions to allow write access to the logging directory for your user account");
writeln("The requested client activity log will instead be located in your users home directory\n");
// set the flag so we dont keep printing this error message
logFileWriteFailFlag = true;
}
string homePath = environment.get("HOME");
string logFileNameAlternate = homePath ~ "/onedrive.log";
logFile = File(logFileNameAlternate, "a");