2006-01-19 00:34:21 +01:00
|
|
|
/***********************************************************************
|
|
|
|
*
|
|
|
|
* Copyright (C) 2005-2006 Novell, Inc.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; version 2.1
|
|
|
|
* of the License.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free
|
|
|
|
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*
|
|
|
|
* To contact Novell about this file by physical or electronic mail,
|
|
|
|
* you may find current contact information at www.novell.com.
|
|
|
|
*
|
|
|
|
***********************************************************************/
|
2005-10-11 21:51:00 +02:00
|
|
|
|
|
|
|
|
|
|
|
namespace Novell.CASA.GUI
|
|
|
|
{
|
|
|
|
using System;
|
|
|
|
using System.Text;
|
|
|
|
using System.Diagnostics;
|
|
|
|
using System.IO;
|
|
|
|
using System.Threading;
|
|
|
|
|
2005-10-31 21:24:36 +01:00
|
|
|
using Gtk;
|
|
|
|
|
2005-10-11 21:51:00 +02:00
|
|
|
class Logger
|
|
|
|
{
|
|
|
|
private static string debugLog = null;
|
|
|
|
private static Stream debugStream= null;
|
|
|
|
private static Mutex dbgmutex = new Mutex();
|
2005-10-31 21:24:36 +01:00
|
|
|
|
|
|
|
static Gtk.TreeStore tsLog;
|
2005-10-11 21:51:00 +02:00
|
|
|
|
|
|
|
static Logger()
|
|
|
|
{
|
|
|
|
#if DEBUG
|
|
|
|
debugLog = GetHomeDir() + "/.CASAManager.logs";
|
|
|
|
|
|
|
|
// Set up for Debug
|
|
|
|
|
|
|
|
if( File.Exists( debugLog ) )
|
|
|
|
{
|
|
|
|
File.Delete( debugLog );
|
|
|
|
}
|
|
|
|
|
|
|
|
debugStream = File.Create(debugLog);
|
|
|
|
|
|
|
|
Debug.Listeners.Add(new TextWriterTraceListener(debugStream));
|
|
|
|
Debug.AutoFlush = true;
|
|
|
|
Debug.Indent();
|
|
|
|
Debug.WriteLine("Debug Log created");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2005-10-31 21:24:36 +01:00
|
|
|
|
|
|
|
public static void ActivateLogWindow(Gtk.TreeView tvLog)
|
|
|
|
{
|
|
|
|
tsLog = new TreeStore(typeof(string));
|
|
|
|
tvLog.Model = tsLog;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void StopLogWindow()
|
|
|
|
{
|
|
|
|
tsLog = null;
|
|
|
|
}
|
2005-10-11 21:51:00 +02:00
|
|
|
|
|
|
|
public static void logbreak()
|
|
|
|
{
|
|
|
|
dbgmutex.WaitOne();
|
|
|
|
Debug.WriteLine(" ") ;
|
|
|
|
Debug.WriteLine("----------------------------------------------------") ;
|
|
|
|
Debug.WriteLine(" ") ;
|
2005-10-31 21:24:36 +01:00
|
|
|
dbgmutex.ReleaseMutex();
|
2005-10-11 21:51:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// The log format is Time stamp :Component name: Error description
|
|
|
|
public static void DbgLog(string message)
|
2005-10-31 21:24:36 +01:00
|
|
|
{
|
|
|
|
if (tsLog != null)
|
|
|
|
{
|
|
|
|
tsLog.AppendValues(DateTime.Now.ToLongTimeString()
|
|
|
|
+ ":"
|
|
|
|
+ message);
|
|
|
|
}
|
|
|
|
|
2005-10-11 21:51:00 +02:00
|
|
|
#if DEBUG
|
|
|
|
dbgmutex.WaitOne();
|
|
|
|
|
|
|
|
Debug.Write(DateTime.Now.ToLongTimeString());
|
|
|
|
Debug.Write(" " + DateTime.Now.ToLongDateString());
|
|
|
|
Debug.Write(":");
|
|
|
|
Debug.WriteLine(message);
|
|
|
|
|
|
|
|
dbgmutex.ReleaseMutex();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void ExpLog(string message)
|
|
|
|
{
|
2005-10-31 21:24:36 +01:00
|
|
|
if (tsLog != null)
|
|
|
|
{
|
|
|
|
tsLog.AppendValues(DateTime.Now.ToLongTimeString()
|
|
|
|
+ ": Exception encountered - ");
|
|
|
|
tsLog.AppendValues(message);
|
|
|
|
|
2005-11-03 21:25:34 +01:00
|
|
|
StackTrace st1 = new StackTrace();
|
|
|
|
tsLog.AppendValues(st1.ToString());
|
2005-10-31 21:24:36 +01:00
|
|
|
}
|
|
|
|
|
2005-10-11 21:51:00 +02:00
|
|
|
#if DEBUG
|
|
|
|
dbgmutex.WaitOne();
|
|
|
|
|
|
|
|
Debug.Write(DateTime.Now.ToLongTimeString());
|
|
|
|
Debug.Write(" " + DateTime.Now.ToLongDateString());
|
|
|
|
Debug.Write(": Exception encountered - ");
|
|
|
|
Debug.WriteLine(message);
|
|
|
|
Debug.WriteLine(" ") ;
|
|
|
|
StackTrace st = new StackTrace();
|
|
|
|
Debug.WriteLine(st.ToString());
|
|
|
|
|
|
|
|
dbgmutex.ReleaseMutex();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
static string GetHomeDir()
|
|
|
|
{
|
|
|
|
int platform = (int)Environment.OSVersion.Platform;
|
|
|
|
|
|
|
|
if ( (platform == 128) || ( platform == 4) )
|
|
|
|
{
|
|
|
|
return System.Environment.GetEnvironmentVariable("HOME");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return (System.Environment.GetEnvironmentVariable("HOMEDRIVE")) +
|
|
|
|
(System.Environment.GetEnvironmentVariable("HOMEPATH"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|