Skip to content

Commit

Permalink
增加延迟构造log,建议使用,防止开启不同级别的log仍然构建字符串产生gc
Browse files Browse the repository at this point in the history
  • Loading branch information
egametang committed Nov 29, 2018
1 parent 1014fe1 commit f6d9574
Show file tree
Hide file tree
Showing 7 changed files with 128 additions and 114 deletions.
40 changes: 0 additions & 40 deletions Server/Model/Base/Logger/ALogDecorater.cs

This file was deleted.

6 changes: 6 additions & 0 deletions Server/Model/Base/Logger/ILog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,11 @@ public interface ILog
void Debug(string message);
void Error(string message);
void Fatal(string message);
void Trace(string message, params object[] args);
void Warning(string message, params object[] args);
void Info(string message, params object[] args);
void Debug(string message, params object[] args);
void Error(string message, params object[] args);
void Fatal(string message, params object[] args);
}
}
50 changes: 38 additions & 12 deletions Server/Model/Base/Logger/NLogAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,68 @@

namespace ETModel
{
public class NLogAdapter: ALogDecorater, ILog
public class NLogAdapter: ILog
{
private readonly Logger logger = LogManager.GetLogger("Logger");

public NLogAdapter(ALogDecorater decorater = null): base(decorater)
{
}

public void Trace(string message)
{
this.logger.Trace(this.Decorate(message));
this.logger.Trace(message);
}

public void Warning(string message)
{
this.logger.Warn(this.Decorate(message));
this.logger.Warn(message);
}

public void Info(string message)
{
this.logger.Info(this.Decorate(message));
this.logger.Info(message);
}

public void Debug(string message)
{
this.logger.Debug(this.Decorate(message));
this.logger.Debug(message);
}

public void Error(string message)
{
this.logger.Error(this.Decorate(message));
this.logger.Error(message);
}

public void Fatal(string message)
{
this.logger.Fatal(this.Decorate(message));
this.logger.Fatal(message);
}
}

public void Trace(string message, params object[] args)
{
this.logger.Trace(message, args);
}

public void Warning(string message, params object[] args)
{
this.logger.Warn(message, args);
}

public void Info(string message, params object[] args)
{
this.logger.Info(message, args);
}

public void Debug(string message, params object[] args)
{
this.logger.Debug(message, args);
}

public void Error(string message, params object[] args)
{
this.logger.Error(message, args);
}

public void Fatal(string message, params object[] args)
{
this.logger.Fatal(message, args);
}
}
}
47 changes: 0 additions & 47 deletions Server/Model/Base/Logger/StackInfoDecorater.cs

This file was deleted.

36 changes: 35 additions & 1 deletion Unity/Assets/Hotfix/Base/Log.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ namespace ETHotfix
{
public static class Log
{
public static void Trace(string msg)
{
ETModel.Log.Trace(msg);
}

public static void Warning(string msg)
{
ETModel.Log.Warning(msg);
Expand All @@ -29,9 +34,38 @@ public static void Debug(string msg)
ETModel.Log.Debug(msg);
}

public static void Trace(string message, params object[] args)
{
ETModel.Log.Trace(message, args);
}

public static void Warning(string message, params object[] args)
{
ETModel.Log.Warning(message, args);
}

public static void Info(string message, params object[] args)
{
ETModel.Log.Info(message, args);
}

public static void Debug(string message, params object[] args)
{
ETModel.Log.Debug(message, args);
}

public static void Error(string message, params object[] args)
{
ETModel.Log.Error(message, args);
}

public static void Fatal(string message, params object[] args)
{
ETModel.Log.Fatal(message, args);
}

public static void Msg(object msg)
{

Debug(Dumper.DumpAsString(msg));
}
}
Expand Down
51 changes: 43 additions & 8 deletions Unity/Assets/Model/Base/Log.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,65 @@ public static void Trace(string msg)
{
UnityEngine.Debug.Log(msg);
}

public static void Warning(string msg)
public static void Debug(string msg)
{
UnityEngine.Debug.LogWarning(msg);
UnityEngine.Debug.Log(msg);
}

public static void Info(string msg)
{
UnityEngine.Debug.Log(msg);
}

public static void Error(Exception e)
public static void Warning(string msg)
{
UnityEngine.Debug.LogError(e.ToString());
UnityEngine.Debug.LogWarning(msg);
}

public static void Error(string msg)
{
UnityEngine.Debug.LogError(msg);
}

public static void Error(Exception e)
{
UnityEngine.Debug.LogException(e);
}

public static void Debug(string msg)
public static void Fatal(string msg)
{
UnityEngine.Debug.Log(msg);
UnityEngine.Debug.LogAssertion(msg);
}

public static void Trace(string message, params object[] args)
{
UnityEngine.Debug.LogFormat(message, args);
}

public static void Warning(string message, params object[] args)
{
UnityEngine.Debug.LogWarningFormat(message, args);
}

public static void Info(string message, params object[] args)
{
UnityEngine.Debug.LogFormat(message, args);
}

public static void Debug(string message, params object[] args)
{
UnityEngine.Debug.LogFormat(message, args);
}

public static void Error(string message, params object[] args)
{
UnityEngine.Debug.LogErrorFormat(message, args);
}

public static void Fatal(string message, params object[] args)
{
UnityEngine.Debug.LogAssertionFormat(message, args);
}

public static void Msg(object msg)
Expand Down
12 changes: 6 additions & 6 deletions Unity/Unity.sln
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Unity.Model", "Unity.Model.
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Unity.ThirdParty", "Unity.ThirdParty.csproj", "{E15BADD2-3A26-309A-AB0F-DC5B08044350}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Unity.Editor", "Unity.Editor.csproj", "{CD311104-1830-B119-81B6-5DBEE2467FFB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Unity.Hotfix", "Unity.Hotfix.csproj", "{1066F652-6A89-D1C4-9881-1A19DF7AB80E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Unity.Editor", "Unity.Editor.csproj", "{CD311104-1830-B119-81B6-5DBEE2467FFB}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -22,14 +22,14 @@ Global
{E15BADD2-3A26-309A-AB0F-DC5B08044350}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E15BADD2-3A26-309A-AB0F-DC5B08044350}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E15BADD2-3A26-309A-AB0F-DC5B08044350}.Release|Any CPU.Build.0 = Release|Any CPU
{CD311104-1830-B119-81B6-5DBEE2467FFB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CD311104-1830-B119-81B6-5DBEE2467FFB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CD311104-1830-B119-81B6-5DBEE2467FFB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CD311104-1830-B119-81B6-5DBEE2467FFB}.Release|Any CPU.Build.0 = Release|Any CPU
{1066F652-6A89-D1C4-9881-1A19DF7AB80E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1066F652-6A89-D1C4-9881-1A19DF7AB80E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1066F652-6A89-D1C4-9881-1A19DF7AB80E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1066F652-6A89-D1C4-9881-1A19DF7AB80E}.Release|Any CPU.Build.0 = Release|Any CPU
{CD311104-1830-B119-81B6-5DBEE2467FFB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CD311104-1830-B119-81B6-5DBEE2467FFB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CD311104-1830-B119-81B6-5DBEE2467FFB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CD311104-1830-B119-81B6-5DBEE2467FFB}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down

0 comments on commit f6d9574

Please sign in to comment.