diff --git a/Duplicati/GUI/DuplicatiRunner.cs b/Duplicati/GUI/DuplicatiRunner.cs index 0fc7d60cd..2f52d6629 100644 --- a/Duplicati/GUI/DuplicatiRunner.cs +++ b/Duplicati/GUI/DuplicatiRunner.cs @@ -58,6 +58,10 @@ namespace Duplicati.GUI public void ExecuteTask(IDuplicityTask task) { Dictionary options = new Dictionary(); + + //Set the log level to be that of the GUI + options["log-level"] = Duplicati.Library.Logging.Log.LogLevel.ToString(); + string destination = task.GetConfiguration(options); string results = ""; diff --git a/Duplicati/GUI/Program.cs b/Duplicati/GUI/Program.cs index 688c48704..2cf277415 100644 --- a/Duplicati/GUI/Program.cs +++ b/Duplicati/GUI/Program.cs @@ -162,6 +162,27 @@ namespace Duplicati.GUI return; } +#if DEBUG + //Log various information in the logfile + if (!commandlineOptions.ContainsKey("log-file")) + { + commandlineOptions["log-file"] = System.IO.Path.Combine(Application.StartupPath, "Duplicati.debug.log"); + commandlineOptions["log-level"] = Duplicati.Library.Logging.LogMessageType.Profiling.ToString(); + } +#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); + + 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"]); + } + //Set the %DUPLICATI_HOME% env variable, if it is not already set if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable(DATAFOLDER_ENV_NAME))) { @@ -258,16 +279,6 @@ namespace Duplicati.GUI //This is non-fatal, just keep running with system default language } -#if DEBUG - //Log various information in the logfile - string logfile = System.IO.Path.Combine(Application.StartupPath, "Duplicati.debug.log"); - if (System.IO.File.Exists(logfile)) - System.IO.File.Delete(logfile); - - Duplicati.Library.Logging.Log.LogLevel = Duplicati.Library.Logging.LogMessageType.Profiling; - Duplicati.Library.Logging.Log.CurrentLog = new Duplicati.Library.Logging.StreamLog(logfile); -#endif - LiveControl = new LiveControls(new ApplicationSettings(DataConnection)); LiveControl.StateChanged += new EventHandler(LiveControl_StateChanged); LiveControl.ThreadPriorityChanged += new EventHandler(LiveControl_ThreadPriorityChanged); @@ -472,7 +483,9 @@ namespace Duplicati.GUI new Duplicati.Library.Interface.CommandLineArgument("pause", Duplicati.Library.Interface.CommandLineArgument.ArgumentType.String, Strings.Program.PauseCommandDescription, Strings.Program.PauseCommandDescription), new Duplicati.Library.Interface.CommandLineArgument("show-status", Duplicati.Library.Interface.CommandLineArgument.ArgumentType.Boolean, Strings.Program.ShowstausCommandDescription, Strings.Program.ShowstausCommandDescription), new Duplicati.Library.Interface.CommandLineArgument("unencrypted-database", Duplicati.Library.Interface.CommandLineArgument.ArgumentType.Boolean, Strings.Program.UnencrypteddatabaseCommandDescription, Strings.Program.UnencrypteddatabaseCommandDescription), - new Duplicati.Library.Interface.CommandLineArgument("portable-mode", Duplicati.Library.Interface.CommandLineArgument.ArgumentType.Boolean, Strings.Program.PortablemodeCommandDescription, Strings.Program.PortablemodeCommandDescription) + new Duplicati.Library.Interface.CommandLineArgument("portable-mode", Duplicati.Library.Interface.CommandLineArgument.ArgumentType.Boolean, Strings.Program.PortablemodeCommandDescription, Strings.Program.PortablemodeCommandDescription), + new Duplicati.Library.Interface.CommandLineArgument("log-file", Duplicati.Library.Interface.CommandLineArgument.ArgumentType.Path, Strings.Program.LogfileCommandDescription, Strings.Program.LogfileCommandDescription), + new Duplicati.Library.Interface.CommandLineArgument("log-level", Duplicati.Library.Interface.CommandLineArgument.ArgumentType.Enumeration, Strings.Program.LoglevelCommandDescription, Strings.Program.LoglevelCommandDescription, "Warning", null, Enum.GetNames(typeof(Duplicati.Library.Logging.LogMessageType))) }; } } diff --git a/Duplicati/GUI/Strings/Program.Designer.cs b/Duplicati/GUI/Strings/Program.Designer.cs index 9f6c3664f..6bbbe5e51 100644 --- a/Duplicati/GUI/Strings/Program.Designer.cs +++ b/Duplicati/GUI/Strings/Program.Designer.cs @@ -126,6 +126,24 @@ namespace Duplicati.GUI.Strings { } } + /// + /// Looks up a localized string similar to Outputs log information to the file given. + /// + internal static string LogfileCommandDescription { + get { + return ResourceManager.GetString("LogfileCommandDescription", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Determines the amount of information written in the log file. + /// + internal static string LoglevelCommandDescription { + get { + return ResourceManager.GetString("LoglevelCommandDescription", resourceCulture); + } + } + /// /// Looks up a localized string similar to Pauses Duplicati, supply a time eg. 5m to limit pause to 5 minutes. /// diff --git a/Duplicati/GUI/Strings/Program.resx b/Duplicati/GUI/Strings/Program.resx index d76834960..c8aea7168 100644 --- a/Duplicati/GUI/Strings/Program.resx +++ b/Duplicati/GUI/Strings/Program.resx @@ -144,6 +144,12 @@ Error message: {0} Failed to set the user interface language: {0} An error message displayed if the language cannot be selected + + Outputs log information to the file given + + + Determines the amount of information written in the log file + Pauses Duplicati, supply a time eg. 5m to limit pause to 5 minutes diff --git a/Duplicati/Library/Main/Interface.cs b/Duplicati/Library/Main/Interface.cs index c97aea560..5e162d22c 100644 --- a/Duplicati/Library/Main/Interface.cs +++ b/Duplicati/Library/Main/Interface.cs @@ -1260,6 +1260,11 @@ namespace Duplicati.Library.Main { m_options.MainAction = stats.OperationMode; + Library.Logging.Log.LogLevel = m_options.Loglevel; + + if (!string.IsNullOrEmpty(m_options.Logfile)) + Library.Logging.Log.CurrentLog = new Library.Logging.StreamLog(m_options.Logfile); + if (stats != null) stats.VerboseErrors = m_options.DebugOutput; diff --git a/Duplicati/Library/Main/Options.cs b/Duplicati/Library/Main/Options.cs index d421b939d..6914ad938 100644 --- a/Duplicati/Library/Main/Options.cs +++ b/Duplicati/Library/Main/Options.cs @@ -151,6 +151,9 @@ namespace Duplicati.Library.Main new CommandLineArgument("debug-output", CommandLineArgument.ArgumentType.Boolean, Strings.Options.DebugoutputShort, Strings.Options.DebugoutputLong, "false"), new CommandLineArgument("exclude-empty-folders", CommandLineArgument.ArgumentType.Boolean, Strings.Options.ExcludeemptyfoldersShort, Strings.Options.ExcludeemptyfoldersLong, "false"), + + new CommandLineArgument("log-file", Duplicati.Library.Interface.CommandLineArgument.ArgumentType.Path, Strings.Options.LogfileShort, Strings.Options.LogfileShort), + new CommandLineArgument("log-level", Duplicati.Library.Interface.CommandLineArgument.ArgumentType.Enumeration, Strings.Options.LoglevelShort, Strings.Options.LoglevelLong, "Warning", null, Enum.GetNames(typeof(Duplicati.Library.Logging.LogMessageType))), }); } } @@ -730,6 +733,39 @@ namespace Duplicati.Library.Main } } + /// + /// Gets the logfile filename + /// + public string Logfile + { + get + { + string value; + if (!m_options.TryGetValue("log-file", out value)) + value = null; + return value; + } + } + + /// + /// Gets the logfile filename + /// + public Duplicati.Library.Logging.LogMessageType Loglevel + { + get + { + string value; + if (!m_options.TryGetValue("log-level", out value)) + value = null; + + foreach (string s in Enum.GetNames(typeof(Duplicati.Library.Logging.LogMessageType))) + if (s.Equals(value, StringComparison.InvariantCultureIgnoreCase)) + return (Duplicati.Library.Logging.LogMessageType)Enum.Parse(typeof(Duplicati.Library.Logging.LogMessageType), s); + + return Duplicati.Library.Logging.LogMessageType.Warning; + } + } + /// /// Gets a list of modules, the key indicates if they are loaded /// diff --git a/Duplicati/Library/Main/Strings/Options.Designer.cs b/Duplicati/Library/Main/Strings/Options.Designer.cs index 356cbfb82..f418ee0eb 100644 --- a/Duplicati/Library/Main/Strings/Options.Designer.cs +++ b/Duplicati/Library/Main/Strings/Options.Designer.cs @@ -537,6 +537,42 @@ namespace Duplicati.Library.Main.Strings { } } + /// + /// Looks up a localized string similar to Specifies the name of a while into which internal log information is written. + /// + internal static string LogfileLong { + get { + return ResourceManager.GetString("LogfileLong", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Log internal information. + /// + internal static string LogfileShort { + get { + return ResourceManager.GetString("LogfileShort", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Specifies the amount of log information to write into the file specified by --log-file. + /// + internal static string LoglevelLong { + get { + return ResourceManager.GetString("LoglevelLong", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Log information level. + /// + internal static string LoglevelShort { + get { + return ResourceManager.GetString("LoglevelShort", resourceCulture); + } + } + /// /// Looks up a localized string similar to By setting this value you can limit how much bandwidth Duplicati consumes for downloads. Setting this limit can make the backups take longer, but will make Duplicati less intrusive.. /// diff --git a/Duplicati/Library/Main/Strings/Options.resx b/Duplicati/Library/Main/Strings/Options.resx index 2324d19e9..cbdc69285 100644 --- a/Duplicati/Library/Main/Strings/Options.resx +++ b/Duplicati/Library/Main/Strings/Options.resx @@ -399,4 +399,16 @@ Duplicati no longer uses a time separator for the filenames so this option is useless + + Specifies the name of a while into which internal log information is written + + + Log internal information + + + Specifies the amount of log information to write into the file specified by --log-file + + + Log information level + \ No newline at end of file