Added --debug log level and updated README.md

This commit is contained in:
Robert Foster 2018-07-07 10:55:35 +09:30
parent fbf572a3d2
commit d5a6f8f770
6 changed files with 27 additions and 9 deletions

View file

@ -103,6 +103,11 @@ When running a sync it may be desirable to see additional information as to the
onedrive --synchronize --verbose
```
Debug logging can be enabled to provide even more information using the following command:
```
onedrive --synchronise --verbose --debug
```
### Client Activity Log
When running onedrive all actions are logged to `/var/log/onedrive/`

View file

@ -16,6 +16,9 @@ static this() {
// enable verbose logging
bool verbose;
// enable debug logging
bool debugging;
void init()
{
if (!exists(logFilePath)){
@ -55,6 +58,15 @@ void vlog(T...)(T args)
}
}
void dlog(T...)(T args)
{
if (debugging) {
writeln("[DEBUG] ", args);
// Write to log file
logfileWriteLine("[DEBUG] ", args);
}
}
void error(T...)(T args)
{
stderr.writeln(args);

View file

@ -27,8 +27,6 @@ int main(string[] args)
bool resync;
// remove the current user and sync state
bool logout;
// enable verbose logging
bool verbose;
// print the access token
bool printAccessToken;
// print the version and exit
@ -82,6 +80,7 @@ int main(string[] args)
"synchronize", "Perform a synchronization", &synchronize,
"upload-only", "Only upload to OneDrive, do not sync changes from OneDrive locally", &uploadOnly,
"verbose|v", "Print more details, useful for debugging", &log.verbose,
"debug", "Print even more details, useful for debugging", &log.debugging,
"version", "Print the version and exit", &printVersion
);
if (opt.helpWanted) {
@ -280,7 +279,7 @@ int main(string[] args)
log.log(e.msg);
}
};
if (!downloadOnly) m.init(cfg, verbose);
if (!downloadOnly) m.init(cfg);
// monitor loop
immutable auto checkInterval = dur!"seconds"(45);
auto lastCheckTime = MonoTime.currTime();

View file

@ -21,7 +21,6 @@ class MonitorException: ErrnoException
final class Monitor
{
bool verbose;
// inotify file descriptor
private int fd;
// map every inotify watch descriptor to its directory
@ -44,9 +43,8 @@ final class Monitor
this.selectiveSync = selectiveSync;
}
void init(Config cfg, bool verbose)
void init(Config cfg)
{
this.verbose = verbose;
fd = inotify_init();
if (fd == -1) throw new MonitorException("inotify_init failed");

View file

@ -34,7 +34,7 @@ final class SelectiveSync
// Does the file match skip_file config entry?
// Returns true if the file matches a skip_file config entry
// Returns false if no match
log.vlog("isNameExcluded for name '", name, "': ", !name.matchFirst(mask).empty);
log.dlog("isNameExcluded for name '", name, "': ", !name.matchFirst(mask).empty);
return !name.matchFirst(mask).empty;
}
@ -42,8 +42,8 @@ final class SelectiveSync
// also incorporates skip_file config parameter for expanded regex path matching
bool isPathExcluded(string path)
{
log.vlog("isPathExcluded for path '", path, "': ", .isPathExcluded(path, paths));
log.vlog("Path Matched for path '", path, "': ", !path.matchFirst(mask).empty);
log.dlog("isPathExcluded for path '", path, "': ", .isPathExcluded(path, paths));
log.dlog("Path Matched for path '", path, "': ", !path.matchFirst(mask).empty);
return .isPathExcluded(path, paths) || !path.matchFirst(mask).empty;
}
}

View file

@ -12,6 +12,7 @@ import std.string;
import std.algorithm;
import std.uri;
import qxor;
static import log;
private string deviceName;
@ -112,6 +113,9 @@ Regex!char wild2regex(const(char)[] pattern)
}
}
str ~= "$";
log.dlog("Wild Card expression: ", pattern);
log.dlog("Regular Expression: ", str);
return regex(str, "i");
}