Skip to content

Commit

Permalink
Merge pull request #55 from onerain88/gitignore
Browse files Browse the repository at this point in the history
chore: Log code
  • Loading branch information
onerain88 authored Apr 30, 2020
2 parents cb6cca2 + 2b0a227 commit e6fa057
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -329,5 +329,5 @@ ASALocalRun/
# MFractors (Xamarin productivity tool) working folder
.mfractor/

!Common/Log/
!Common/Common/Log/
Doc/
19 changes: 19 additions & 0 deletions Common/Common/Log/LCLogLevel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace LeanCloud {
/// <summary>
/// 日志级别
/// </summary>
public enum LCLogLevel {
/// <summary>
/// 调试级别
/// </summary>
Debug,
/// <summary>
/// 警告级别
/// </summary>
Warn,
/// <summary>
/// 错误级别
/// </summary>
Error,
}
}
51 changes: 51 additions & 0 deletions Common/Common/Log/LCLogger.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using System;
using System.Text;

namespace LeanCloud {
/// <summary>
/// 日志类
/// </summary>
public static class LCLogger {
/// <summary>
/// 日志回调接口,方便开发者调试
/// </summary>
/// <value>The log delegate.</value>
public static Action<LCLogLevel, string> LogDelegate {
get; set;
}

public static void Debug(string log) {
LogDelegate?.Invoke(LCLogLevel.Debug, log);
}

public static void Debug(string format, params object[] args) {
LogDelegate?.Invoke(LCLogLevel.Debug, string.Format(format, args));
}

public static void Warn(string log) {
LogDelegate?.Invoke(LCLogLevel.Warn, log);
}

public static void Warn(string format, params object[] args) {
LogDelegate?.Invoke(LCLogLevel.Warn, string.Format(format, args));
}

public static void Error(string log) {
LogDelegate?.Invoke(LCLogLevel.Error, log);
}

public static void Error(string format, params object[] args) {
LogDelegate?.Invoke(LCLogLevel.Error, string.Format(format, args));
}

public static void Error(Exception e) {
StringBuilder sb = new StringBuilder();
sb.Append(e.GetType());
sb.Append("\n");
sb.Append(e.Message);
sb.Append("\n");
sb.Append(e.StackTrace);
Error(sb.ToString());
}
}
}

0 comments on commit e6fa057

Please sign in to comment.