plain log message should not be treated as format string

pull/3374/head
Jan Tattermusch 9 years ago
parent 1965810ede
commit c4ebda7d30
  1. 52
      src/csharp/Grpc.Core/Logging/ConsoleLogger.cs
  2. 24
      src/csharp/Grpc.Core/Logging/ILogger.cs

@ -79,48 +79,72 @@ namespace Grpc.Core.Logging
} }
/// <summary>Logs a message with severity Debug.</summary> /// <summary>Logs a message with severity Debug.</summary>
public void Debug(string message, params object[] formatArgs) public void Debug(string message)
{ {
Log("D", message, formatArgs); Log("D", message);
}
/// <summary>Logs a formatted message with severity Debug.</summary>
public void Debug(string format, params object[] formatArgs)
{
Debug(string.Format(format, formatArgs));
} }
/// <summary>Logs a message with severity Info.</summary> /// <summary>Logs a message with severity Info.</summary>
public void Info(string message, params object[] formatArgs) public void Info(string message)
{
Log("I", message);
}
/// <summary>Logs a formatted message with severity Info.</summary>
public void Info(string format, params object[] formatArgs)
{ {
Log("I", message, formatArgs); Info(string.Format(format, formatArgs));
} }
/// <summary>Logs a message with severity Warning.</summary> /// <summary>Logs a message with severity Warning.</summary>
public void Warning(string message, params object[] formatArgs) public void Warning(string message)
{ {
Log("W", message, formatArgs); Log("W", message);
}
/// <summary>Logs a formatted message with severity Warning.</summary>
public void Warning(string format, params object[] formatArgs)
{
Warning(string.Format(format, formatArgs));
} }
/// <summary>Logs a message and an associated exception with severity Warning.</summary> /// <summary>Logs a message and an associated exception with severity Warning.</summary>
public void Warning(Exception exception, string message, params object[] formatArgs) public void Warning(Exception exception, string message)
{ {
Log("W", message + " " + exception, formatArgs); Warning(message + " " + exception);
} }
/// <summary>Logs a message with severity Error.</summary> /// <summary>Logs a message with severity Error.</summary>
public void Error(string message, params object[] formatArgs) public void Error(string message)
{
Log("E", message);
}
/// <summary>Logs a formatted message with severity Error.</summary>
public void Error(string format, params object[] formatArgs)
{ {
Log("E", message, formatArgs); Error(string.Format(format, formatArgs));
} }
/// <summary>Logs a message and an associated exception with severity Error.</summary> /// <summary>Logs a message and an associated exception with severity Error.</summary>
public void Error(Exception exception, string message, params object[] formatArgs) public void Error(Exception exception, string message)
{ {
Log("E", message + " " + exception, formatArgs); Error(message + " " + exception);
} }
private void Log(string severityString, string message, object[] formatArgs) private void Log(string severityString, string message)
{ {
Console.Error.WriteLine("{0}{1} {2}{3}", Console.Error.WriteLine("{0}{1} {2}{3}",
severityString, severityString,
DateTime.Now, DateTime.Now,
forTypeString, forTypeString,
string.Format(message, formatArgs)); message);
} }
} }
} }

@ -43,21 +43,33 @@ namespace Grpc.Core.Logging
ILogger ForType<T>(); ILogger ForType<T>();
/// <summary>Logs a message with severity Debug.</summary> /// <summary>Logs a message with severity Debug.</summary>
void Debug(string message, params object[] formatArgs); void Debug(string message);
/// <summary>Logs a formatted message with severity Debug.</summary>
void Debug(string format, params object[] formatArgs);
/// <summary>Logs a message with severity Info.</summary> /// <summary>Logs a message with severity Info.</summary>
void Info(string message, params object[] formatArgs); void Info(string message);
/// <summary>Logs a formatted message with severity Info.</summary>
void Info(string format, params object[] formatArgs);
/// <summary>Logs a message with severity Warning.</summary> /// <summary>Logs a message with severity Warning.</summary>
void Warning(string message, params object[] formatArgs); void Warning(string message);
/// <summary>Logs a formatted message with severity Warning.</summary>
void Warning(string format, params object[] formatArgs);
/// <summary>Logs a message and an associated exception with severity Warning.</summary> /// <summary>Logs a message and an associated exception with severity Warning.</summary>
void Warning(Exception exception, string message, params object[] formatArgs); void Warning(Exception exception, string message);
/// <summary>Logs a message with severity Error.</summary> /// <summary>Logs a message with severity Error.</summary>
void Error(string message, params object[] formatArgs); void Error(string message);
/// <summary>Logs a formatted message with severity Error.</summary>
void Error(string format, params object[] formatArgs);
/// <summary>Logs a message and an associated exception with severity Error.</summary> /// <summary>Logs a message and an associated exception with severity Error.</summary>
void Error(Exception exception, string message, params object[] formatArgs); void Error(Exception exception, string message);
} }
} }

Loading…
Cancel
Save