[chronojump] Automatic logs again
- From: Xavier de Blas <xaviblas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump] Automatic logs again
- Date: Mon, 22 Dec 2014 11:57:29 +0000 (UTC)
commit a14535987cd577fd6d0154bb9604ac979ee860af
Author: Xavier de Blas <xaviblas gmail com>
Date: Mon Dec 22 12:57:13 2014 +0100
Automatic logs again
src/chronojump.cs | 24 +++++++------
src/gui/chronojump.cs | 4 ++-
src/gui/preferences.cs | 2 +-
src/log.cs | 84 ++++++++++++++++++++++++++++++++++++-----------
src/util.cs | 3 --
src/utilAll.cs | 12 +++++++
6 files changed, 93 insertions(+), 36 deletions(-)
---
diff --git a/src/chronojump.cs b/src/chronojump.cs
index c139a8f..6df47e0 100644
--- a/src/chronojump.cs
+++ b/src/chronojump.cs
@@ -73,6 +73,9 @@ public class ChronoJump
System.Console.SetError(sw);
sw.AutoFlush = true;
*/
+
+ //1.4.10
+ Log.Start();
var envPath = Environment.GetEnvironmentVariable ("PATH");
@@ -504,17 +507,16 @@ Console.WriteLine("--6--");
startChronojump();
}
- private void on_message_boot_accepted_quit (object o, EventArgs args) {
- try {
- File.Delete(runningFileName);
- } catch {
- //done because if database dir is moved in a chronojump conversion (eg from before
installer to installjammer) maybe it will not find this runningFileName
- }
- System.Console.Out.Close();
- //Log.End();
- //Log.Delete();
- Application.Quit();
- }
+ private void on_message_boot_accepted_quit (object o, EventArgs args) {
+ try {
+ File.Delete(runningFileName);
+ } catch {
+ //done because if database dir is moved in a chronojump conversion (eg from before
installer to installjammer) maybe it will not find this runningFileName
+ }
+ Log.End();
+ //Log.Delete();
+ Application.Quit();
+ }
private void startChronojump() {
diff --git a/src/gui/chronojump.cs b/src/gui/chronojump.cs
index 48df4c5..a608557 100644
--- a/src/gui/chronojump.cs
+++ b/src/gui/chronojump.cs
@@ -2366,7 +2366,9 @@ public partial class ChronoJumpWindow
Util.GetDatabaseDir() + Path.DirectorySeparatorChar + "chronojump.db");
Log.WriteLine("Bye2!");
- System.Console.Out.Close();
+
+ Log.End();
+
Log.WriteLine("Bye3!");
Application.Quit();
Log.WriteLine("Bye4!");
diff --git a/src/gui/preferences.cs b/src/gui/preferences.cs
index 193db13..43e51c0 100644
--- a/src/gui/preferences.cs
+++ b/src/gui/preferences.cs
@@ -379,7 +379,7 @@ public class PreferencesWindow {
void on_button_logs_folder_open_clicked (object o, EventArgs args)
{
- string dir = Util.GetLogsDir();
+ string dir = UtilAll.GetLogsDir();
Log.WriteLine(dir);
if( ! new System.IO.DirectoryInfo(dir).Exists) {
diff --git a/src/log.cs b/src/log.cs
index cdce4e2..87b5382 100644
--- a/src/log.cs
+++ b/src/log.cs
@@ -26,12 +26,17 @@ public class Log
/*
* writes to screen and to log
* timeLog ensures a different log for every chronojump launch
- * log is deleted if all ends ok
+ * log is deleted if all ends ok.
*/
//private static TextWriter writer; //writer is not used now, all is thone in the Main (on
chronojump.cs).we only need to print to console now (0.7.5)
//private static string timeLog = "";
- private static bool useConsole = true; //for the new method on chronojump.cs for redirecting output
and error to same file also on windows (0.7.5)
+ //private static bool useConsole = true; //for the new method on chronojump.cs for redirecting output
and error to same file also on windows (0.7.5)
+
+ //1.4.10 have log again by default to all windows users
+ //only two logs: current execution log and previous execution log
+ private static TextWriter writer;
+ private static bool useConsole;
/*
private static bool initializeTime(string [] args) {
@@ -107,35 +112,74 @@ public class Log
}
*/
- public static void Write(string text) {
- if(useConsole)
- Console.Write(text);
- /*
+
+ //on Windows since 1.4.10
+ public static void Start()
+ {
+ //first define console will be used.
+ //if writer is created ok, then console will NOT be used
+ useConsole = true;
+
+ //create dir if not exists
+ string dir = UtilAll.GetLogsDir();
+ if( ! Directory.Exists(dir)) {
+ try {
+ Directory.CreateDirectory (dir);
+ } catch {
+ return;
+ }
+ }
+
+ string filename = UtilAll.GetLogFileCurrent();
+ string filenameOld = UtilAll.GetLogFileOld();
+
+ //if exists, copy to old
+ if(File.Exists(filename)) {
+ try {
+ File.Copy(filename, filenameOld, true); //can be overwritten
+ } catch {}
+ }
+
try {
- writer.Write(text);
- writer.Flush();
+ writer = File.CreateText(filename);
+ useConsole = false;
} catch {}
- */
+ }
+
+ public static void Write(string text)
+ {
+ if(useConsole)
+ Console.Write(text);
+ else {
+ try {
+ writer.Write(text);
+ writer.Flush();
+ } catch {}
+ }
}
- public static void WriteLine(string text) {
+ public static void WriteLine(string text)
+ {
if(useConsole)
Console.WriteLine(text);
- /*
- try {
+ else {
+ try {
writer.WriteLine(text);
writer.Flush();
- } catch {}
- */
+ } catch {}
+ }
}
- /*
- public static void End() {
- try {
- ((IDisposable)writer).Dispose();
- } catch {}
+ public static void End()
+ {
+ if(useConsole)
+ System.Console.Out.Close();
+ else {
+ try {
+ ((IDisposable)writer).Dispose();
+ } catch {}
+ }
}
- */
//if exit normally, then delete file
/*
diff --git a/src/util.cs b/src/util.cs
index 9c0eda0..aea1088 100644
--- a/src/util.cs
+++ b/src/util.cs
@@ -767,9 +767,6 @@ public class Util
/********** end of database paths ************/
- public static string GetLogsDir() {
- return Path.Combine(Path.GetTempPath(), "Chronojump-logs");
- }
/********** start of multimedia paths ************/
diff --git a/src/utilAll.cs b/src/utilAll.cs
index c404ca6..798da1f 100644
--- a/src/utilAll.cs
+++ b/src/utilAll.cs
@@ -106,4 +106,16 @@ public class UtilAll
return str;
}
+ // ----------- logs -----------------------
+
+ public static string GetLogsDir() {
+ return Path.Combine(Path.GetTempPath(), "Chronojump-logs");
+ }
+ public static string GetLogFileCurrent() {
+ return Path.Combine(GetLogsDir() + Path.DirectorySeparatorChar + "log_chronojump.txt");
+ }
+ public static string GetLogFileOld() {
+ return Path.Combine(GetLogsDir() + Path.DirectorySeparatorChar + "log_chronojump_old.txt");
+ }
+
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]