I'm exploring the RC API via librclone
and I wonder if there is a way to set log level and log file via RPC. My goal is to run sync/copy
in DryRun mode and parse the output to see if source and destination have any differences. I know there is the [check](https://rclone.org/commands/rclone_check/)
command but it don't look like it is available via rc.
Here is some code I have so far based on examples I found.
type RcloneSyncRequest struct {
SrcFs string `json:"srcFs"`
DstFs string `json:"dstFs"`
Group string `json:"_group"`
Async bool `json:"_async"`
Config string `json:"_config"`
}
type RcloneOptions struct {
Main string `json:"main"`
}
options := RcloneOptions{
Main: `{"LogLevel": "DEBUG"}`,
}
optionsJSON, err := json.Marshal(options)
if err != nil {
fmt.Println(err)
}
out, status := librclone.RPC("options/set", string(optionsJSON))
if status != 200 {
err := fmt.Errorf("AsyncCheck librclone.RPC error: Got status %d and output %q", status, out)
return err
}
syncRequest := RcloneSyncRequest{
SrcFs: srcPath,
DstFs: dstPath,
Async: true,
Config: `{"DryRun": true}`,
}
syncRequestJSON, err := json.Marshal(syncRequest)
if err != nil {
fmt.Println(err)
}
out, status = librclone.RPC("sync/copy", string(syncRequestJSON))
if status != 200 {
err := fmt.Errorf("AsyncCheck librclone.RPC error: Got status %d and output %q", status, out)
return err
}
However, when I run the above code I get following error:
2023/11/01 20:07:05 ERROR : rc: "options/set": error: unknown option block "main"
I saw some examples where logging was set in the following way:
rclone rc options/set --json '{"main": {"LogLevel": "DEBUG"}}'
My question is - is there a way to set log level (--log-level
) and log file (--log-file
) via librclone.RPC like it is possible via cli?
I went over this thread where core/log
was discussed. Did this ever get any traction?
Also, another issue I'm having is after executing sync/copy
command out
is empty. I did some search and looks like this is related to returnType
which should be set to "STREAM", "STREAM_ONLY_STDOUT", "STREAM_ONLY_STDERR".
Is there a way to set the returnType
via librclone.RPC?
Another idea I had is to use core/command
to run sync
/copy
/check
with returnType
set to STREAM but not sure if this is doable. I saw in this post @Ole created an HTTP request which has pretty much what I'm looking for. However, I don't know if the below HTTP snippet can be converted into a librclone.RPC call.
POST http://localhost:5572/core/command HTTP/1.1
content-type: application/json
{
"command": "sync",
"arg": [
"/home/pi/data",
"aws-remote:s3.rclonebucket.testing",
"--dry-run",
"--log-level=NOTICE",
"--use-json-log=false"
],
"returnType": "STREAM"
}
Thanks in advance!