Refactored Logger.cs and LogData.cs
This commit is contained in:
parent
bb8d4c25ba
commit
2ec26308a7
@ -474,7 +474,7 @@ So if you would like to change the current logging level (`WebSocketSharp.LogLev
|
|||||||
ws.Log.Level = LogLevel.Debug;
|
ws.Log.Level = LogLevel.Debug;
|
||||||
```
|
```
|
||||||
|
|
||||||
This means a log with less than `LogLevel.Debug` cannot be outputted.
|
This means a log with lower than `LogLevel.Debug` cannot be outputted.
|
||||||
|
|
||||||
And if you would like to output a log, you should use any of the output methods. The following outputs a log with `LogLevel.Debug`.
|
And if you would like to output a log, you should use any of the output methods. The following outputs a log with `LogLevel.Debug`.
|
||||||
|
|
||||||
|
@ -4,8 +4,8 @@
|
|||||||
*
|
*
|
||||||
* The MIT License
|
* The MIT License
|
||||||
*
|
*
|
||||||
* Copyright (c) 2013 sta.blockhead
|
* Copyright (c) 2013-2014 sta.blockhead
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
* in the Software without restriction, including without limitation the rights
|
* in the Software without restriction, including without limitation the rights
|
||||||
@ -15,7 +15,7 @@
|
|||||||
*
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in
|
* The above copyright notice and this permission notice shall be included in
|
||||||
* all copies or substantial portions of the Software.
|
* all copies or substantial portions of the Software.
|
||||||
*
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
@ -33,7 +33,7 @@ using System.Text;
|
|||||||
namespace WebSocketSharp
|
namespace WebSocketSharp
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents the log data used by the <see cref="Logger"/> class.
|
/// Represents a log data used by the <see cref="Logger"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class LogData
|
public class LogData
|
||||||
{
|
{
|
||||||
@ -52,7 +52,7 @@ namespace WebSocketSharp
|
|||||||
{
|
{
|
||||||
_level = level;
|
_level = level;
|
||||||
_caller = caller;
|
_caller = caller;
|
||||||
_message = message;
|
_message = message ?? String.Empty;
|
||||||
_date = DateTime.Now;
|
_date = DateTime.Now;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,7 +64,7 @@ namespace WebSocketSharp
|
|||||||
/// Gets the information of the logging method caller.
|
/// Gets the information of the logging method caller.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>
|
/// <value>
|
||||||
/// A <see cref="StackFrame"/> that contains the information of a logging method caller.
|
/// A <see cref="StackFrame"/> that provides the information of the logging method caller.
|
||||||
/// </value>
|
/// </value>
|
||||||
public StackFrame Caller {
|
public StackFrame Caller {
|
||||||
get {
|
get {
|
||||||
@ -76,7 +76,7 @@ namespace WebSocketSharp
|
|||||||
/// Gets the date and time when the log data was created.
|
/// Gets the date and time when the log data was created.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>
|
/// <value>
|
||||||
/// A <see cref="DateTime"/> that contains the date and time when the log data was created.
|
/// A <see cref="DateTime"/> that represents the date and time when the log data was created.
|
||||||
/// </value>
|
/// </value>
|
||||||
public DateTime Date {
|
public DateTime Date {
|
||||||
get {
|
get {
|
||||||
@ -85,11 +85,10 @@ namespace WebSocketSharp
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the logging level associated with the log data.
|
/// Gets the logging level of the log data.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>
|
/// <value>
|
||||||
/// One of the <see cref="LogLevel"/> values that indicates the logging level
|
/// One of the <see cref="LogLevel"/> enum values, indicates the logging level of the log data.
|
||||||
/// associated with the log data.
|
|
||||||
/// </value>
|
/// </value>
|
||||||
public LogLevel Level {
|
public LogLevel Level {
|
||||||
get {
|
get {
|
||||||
@ -101,7 +100,7 @@ namespace WebSocketSharp
|
|||||||
/// Gets the message of the log data.
|
/// Gets the message of the log data.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>
|
/// <value>
|
||||||
/// A <see cref="string"/> that contains the message of a log data.
|
/// A <see cref="string"/> that represents the message of the log data.
|
||||||
/// </value>
|
/// </value>
|
||||||
public string Message {
|
public string Message {
|
||||||
get {
|
get {
|
||||||
@ -126,7 +125,8 @@ namespace WebSocketSharp
|
|||||||
var type = method.DeclaringType;
|
var type = method.DeclaringType;
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
var lineNum = _caller.GetFileLineNumber ();
|
var lineNum = _caller.GetFileLineNumber ();
|
||||||
var headerAndCaller = String.Format ("{0}{1}.{2}:{3}|", header, type.Name, method.Name, lineNum);
|
var headerAndCaller = String.Format (
|
||||||
|
"{0}{1}.{2}:{3}|", header, type.Name, method.Name, lineNum);
|
||||||
#else
|
#else
|
||||||
var headerAndCaller = String.Format ("{0}{1}.{2}|", header, type.Name, method.Name);
|
var headerAndCaller = String.Format ("{0}{1}.{2}|", header, type.Name, method.Name);
|
||||||
#endif
|
#endif
|
||||||
@ -135,14 +135,16 @@ namespace WebSocketSharp
|
|||||||
if (messages.Length <= 1)
|
if (messages.Length <= 1)
|
||||||
return String.Format ("{0}{1}", headerAndCaller, _message);
|
return String.Format ("{0}{1}", headerAndCaller, _message);
|
||||||
|
|
||||||
var output = new StringBuilder (String.Format ("{0}{1}\n", headerAndCaller, messages [0]), 64);
|
var log = new StringBuilder (
|
||||||
|
String.Format ("{0}{1}\n", headerAndCaller, messages [0]), 64);
|
||||||
|
|
||||||
var space = header.Length;
|
var space = header.Length;
|
||||||
var format = String.Format ("{{0,{0}}}{{1}}\n", space);
|
var format = String.Format ("{{0,{0}}}{{1}}\n", space);
|
||||||
for (var i = 1; i < messages.Length; i++)
|
for (var i = 1; i < messages.Length; i++)
|
||||||
output.AppendFormat (format, "", messages [i]);
|
log.AppendFormat (format, "", messages [i]);
|
||||||
|
|
||||||
output.Length--;
|
log.Length--;
|
||||||
return output.ToString ();
|
return log.ToString ();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
@ -4,8 +4,8 @@
|
|||||||
*
|
*
|
||||||
* The MIT License
|
* The MIT License
|
||||||
*
|
*
|
||||||
* Copyright (c) 2013 sta.blockhead
|
* Copyright (c) 2013-2014 sta.blockhead
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
* in the Software without restriction, including without limitation the rights
|
* in the Software without restriction, including without limitation the rights
|
||||||
@ -15,7 +15,7 @@
|
|||||||
*
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in
|
* The above copyright notice and this permission notice shall be included in
|
||||||
* all copies or substantial portions of the Software.
|
* all copies or substantial portions of the Software.
|
||||||
*
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
@ -33,22 +33,20 @@ using System.IO;
|
|||||||
namespace WebSocketSharp
|
namespace WebSocketSharp
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Provides the simple logging functions.
|
/// Provides a set of methods and properties for logging.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <remarks>
|
/// <remarks>
|
||||||
/// <para>
|
/// <para>
|
||||||
/// The Logger class provides some methods that output the logs associated with the each
|
/// If you output a log with lower than the <see cref="Logger.Level"/>,
|
||||||
/// <see cref="LogLevel"/> values.
|
/// it cannot be outputted.
|
||||||
/// If the <see cref="LogLevel"/> value associated with a log is less than the <see cref="Level"/>,
|
|
||||||
/// the log can not be outputted.
|
|
||||||
/// </para>
|
/// </para>
|
||||||
/// <para>
|
/// <para>
|
||||||
/// The default output action used by the output methods outputs the log data to the standard output stream
|
/// The default output action writes a log to the standard output stream and
|
||||||
/// and writes the same log data to the <see cref="Logger.File"/> if it has a valid path.
|
/// the <see cref="Logger.File"/> if it has a valid path.
|
||||||
/// </para>
|
/// </para>
|
||||||
/// <para>
|
/// <para>
|
||||||
/// If you want to run custom output action, you can replace the current output action with
|
/// If you would like to use the custom output action, you should set the
|
||||||
/// your output action by using the <see cref="SetOutput"/> method.
|
/// <see cref="Logger.Output"/> to any <c>Action<LogData, string></c>.
|
||||||
/// </para>
|
/// </para>
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
public class Logger
|
public class Logger
|
||||||
@ -68,8 +66,7 @@ namespace WebSocketSharp
|
|||||||
/// Initializes a new instance of the <see cref="Logger"/> class.
|
/// Initializes a new instance of the <see cref="Logger"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <remarks>
|
/// <remarks>
|
||||||
/// This constructor initializes the current logging level with the <see cref="LogLevel.Error"/> and
|
/// This constructor initializes the current logging level with <see cref="LogLevel.Error"/>.
|
||||||
/// initializes the path to the log file with <see langword="null"/>.
|
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
public Logger ()
|
public Logger ()
|
||||||
: this (LogLevel.Error, null, null)
|
: this (LogLevel.Error, null, null)
|
||||||
@ -77,14 +74,11 @@ namespace WebSocketSharp
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="Logger"/> class
|
/// Initializes a new instance of the <see cref="Logger"/> class with the specified
|
||||||
/// with the specified logging <paramref name="level"/>.
|
/// logging <paramref name="level"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <remarks>
|
|
||||||
/// This constructor initializes the path to the log file with <see langword="null"/>.
|
|
||||||
/// </remarks>
|
|
||||||
/// <param name="level">
|
/// <param name="level">
|
||||||
/// One of the <see cref="LogLevel"/> values to initialize.
|
/// One of the <see cref="LogLevel"/> enum values.
|
||||||
/// </param>
|
/// </param>
|
||||||
public Logger (LogLevel level)
|
public Logger (LogLevel level)
|
||||||
: this (level, null, null)
|
: this (level, null, null)
|
||||||
@ -92,26 +86,26 @@ namespace WebSocketSharp
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="Logger"/> class
|
/// Initializes a new instance of the <see cref="Logger"/> class with the specified
|
||||||
/// with the specified logging <paramref name="level"/>, path to the log <paramref name="file"/>
|
/// logging <paramref name="level"/>, path to the log <paramref name="file"/>, and
|
||||||
/// and <paramref name="output"/> action.
|
/// <paramref name="output"/> action.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="level">
|
/// <param name="level">
|
||||||
/// One of the <see cref="LogLevel"/> values to initialize.
|
/// One of the <see cref="LogLevel"/> enum values.
|
||||||
/// </param>
|
/// </param>
|
||||||
/// <param name="file">
|
/// <param name="file">
|
||||||
/// A <see cref="string"/> that contains a path to the log file to initialize.
|
/// A <see cref="string"/> that represents the path to the log file.
|
||||||
/// </param>
|
/// </param>
|
||||||
/// <param name="output">
|
/// <param name="output">
|
||||||
/// An <c>Action<LogData, string></c> delegate that references the method(s) to initialize.
|
/// An <c>Action<LogData, string></c> delegate that references the method(s)
|
||||||
/// A <see cref="string"/> parameter to pass to the method(s) is the value of the <see cref="Logger.File"/>
|
/// used to output a log. A <see cref="string"/> parameter passed to this delegate
|
||||||
/// if any.
|
/// is <paramref name="file"/> if any.
|
||||||
/// </param>
|
/// </param>
|
||||||
public Logger (LogLevel level, string file, Action<LogData, string> output)
|
public Logger (LogLevel level, string file, Action<LogData, string> output)
|
||||||
{
|
{
|
||||||
_level = level;
|
_level = level;
|
||||||
_file = file;
|
_file = file;
|
||||||
_output = output != null ? output : defaultOutput;
|
_output = output ?? defaultOutput;
|
||||||
_sync = new object ();
|
_sync = new object ();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -123,7 +117,7 @@ namespace WebSocketSharp
|
|||||||
/// Gets or sets the path to the log file.
|
/// Gets or sets the path to the log file.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>
|
/// <value>
|
||||||
/// A <see cref="string"/> that contains a path to the log file if any.
|
/// A <see cref="string"/> that represents the path to the log file if any.
|
||||||
/// </value>
|
/// </value>
|
||||||
public string File {
|
public string File {
|
||||||
get {
|
get {
|
||||||
@ -131,10 +125,10 @@ namespace WebSocketSharp
|
|||||||
}
|
}
|
||||||
|
|
||||||
set {
|
set {
|
||||||
lock (_sync)
|
lock (_sync) {
|
||||||
{
|
|
||||||
_file = value;
|
_file = value;
|
||||||
Warn (String.Format ("The current path to the log file has been changed to {0}.", _file ?? ""));
|
Warn (
|
||||||
|
String.Format ("The current path to the log file has been changed to {0}.", _file));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -143,10 +137,10 @@ namespace WebSocketSharp
|
|||||||
/// Gets or sets the current logging level.
|
/// Gets or sets the current logging level.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <remarks>
|
/// <remarks>
|
||||||
/// A log associated with a less than the current logging level can not be outputted.
|
/// A log with lower than the value of this property cannot be outputted.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
/// <value>
|
/// <value>
|
||||||
/// One of the <see cref="LogLevel"/> values that indicates the current logging level.
|
/// One of the <see cref="LogLevel"/> enum values, indicates the current logging level.
|
||||||
/// </value>
|
/// </value>
|
||||||
public LogLevel Level {
|
public LogLevel Level {
|
||||||
get {
|
get {
|
||||||
@ -154,8 +148,37 @@ namespace WebSocketSharp
|
|||||||
}
|
}
|
||||||
|
|
||||||
set {
|
set {
|
||||||
_level = value;
|
lock (_sync) {
|
||||||
Warn (String.Format ("The current logging level has been changed to {0}.", _level));
|
_level = value;
|
||||||
|
Warn (String.Format ("The current logging level has been changed to {0}.", _level));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the current output action used to output a log.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>
|
||||||
|
/// <para>
|
||||||
|
/// An <c>Action<LogData, string></c> delegate that references the method(s) used to
|
||||||
|
/// output a log. A <see cref="string"/> parameter passed to this delegate is the value of
|
||||||
|
/// the <see cref="Logger.File"/> if any.
|
||||||
|
/// </para>
|
||||||
|
/// <para>
|
||||||
|
/// If the value to set is <see langword="null"/>, the current output action is changed to
|
||||||
|
/// the default output action.
|
||||||
|
/// </para>
|
||||||
|
/// </value>
|
||||||
|
public Action<LogData, string> Output {
|
||||||
|
get {
|
||||||
|
return _output;
|
||||||
|
}
|
||||||
|
|
||||||
|
set {
|
||||||
|
lock (_sync) {
|
||||||
|
_output = value ?? defaultOutput;
|
||||||
|
Warn ("The current output action has been changed.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -168,16 +191,15 @@ namespace WebSocketSharp
|
|||||||
var log = data.ToString ();
|
var log = data.ToString ();
|
||||||
Console.WriteLine (log);
|
Console.WriteLine (log);
|
||||||
if (path != null && path.Length > 0)
|
if (path != null && path.Length > 0)
|
||||||
writeLine (log, path);
|
writeToFile (path, log);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void output (string message, LogLevel level)
|
private void output (string message, LogLevel level)
|
||||||
{
|
{
|
||||||
if (level < _level || message == null || message.Length == 0)
|
lock (_sync) {
|
||||||
return;
|
if (_level > level)
|
||||||
|
return;
|
||||||
|
|
||||||
lock (_sync)
|
|
||||||
{
|
|
||||||
LogData data = null;
|
LogData data = null;
|
||||||
try {
|
try {
|
||||||
data = new LogData (level, new StackFrame (2, true), message);
|
data = new LogData (level, new StackFrame (2, true), message);
|
||||||
@ -190,11 +212,10 @@ namespace WebSocketSharp
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void writeLine (string value, string path)
|
private static void writeToFile (string path, string value)
|
||||||
{
|
{
|
||||||
using (var writer = new StreamWriter (path, true))
|
using (var writer = new StreamWriter (path, true))
|
||||||
using (var syncWriter = TextWriter.Synchronized (writer))
|
using (var syncWriter = TextWriter.Synchronized (writer)) {
|
||||||
{
|
|
||||||
syncWriter.WriteLine (value);
|
syncWriter.WriteLine (value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -204,44 +225,46 @@ namespace WebSocketSharp
|
|||||||
#region Public Methods
|
#region Public Methods
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Outputs the specified <see cref="string"/> as a log with the <see cref="LogLevel.Debug"/>.
|
/// Outputs <paramref name="message"/> as a log with <see cref="LogLevel.Debug"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <remarks>
|
/// <remarks>
|
||||||
/// If the current logging level is greater than the <see cref="LogLevel.Debug"/>,
|
/// If the current logging level is higher than <see cref="LogLevel.Debug"/>, this method
|
||||||
/// this method does not output <paramref name="message"/> as a log.
|
/// doesn't output <paramref name="message"/> as a log.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
/// <param name="message">
|
/// <param name="message">
|
||||||
/// A <see cref="string"/> that contains a message to output as a log.
|
/// A <see cref="string"/> that represents the message to output as a log.
|
||||||
/// </param>
|
/// </param>
|
||||||
public void Debug (string message)
|
public void Debug (string message)
|
||||||
{
|
{
|
||||||
|
if (_level > LogLevel.Debug)
|
||||||
|
return;
|
||||||
|
|
||||||
output (message, LogLevel.Debug);
|
output (message, LogLevel.Debug);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Outputs the specified <see cref="string"/> as a log with the <see cref="LogLevel.Error"/>.
|
/// Outputs <paramref name="message"/> as a log with <see cref="LogLevel.Error"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <remarks>
|
/// <remarks>
|
||||||
/// If the current logging level is greater than the <see cref="LogLevel.Error"/>,
|
/// If the current logging level is higher than <see cref="LogLevel.Error"/>, this method
|
||||||
/// this method does not output <paramref name="message"/> as a log.
|
/// doesn't output <paramref name="message"/> as a log.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
/// <param name="message">
|
/// <param name="message">
|
||||||
/// A <see cref="string"/> that contains a message to output as a log.
|
/// A <see cref="string"/> that represents the message to output as a log.
|
||||||
/// </param>
|
/// </param>
|
||||||
public void Error (string message)
|
public void Error (string message)
|
||||||
{
|
{
|
||||||
|
if (_level > LogLevel.Error)
|
||||||
|
return;
|
||||||
|
|
||||||
output (message, LogLevel.Error);
|
output (message, LogLevel.Error);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Outputs the specified <see cref="string"/> as a log with the <see cref="LogLevel.Fatal"/>.
|
/// Outputs <paramref name="message"/> as a log with <see cref="LogLevel.Fatal"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <remarks>
|
|
||||||
/// If the current logging level is greater than the <see cref="LogLevel.Fatal"/>,
|
|
||||||
/// this method does not output <paramref name="message"/> as a log.
|
|
||||||
/// </remarks>
|
|
||||||
/// <param name="message">
|
/// <param name="message">
|
||||||
/// A <see cref="string"/> that contains a message to output as a log.
|
/// A <see cref="string"/> that represents the message to output as a log.
|
||||||
/// </param>
|
/// </param>
|
||||||
public void Fatal (string message)
|
public void Fatal (string message)
|
||||||
{
|
{
|
||||||
@ -249,68 +272,56 @@ namespace WebSocketSharp
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Outputs the specified <see cref="string"/> as a log with the <see cref="LogLevel.Info"/>.
|
/// Outputs <paramref name="message"/> as a log with <see cref="LogLevel.Info"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <remarks>
|
/// <remarks>
|
||||||
/// If the current logging level is greater than the <see cref="LogLevel.Info"/>,
|
/// If the current logging level is higher than <see cref="LogLevel.Info"/>, this method
|
||||||
/// this method does not output <paramref name="message"/> as a log.
|
/// doesn't output <paramref name="message"/> as a log.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
/// <param name="message">
|
/// <param name="message">
|
||||||
/// A <see cref="string"/> that contains a message to output as a log.
|
/// A <see cref="string"/> that represents the message to output as a log.
|
||||||
/// </param>
|
/// </param>
|
||||||
public void Info (string message)
|
public void Info (string message)
|
||||||
{
|
{
|
||||||
|
if (_level > LogLevel.Info)
|
||||||
|
return;
|
||||||
|
|
||||||
output (message, LogLevel.Info);
|
output (message, LogLevel.Info);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Replaces the current output action with the specified <paramref name="output"/> action.
|
/// Outputs <paramref name="message"/> as a log with <see cref="LogLevel.Trace"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <remarks>
|
/// <remarks>
|
||||||
/// If <paramref name="output"/> is <see langword="null"/>,
|
/// If the current logging level is higher than <see cref="LogLevel.Trace"/>, this method
|
||||||
/// this method replaces the current output action with the default output action.
|
/// doesn't output <paramref name="message"/> as a log.
|
||||||
/// </remarks>
|
|
||||||
/// <param name="output">
|
|
||||||
/// An <c>Action<LogData, string></c> delegate that references the method(s) to set.
|
|
||||||
/// A <see cref="string"/> parameter to pass to the method(s) is the value of the <see cref="Logger.File"/>
|
|
||||||
/// if any.
|
|
||||||
/// </param>
|
|
||||||
public void SetOutput (Action<LogData, string> output)
|
|
||||||
{
|
|
||||||
lock (_sync)
|
|
||||||
{
|
|
||||||
_output = output != null ? output : defaultOutput;
|
|
||||||
Warn ("The current output action has been replaced.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Outputs the specified <see cref="string"/> as a log with the <see cref="LogLevel.Trace"/>.
|
|
||||||
/// </summary>
|
|
||||||
/// <remarks>
|
|
||||||
/// If the current logging level is greater than the <see cref="LogLevel.Trace"/>,
|
|
||||||
/// this method does not output <paramref name="message"/> as a log.
|
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
/// <param name="message">
|
/// <param name="message">
|
||||||
/// A <see cref="string"/> that contains a message to output as a log.
|
/// A <see cref="string"/> that represents the message to output as a log.
|
||||||
/// </param>
|
/// </param>
|
||||||
public void Trace (string message)
|
public void Trace (string message)
|
||||||
{
|
{
|
||||||
|
if (_level > LogLevel.Trace)
|
||||||
|
return;
|
||||||
|
|
||||||
output (message, LogLevel.Trace);
|
output (message, LogLevel.Trace);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Outputs the specified <see cref="string"/> as a log with the <see cref="LogLevel.Warn"/>.
|
/// Outputs <paramref name="message"/> as a log with <see cref="LogLevel.Warn"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <remarks>
|
/// <remarks>
|
||||||
/// If the current logging level is greater than the <see cref="LogLevel.Warn"/>,
|
/// If the current logging level is higher than <see cref="LogLevel.Warn"/>, this method
|
||||||
/// this method does not output <paramref name="message"/> as a log.
|
/// doesn't output <paramref name="message"/> as a log.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
/// <param name="message">
|
/// <param name="message">
|
||||||
/// A <see cref="string"/> that contains a message to output as a log.
|
/// A <see cref="string"/> that represents the message to output as a log.
|
||||||
/// </param>
|
/// </param>
|
||||||
public void Warn (string message)
|
public void Warn (string message)
|
||||||
{
|
{
|
||||||
|
if (_level > LogLevel.Warn)
|
||||||
|
return;
|
||||||
|
|
||||||
output (message, LogLevel.Warn);
|
output (message, LogLevel.Warn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user