diff --git a/Duplicati/Server/Duplicati.Server.csproj b/Duplicati/Server/Duplicati.Server.csproj
index bde1714b5..d898c0230 100644
--- a/Duplicati/Server/Duplicati.Server.csproj
+++ b/Duplicati/Server/Duplicati.Server.csproj
@@ -116,6 +116,7 @@
+
diff --git a/Duplicati/Server/Program.cs b/Duplicati/Server/Program.cs
index 450e57210..3eaca2e83 100644
--- a/Duplicati/Server/Program.cs
+++ b/Duplicati/Server/Program.cs
@@ -108,6 +108,11 @@ namespace Duplicati.Server
///
public static long LastDataUpdateID = 0;
+ ///
+ /// The log redirect handler
+ ///
+ public static LogWriteHandler LogHandler = new LogWriteHandler();
+
public static int ServerPort
{
get
@@ -218,11 +223,6 @@ namespace Duplicati.Server
}
#endif
- if (commandlineOptions.ContainsKey("log-level"))
- foreach(string s in Enum.GetNames(typeof(Duplicati.Library.Logging.LogMessageType)))
- if (s.Equals(commandlineOptions["log-level"].Trim(), StringComparison.InvariantCultureIgnoreCase))
- Duplicati.Library.Logging.Log.LogLevel = (Duplicati.Library.Logging.LogMessageType)Enum.Parse(typeof(Duplicati.Library.Logging.LogMessageType), s);
-
//Set the %DUPLICATI_HOME% env variable, if it is not already set
if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable(DATAFOLDER_ENV_NAME)))
{
@@ -278,11 +278,20 @@ namespace Duplicati.Server
}
}
+ // Setup the log redirect
+ Duplicati.Library.Logging.Log.CurrentLog = Program.LogHandler;
+
if (commandlineOptions.ContainsKey("log-file"))
{
if (System.IO.File.Exists(commandlineOptions["log-file"]))
System.IO.File.Delete(commandlineOptions["log-file"]);
- Duplicati.Library.Logging.Log.CurrentLog = new Duplicati.Library.Logging.StreamLog(commandlineOptions["log-file"]);
+
+ var loglevel = Duplicati.Library.Logging.LogMessageType.Error;
+
+ if (commandlineOptions.ContainsKey("log-level"))
+ Enum.TryParse(commandlineOptions["log-level"], true, out loglevel);
+
+ Program.LogHandler.SetServerFile(commandlineOptions["log-file"], loglevel);
}
Version sqliteVersion = new Version((string)Duplicati.Library.SQLiteHelper.SQLiteLoader.SQLiteConnectionType.GetProperty("SQLiteVersion").GetValue(null, null));
@@ -418,11 +427,9 @@ namespace Duplicati.Server
try { PingPongThread.Abort(); }
catch { }
-#if DEBUG
- //Flush the file
- using (Duplicati.Library.Logging.Log.CurrentLog as Duplicati.Library.Logging.StreamLog)
- Duplicati.Library.Logging.Log.CurrentLog = null;
-#endif
+ if (LogHandler != null)
+ LogHandler.Dispose();
+
}
}
diff --git a/Duplicati/Server/Runner.cs b/Duplicati/Server/Runner.cs
index b2029ebd9..29b712dba 100644
--- a/Duplicati/Server/Runner.cs
+++ b/Duplicati/Server/Runner.cs
@@ -286,6 +286,21 @@ namespace Duplicati.Server
if (data.ExtraOptions != null)
foreach(var k in data.ExtraOptions)
options[k.Key] = k.Value;
+
+ if (options.ContainsKey("log-file"))
+ {
+ var file = options["log-file"];
+
+ string o;
+ Library.Logging.LogMessageType level;
+ options.TryGetValue("log-level", out o);
+ Enum.TryParse(o, true, out level);
+
+ options.Remove("log-file");
+ options.Remove("log-level");
+
+ Program.LogHandler.SetOperationFile(file, level);
+ }
using(var controller = new Duplicati.Library.Main.Controller(backup.TargetURL, options, sink))
{
@@ -365,6 +380,7 @@ namespace Duplicati.Server
finally
{
((RunnerData)data).Controller = null;
+ Program.LogHandler.RemoveOperationFile();
}
}
diff --git a/Duplicati/Server/WebServer/ControlHandler.cs b/Duplicati/Server/WebServer/ControlHandler.cs
index 792a16c2f..e44cc315c 100644
--- a/Duplicati/Server/WebServer/ControlHandler.cs
+++ b/Duplicati/Server/WebServer/ControlHandler.cs
@@ -60,6 +60,7 @@ namespace Duplicati.Server.WebServer
SUPPORTED_METHODS.Add("get-license-data", GetLicenseData);
SUPPORTED_METHODS.Add("get-changelog", GetChangelog);
SUPPORTED_METHODS.Add("locate-uri-db", LocateUriDb);
+ SUPPORTED_METHODS.Add("poll-log-messages", PollLogMessages);
}
public override bool Process (HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session)
@@ -349,7 +350,7 @@ namespace Duplicati.Server.WebServer
bw.OutputOK();
}
- catch (Duplicati.Library.Interface.FolderMissingException fex)
+ catch (Duplicati.Library.Interface.FolderMissingException)
{
ReportError(response, bw, "missing-folder");
}
@@ -403,7 +404,8 @@ namespace Duplicati.Server.WebServer
GenericModules = Serializable.ServerSettings.GenericModules,
WebModules = Serializable.ServerSettings.WebModules,
ConnectionModules = Serializable.ServerSettings.ConnectionModules,
- UsingAlternateUpdateURLs = Duplicati.Library.AutoUpdater.AutoUpdateSettings.UsesAlternateURLs
+ UsingAlternateUpdateURLs = Duplicati.Library.AutoUpdater.AutoUpdateSettings.UsesAlternateURLs,
+ LogLevels = Enum.GetNames(typeof(Duplicati.Library.Logging.LogMessageType))
});
}
@@ -649,6 +651,21 @@ namespace Duplicati.Server.WebServer
});
}
+ private void PollLogMessages(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session, BodyWriter bw)
+ {
+ HttpServer.HttpInput input = request.Method.ToUpper() == "POST" ? request.Form : request.QueryString;
+ var level_str = input["level"].Value ?? "";
+ var id_str = input["id"].Value ?? "";
+
+ Library.Logging.LogMessageType level;
+ long id;
+
+ long.TryParse(id_str, out id);
+ Enum.TryParse(level_str, true, out level);
+
+ bw.OutputOK(Program.LogHandler.AfterID(id, level));
+ }
+
private void SendCommand(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session, BodyWriter bw)
{
HttpServer.HttpInput input = request.Method.ToUpper() == "POST" ? request.Form : request.QueryString;
diff --git a/Duplicati/Server/webroot/index.html b/Duplicati/Server/webroot/index.html
index 7ae0df540..ee248cd23 100644
--- a/Duplicati/Server/webroot/index.html
+++ b/Duplicati/Server/webroot/index.html
@@ -90,6 +90,15 @@
+
+