up
This commit is contained in:
122
Assets/BestHTTP/Logger/DefaultLogger.cs
Normal file
122
Assets/BestHTTP/Logger/DefaultLogger.cs
Normal file
@@ -0,0 +1,122 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace BestHTTP.Logger
|
||||
{
|
||||
/// <summary>
|
||||
/// A basic logger implementation to be able to log intelligently additional informations about the plugin's internal mechanism.
|
||||
/// </summary>
|
||||
public class DefaultLogger : BestHTTP.Logger.ILogger
|
||||
{
|
||||
public Loglevels Level { get; set; }
|
||||
public string FormatVerbose { get; set; }
|
||||
public string FormatInfo { get; set; }
|
||||
public string FormatWarn { get; set; }
|
||||
public string FormatErr { get; set; }
|
||||
public string FormatEx { get; set; }
|
||||
|
||||
public DefaultLogger()
|
||||
{
|
||||
FormatVerbose = "D [{0}]: {1}";
|
||||
FormatInfo = "I [{0}]: {1}";
|
||||
FormatWarn = "W [{0}]: {1}";
|
||||
FormatErr = "Err [{0}]: {1}";
|
||||
FormatEx = "Ex [{0}]: {1} - Message: {2} StackTrace: {3}";
|
||||
|
||||
Level = UnityEngine.Debug.isDebugBuild ? Loglevels.Warning : Loglevels.Error;
|
||||
}
|
||||
|
||||
public void Verbose(string division, string verb)
|
||||
{
|
||||
if (Level <= Loglevels.All)
|
||||
{
|
||||
try
|
||||
{
|
||||
UnityEngine.Debug.Log(string.Format(FormatVerbose, division, verb));
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
}
|
||||
}
|
||||
|
||||
public void Information(string division, string info)
|
||||
{
|
||||
if (Level <= Loglevels.Information)
|
||||
{
|
||||
try
|
||||
{
|
||||
UnityEngine.Debug.Log(string.Format(FormatInfo, division, info));
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
}
|
||||
}
|
||||
|
||||
public void Warning(string division, string warn)
|
||||
{
|
||||
if (Level <= Loglevels.Warning)
|
||||
{
|
||||
try
|
||||
{
|
||||
UnityEngine.Debug.LogWarning(string.Format(FormatWarn, division, warn));
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
}
|
||||
}
|
||||
|
||||
public void Error(string division, string err)
|
||||
{
|
||||
if (Level <= Loglevels.Error)
|
||||
{
|
||||
try
|
||||
{
|
||||
UnityEngine.Debug.LogError(string.Format(FormatErr, division, err));
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
}
|
||||
}
|
||||
|
||||
public void Exception(string division, string msg, Exception ex)
|
||||
{
|
||||
if (Level <= Loglevels.Exception)
|
||||
{
|
||||
try
|
||||
{
|
||||
string exceptionMessage = string.Empty;
|
||||
if (ex == null)
|
||||
exceptionMessage = "null";
|
||||
else
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
Exception exception = ex;
|
||||
int counter = 1;
|
||||
while (exception != null)
|
||||
{
|
||||
sb.AppendFormat("{0}: {1} {2}", counter++.ToString(), ex.Message, ex.StackTrace);
|
||||
|
||||
exception = exception.InnerException;
|
||||
|
||||
if (exception != null)
|
||||
sb.AppendLine();
|
||||
}
|
||||
|
||||
exceptionMessage = sb.ToString();
|
||||
}
|
||||
|
||||
UnityEngine.Debug.LogError(string.Format(FormatEx,
|
||||
division,
|
||||
msg,
|
||||
exceptionMessage,
|
||||
ex != null ? ex.StackTrace : "null"));
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/BestHTTP/Logger/DefaultLogger.cs.meta
Normal file
11
Assets/BestHTTP/Logger/DefaultLogger.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 764fa0b0e514f4fa8b9dc546abcad397
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
62
Assets/BestHTTP/Logger/ILogger.cs
Normal file
62
Assets/BestHTTP/Logger/ILogger.cs
Normal file
@@ -0,0 +1,62 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace BestHTTP.Logger
|
||||
{
|
||||
/// <summary>
|
||||
/// Available logging levels.
|
||||
/// </summary>
|
||||
public enum Loglevels : byte
|
||||
{
|
||||
/// <summary>
|
||||
/// All message will be logged.
|
||||
/// </summary>
|
||||
All,
|
||||
|
||||
/// <summary>
|
||||
/// Only Informations and above will be logged.
|
||||
/// </summary>
|
||||
Information,
|
||||
|
||||
/// <summary>
|
||||
/// Only Warnings and above will be logged.
|
||||
/// </summary>
|
||||
Warning,
|
||||
|
||||
/// <summary>
|
||||
/// Only Errors and above will be logged.
|
||||
/// </summary>
|
||||
Error,
|
||||
|
||||
/// <summary>
|
||||
/// Only Exceptions will be logged.
|
||||
/// </summary>
|
||||
Exception,
|
||||
|
||||
/// <summary>
|
||||
/// No logging will be occur.
|
||||
/// </summary>
|
||||
None
|
||||
}
|
||||
|
||||
public interface ILogger
|
||||
{
|
||||
/// <summary>
|
||||
/// The minimum severity to log
|
||||
/// </summary>
|
||||
Loglevels Level { get; set; }
|
||||
string FormatVerbose { get; set; }
|
||||
string FormatInfo { get; set; }
|
||||
string FormatWarn { get; set; }
|
||||
string FormatErr { get; set; }
|
||||
string FormatEx { get; set; }
|
||||
|
||||
void Verbose(string division, string verb);
|
||||
void Information(string division, string info);
|
||||
void Warning(string division, string warn);
|
||||
void Error(string division, string err);
|
||||
void Exception(string division, string msg, Exception ex);
|
||||
}
|
||||
}
|
||||
11
Assets/BestHTTP/Logger/ILogger.cs.meta
Normal file
11
Assets/BestHTTP/Logger/ILogger.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 38ac7ce282efe410fa1a91eb0045d712
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user