codesite...@google.com
unread,Sep 11, 2008, 5:49:42 PM9/11/08Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to migratordo...@googlegroups.com
Author: geofflane
Date: Thu Sep 11 14:48:32 2008
New Revision: 120
Modified:
trunk/src/Migrator.Framework/ILogger.cs
trunk/src/Migrator.Framework/Loggers/IAttachableLogger.cs
trunk/src/Migrator.Framework/Loggers/ILogWriter.cs
trunk/src/Migrator.Framework/Loggers/Logger.cs
trunk/src/Migrator.Framework/Loggers/SqlScriptFileLogger.cs
trunk/src/Migrator.MSBuild/Logger/TaskLogger.cs
trunk/src/Migrator.NAnt/Loggers/TaskLogger.cs
Log:
Issue #51
Improve the logging of Error messages a bit. Print the stack trace
regardless of the 'trace' setting since these are exceptional events and
not really debugging events.
Modified: trunk/src/Migrator.Framework/ILogger.cs
==============================================================================
--- trunk/src/Migrator.Framework/ILogger.cs (original)
+++ trunk/src/Migrator.Framework/ILogger.cs Thu Sep 11 14:48:32 2008
@@ -5,7 +5,6 @@
{
public interface ILogger
{
-
/// <summary>
/// Log that we have started a migration
/// </summary>
@@ -55,11 +54,18 @@
/// <summary>
/// Log that we had an exception on a migration
/// </summary>
- /// <param name="version">La version de la migration qui a produire
l'exception.</param>
- /// <param name="migrationName">Le nom de la migration qui a produire
l'exception.</param>
- /// <param name="ex">L'exception lanc�e</param>
+ /// <param name="version">The version of the migration that caused the
exception.</param>
+ /// <param name="migrationName">The name of the migration that caused
the exception.</param>
+ /// <param name="ex">The exception itself</param>
void Exception(long version, string migrationName, Exception ex);
+ /// <summary>
+ /// Log that we had an exception on a migration
+ /// </summary>
+ /// <param name="message">An informative message to show to the
user.</param>
+ /// <param name="ex">The exception itself</param>
+ void Exception(string message, Exception ex);
+
/// <summary>
/// Log that we have finished a migration
/// </summary>
@@ -70,22 +76,22 @@
/// <summary>
/// Log a message
/// </summary>
- /// <param name="format">Le format ("{0}, blbla {1}") ou la cha�ne �
afficher.</param>
- /// <param name="args">Les param�tres dans le cas d'un format au premier
param�tre.</param>
+ /// <param name="format">The format string ("{0}, blabla {1}").</param>
+ /// <param name="args">Parameters to apply to the format string.</param>
void Log(string format, params object[] args);
/// <summary>
/// Log a Warning
/// </summary>
- /// <param name="format">Le format ("{0}, blbla {1}") ou la cha�ne �
afficher.</param>
- /// <param name="args">Les param�tres dans le cas d'un format au premier
param�tre.</param>
+ /// <param name="format">The format string ("{0}, blabla
{1}").</param>
+ /// <param name="args">Parameters to apply to the format
string.</param>
void Warn(string format, params object[] args);
/// <summary>
/// Log a Trace Message
/// </summary>
- /// <param name="format">Le format ("{0}, blbla {1}") ou la cha�ne �
afficher.</param>
- /// <param name="args">Les param�tres dans le cas d'un format au premier
param�tre.</param>
+ /// <param name="format">The format string ("{0}, blabla
{1}").</param>
+ /// <param name="args">Parameters to apply to the format
string.</param>
void Trace(string format, params object[] args);
}
}
Modified: trunk/src/Migrator.Framework/Loggers/IAttachableLogger.cs
==============================================================================
--- trunk/src/Migrator.Framework/Loggers/IAttachableLogger.cs (original)
+++ trunk/src/Migrator.Framework/Loggers/IAttachableLogger.cs Thu Sep 11
14:48:32 2008
@@ -9,8 +9,6 @@
//under the License.
#endregion
-using Migrator.Framework;
-
namespace Migrator.Framework.Loggers
{
/// <summary>
Modified: trunk/src/Migrator.Framework/Loggers/ILogWriter.cs
==============================================================================
--- trunk/src/Migrator.Framework/Loggers/ILogWriter.cs (original)
+++ trunk/src/Migrator.Framework/Loggers/ILogWriter.cs Thu Sep 11 14:48:32
2008
@@ -9,8 +9,6 @@
//under the License.
#endregion
-using System;
-
namespace Migrator.Framework.Loggers
{
/// <summary>
Modified: trunk/src/Migrator.Framework/Loggers/Logger.cs
==============================================================================
--- trunk/src/Migrator.Framework/Loggers/Logger.cs (original)
+++ trunk/src/Migrator.Framework/Loggers/Logger.cs Thu Sep 11 14:48:32 2008
@@ -11,7 +11,6 @@
using System;
using System.Collections.Generic;
-using Migrator.Framework;
namespace Migrator.Framework.Loggers
{
@@ -20,8 +19,7 @@
/// </summary>
public class Logger : IAttachableLogger
{
- private readonly int _widthFirstColumn = 5;
- private readonly bool _trace = false;
+ private readonly bool _trace;
private readonly List<ILogWriter> _writers = new List<ILogWriter>();
public Logger(bool trace)
@@ -57,17 +55,17 @@
public void MigrateUp(long version, string migrationName)
{
- WriteLine("Applying {0}: {1}",
version.ToString().PadLeft(_widthFirstColumn), migrationName);
+ WriteLine("Applying {0}: {1}", version.ToString(), migrationName);
}
public void MigrateDown(long version, string migrationName)
{
- WriteLine("Removing {0}: {1}",
version.ToString().PadLeft(_widthFirstColumn), migrationName);
+ WriteLine("Removing {0}: {1}", version.ToString(), migrationName);
}
public void Skipping(long version)
{
- WriteLine("{0} {1}",
version.ToString().PadLeft(_widthFirstColumn), "<Migration not found>");
+ WriteLine("{0} {1}", version.ToString(), "<Migration not found>");
}
public void RollingBack(long originalVersion)
@@ -82,24 +80,34 @@
public void Exception(long version, string migrationName, Exception ex)
{
- WriteLine("{0} Error in migration {1} :
{2}", "".PadLeft(_widthFirstColumn), version, ex.Message);
- if (_trace)
- {
- WriteLine("========= Error detail =========");
- WriteLine(ex.ToString());
- WriteLine(ex.StackTrace);
- Exception iex = ex.InnerException;
- while (iex != null)
- {
- WriteLine("Caused by: {0}", iex);
- WriteLine(ex.StackTrace);
- iex = iex.InnerException;
- }
- WriteLine("======================================");
- }
+ WriteLine("============ Error Detail ============");
+ WriteLine("Error in migration: {0}", version);
+ LogExceptionDetails(ex);
+ WriteLine("======================================");
}
- public void Finished(long originalVersion, long currentVersion)
+ public void Exception(string message, Exception ex)
+ {
+ WriteLine("============ Error Detail ============");
+ WriteLine("Error: {0}", message);
+ LogExceptionDetails(ex);
+ WriteLine("======================================");
+ }
+
+ private void LogExceptionDetails(Exception ex)
+ {
+ WriteLine("{0}", ex.Message);
+ WriteLine("{0}", ex.StackTrace);
+ Exception iex = ex.InnerException;
+ while (iex != null)
+ {
+ WriteLine("Caused by: {0}", iex);
+ WriteLine("{0}", ex.StackTrace);
+ iex = iex.InnerException;
+ }
+ }
+
+ public void Finished(long originalVersion, long currentVersion)
{
WriteLine("Migrated to version {0}", currentVersion);
}
@@ -111,13 +119,12 @@
public void Log(string format, params object[] args)
{
- Write("{0} ", "".PadLeft(_widthFirstColumn));
WriteLine(format, args);
}
public void Warn(string format, params object[] args)
{
- Write("{0} Warning! : ", "".PadLeft(_widthFirstColumn));
+ Write("Warning! : ");
WriteLine(format, args);
}
@@ -150,8 +157,9 @@
return new Logger(false, new ConsoleWriter());
}
- private string LatestVersion(List<long> versions){
- if(versions.Count > 0)
+ private string LatestVersion(List<long> versions)
+ {
+ if (versions.Count > 0)
{
return versions[versions.Count - 1].ToString();
}
Modified: trunk/src/Migrator.Framework/Loggers/SqlScriptFileLogger.cs
==============================================================================
--- trunk/src/Migrator.Framework/Loggers/SqlScriptFileLogger.cs (original)
+++ trunk/src/Migrator.Framework/Loggers/SqlScriptFileLogger.cs Thu Sep 11
14:48:32 2008
@@ -79,6 +79,11 @@
_innerLogger.Exception(version, migrationName, ex);
}
+ public void Exception(string message, Exception ex)
+ {
+ _innerLogger.Exception(message, ex);
+ }
+
public void Finished(List<long> appliedVersions, long
currentVersion)
{
_innerLogger.Finished(appliedVersions, currentVersion);
Modified: trunk/src/Migrator.MSBuild/Logger/TaskLogger.cs
==============================================================================
--- trunk/src/Migrator.MSBuild/Logger/TaskLogger.cs (original)
+++ trunk/src/Migrator.MSBuild/Logger/TaskLogger.cs Thu Sep 11 14:48:32 2008
@@ -22,7 +22,6 @@
/// </summary>
public class TaskLogger : ILogger
{
- private int _widthFirstColumn = 5;
private readonly Task _task;
public TaskLogger(Task task)
@@ -52,12 +51,12 @@
public void MigrateUp(long version, string migrationName)
{
- LogInfo("Applying {0}: {1}",
version.ToString().PadLeft(_widthFirstColumn), migrationName);
+ LogInfo("Applying {0}: {1}", version.ToString(), migrationName);
}
public void MigrateDown(long version, string migrationName)
{
- LogInfo("Removing {0}: {1}",
version.ToString().PadLeft(_widthFirstColumn), migrationName);
+ LogInfo("Removing {0}: {1}", version.ToString(), migrationName);
}
public void Skipping(long version)
@@ -77,10 +76,19 @@
public void Exception(long version, string migrationName,
Exception ex)
{
- LogInfo("{0} Error in migration {1} :
{2}", "".PadLeft(_widthFirstColumn), version, ex.Message);
+ LogInfo("============ Error Detail ============");
+ LogInfo("Error in migration: {0}", version);
_task.Log.LogErrorFromException(ex, true);
+ LogInfo("======================================");
+ }
+
+ public void Exception(string message, Exception ex)
+ {
+ LogInfo("============ Error Detail ============");
+ LogInfo("Error: {0}", message);
+ _task.Log.LogErrorFromException(ex, true);
+ LogInfo("======================================");
}
-
public void Finished(long originalVersion, long currentVersion)
{
@@ -94,17 +102,17 @@
public void Log(string format, params object[] args)
{
- LogInfo("{0} {1}", "".PadLeft(_widthFirstColumn),
String.Format(format, args));
+ LogInfo(format, args);
}
public void Warn(string format, params object[] args)
{
- _task.Log.LogWarning("{0} [Warning]
{1}", "".PadLeft(_widthFirstColumn), String.Format(format, args));
+ _task.Log.LogWarning("[Warning] {0}", String.Format(format,
args));
}
public void Trace(string format, params object[] args)
{
- _task.Log.LogMessage(MessageImportance.Low, "{0}
{1}", "".PadLeft(_widthFirstColumn), String.Format(format, args));
+ _task.Log.LogMessage(MessageImportance.Low, format, args);
}
private string LatestVersion(List<long> versions)
Modified: trunk/src/Migrator.NAnt/Loggers/TaskLogger.cs
==============================================================================
--- trunk/src/Migrator.NAnt/Loggers/TaskLogger.cs (original)
+++ trunk/src/Migrator.NAnt/Loggers/TaskLogger.cs Thu Sep 11 14:48:32 2008
@@ -21,8 +21,7 @@
/// </summary>
public class TaskLogger : ILogger
{
- private int _widthFirstColumn = 5;
- private Task _task;
+ private readonly Task _task;
public TaskLogger(Task task)
{
@@ -51,12 +50,12 @@
public void MigrateUp(long version, string migrationName)
{
- LogInfo("Applying {0}: {1}",
version.ToString().PadLeft(_widthFirstColumn), migrationName);
+ LogInfo("Applying {0}: {1}", version.ToString(), migrationName);
}
public void MigrateDown(long version, string migrationName)
{
- LogInfo("Removing {0}: {1}",
version.ToString().PadLeft(_widthFirstColumn), migrationName);
+ LogInfo("Removing {0}: {1}", version.ToString(), migrationName);
}
public void Skipping(long version)
@@ -76,20 +75,34 @@
public void Exception(long version, string migrationName, Exception ex)
{
- LogInfo("{0} Error in migration {1} :
{2}", "".PadLeft(_widthFirstColumn), version, ex.Message);
-
- LogError(ex.Message);
- LogError(ex.StackTrace);
- Exception iex = ex.InnerException;
- while (ex.InnerException != null)
- {
- LogError("Caused by: {0}", ex.InnerException);
- LogError(ex.InnerException.StackTrace);
- iex = iex.InnerException;
- }
+ LogInfo("============ Error Detail ============");
+ LogInfo("Error in migration: {0}", version);
+ LogExceptionDetails(ex);
+ LogInfo("======================================");
}
-
- public void Finished(long originalVersion, long currentVersion)
+
+ public void Exception(string message, Exception ex)
+ {
+ LogInfo("============ Error Detail ============");
+ LogInfo("Error: {0}", message);
+ LogExceptionDetails(ex);
+ LogInfo("======================================");
+ }
+
+ private void LogExceptionDetails(Exception ex)
+ {
+ LogInfo("{0}", ex.Message);
+ LogInfo("{0}", ex.StackTrace);
+ Exception iex = ex.InnerException;
+ while (iex != null)
+ {
+ LogInfo("Caused by: {0}", iex);
+ LogInfo("{0}", ex.StackTrace);
+ iex = iex.InnerException;
+ }
+ }
+
+ public void Finished(long originalVersion, long currentVersion)
{
LogInfo("Migrated to version {0}", currentVersion);
}
@@ -101,20 +114,21 @@
public void Log(string format, params object[] args)
{
- LogInfo("{0} {1}", "".PadLeft(_widthFirstColumn), String.Format(format,
args));
+ LogInfo(format, args);
}
public void Warn(string format, params object[] args)
{
- LogInfo("{0} [Warning] {1}", "".PadLeft(_widthFirstColumn),
String.Format(format, args));
+ LogInfo("[Warning] {0}", String.Format(format, args));
}
public void Trace(string format, params object[] args)
{
- _task.Log(Level.Debug, "{0} {1}", "".PadLeft(_widthFirstColumn),
String.Format(format, args));
+ _task.Log(Level.Debug, format, args);
}
- private string LatestVersion(List<long> versions){
+ private string LatestVersion(List<long> versions)
+ {
if(versions.Count > 0)
{
return versions[versions.Count - 1].ToString();