From 98746b26c7e4c2d50eeb2d0a836a29cfe8149aa7 Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Wed, 11 Jan 2012 23:02:22 +0000 Subject: [PATCH] Write debug output to a log file. Closes #515 --- SparkleLib/SparkleConfig.cs | 16 ++++++++++++++-- SparkleLib/SparkleHelpers.cs | 11 +++++++++-- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/SparkleLib/SparkleConfig.cs b/SparkleLib/SparkleConfig.cs index f9f57548..77749156 100755 --- a/SparkleLib/SparkleConfig.cs +++ b/SparkleLib/SparkleConfig.cs @@ -29,8 +29,11 @@ namespace SparkleLib { Environment.GetFolderPath (Environment.SpecialFolder.ApplicationData), "sparkleshare"); + public bool DebugMode = true; + public static SparkleConfig DefaultConfig = new SparkleConfig (ConfigPath, "config.xml"); public string FullPath; + public string LogFilePath; public string HomePath { get { @@ -38,7 +41,6 @@ namespace SparkleLib { } } - public string FoldersPath { get { if (GetConfigOption ("folders_path") != null) @@ -57,7 +59,17 @@ namespace SparkleLib { public SparkleConfig (string config_path, string config_file_name) { - FullPath = System.IO.Path.Combine (config_path, config_file_name); + FullPath = Path.Combine (config_path, config_file_name); + LogFilePath = Path.Combine (config_path, "debug.log"); + + if (File.Exists (LogFilePath)) { + try { + File.Delete (LogFilePath); + + } catch (Exception) { + // Don't delete the debug.log if 'tail' is reading it + } + } if (!Directory.Exists (config_path)) { Directory.CreateDirectory (config_path); diff --git a/SparkleLib/SparkleHelpers.cs b/SparkleLib/SparkleHelpers.cs index b2b1a459..eb6a662d 100755 --- a/SparkleLib/SparkleHelpers.cs +++ b/SparkleLib/SparkleHelpers.cs @@ -34,8 +34,15 @@ namespace SparkleLib { if (!message.StartsWith ("[")) message = " " + message; - // TODO: Write to a log - Console.WriteLine (timestamp + " " + "[" + type + "]" + message); + string line = timestamp + " " + "[" + type + "]" + message; + + if (SparkleConfig.DefaultConfig.DebugMode) + Console.WriteLine (line); + + File.AppendAllText ( + SparkleConfig.DefaultConfig.LogFilePath, + line + Environment.NewLine + ); } }