Write debug output to a log file. Closes #515

This commit is contained in:
Hylke Bons 2012-01-11 23:02:22 +00:00
parent 63497bbed3
commit 98746b26c7
2 changed files with 23 additions and 4 deletions

View file

@ -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);

View file

@ -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
);
}
}