示例#1
0
 public void Log(string moduleName, object msg, Loglevels level = Loglevels.All)
 {
     if (_config.IsAllEnable)
     {
         LogModule.Log(moduleName, msg, level);
         if (!mModuleNames.Contains(moduleName))
         {
             mModuleNames.Add(moduleName);
         }
     }
 }
示例#2
0
        private void AddJob(Loglevels level, string div, string msg, Exception ex, LoggingContext context1, LoggingContext context2, LoggingContext context3)
        {
            if (this.Level > level)
            {
                return;
            }

#if !UNITY_WEBGL || UNITY_EDITOR
            if (this.isDisposed)
            {
                return;
            }
#endif

            var job = new LogJob
            {
                level      = level,
                division   = div,
                msg        = msg,
                ex         = ex,
                time       = DateTime.Now,
                threadId   = System.Threading.Thread.CurrentThread.ManagedThreadId,
                stackTrace = System.Environment.StackTrace,
                context1   = context1 != null?context1.Clone() : null,
                                 context2 = context2 != null?context2.Clone() : null,
                                                context3 = context3 != null?context3.Clone() : null
            };

#if !UNITY_WEBGL || UNITY_EDITOR
            this.jobs.Enqueue(job);
            try
            {
                this.newJobEvent.Set();
            }
            catch
            {
                try
                {
                    this.Output.Write(job.level, job.ToJson(sb));
                }
                catch
                { }
                return;
            }

            if (System.Threading.Interlocked.CompareExchange(ref this.threadCreated, 1, 0) == 0)
            {
                BestHTTP.PlatformSupport.Threading.ThreadedRunner.RunLongLiving(ThreadFunc);
            }
#else
            this.Output.Write(job.level, job.ToJson(sb));
#endif
        }
示例#3
0
        public void Write(Loglevels level, string logEntry)
        {
            switch (level)
            {
            case Loglevels.All:
            case Loglevels.Information:
                UnityEngine.Debug.Log(logEntry);
                break;

            case Loglevels.Warning:
                UnityEngine.Debug.LogWarning(logEntry);
                break;

            case Loglevels.Error:
            case Loglevels.Exception:
                UnityEngine.Debug.LogError(logEntry);
                break;
            }
        }
示例#4
0
        public void Write(Loglevels level, string logEntry)
        {
            if (this.fileStream != null && !string.IsNullOrEmpty(logEntry))
            {
                int count  = System.Text.Encoding.UTF8.GetByteCount(logEntry);
                var buffer = BufferPool.Get(count, true);

                try
                {
                    System.Text.Encoding.UTF8.GetBytes(logEntry, 0, logEntry.Length, buffer, 0);

                    this.fileStream.Write(buffer, 0, count);
                    this.fileStream.WriteLine();
                }
                finally
                {
                    BufferPool.Release(buffer);
                }

                this.fileStream.Flush();
            }
        }
示例#5
0
 /// <summary>
 /// Interaction with Charisma
 /// </summary>
 /// <param name="token">A valid play-though token.</param>
 /// <param name="loglevel">Log levels for advanced debugging.</param>
 public Charisma(string token, Loglevels loglevel)
 {
     Token = token;
     HTTPManager.Logger.Level = loglevel;
 }
示例#6
0
        public static void Log(string moduleName, object msg, Loglevels level = Loglevels.All)
        {
            try
            {
                if (LogManager.Instance.Config.Level <= level)
                {
                    string          stringformat = string.Empty;
                    Action <object> action       = UnityEngine.Debug.Log;
                    switch (level)
                    {
                    case Loglevels.All:
                        stringformat = FormatVerbose;
                        break;

                    case Loglevels.Information:
                        stringformat = FormatInfo;
                        break;

                    case Loglevels.Warning:
                        stringformat = FormatWarn;
                        break;

                    case Loglevels.Error:
                        stringformat = FormatErr;
                        action       = UnityEngine.Debug.LogError;
                        break;

                    case Loglevels.Exception:
                        stringformat = FormatEx;
                        break;

                    case Loglevels.None:

                        break;
                    }

                    StackTrace stackTrace = new StackTrace(true);
                    // FIXME call stack count!
                    var stackFrame = stackTrace.GetFrame(5);
#if UNITY_EDITOR
                    SunLog.AddStackFrame(stackFrame);
#endif
                    string stackInfo      = Path.GetFileName(stackFrame.GetFileName()) + ":" + stackFrame.GetMethod().Name + "() @ L" + stackFrame.GetFileLineNumber();
                    string timeInfo       = Time.frameCount + "F , " + DateTime.Now.Millisecond + "ms";
                    string stackInfoColor = "#990032";
                    string messageColor   = "#B803D0";

                    var    content    = string.Empty;
                    string logContent = string.Format("[{0}][{1}] -> {2}", timeInfo, stackInfo, msg);
                    content = string.Format(stringformat, level, logContent);


                    if (LogManager.Instance.Config.IsLogFileEnable)
                    {
                        CUDLR.Console.Log(content);
                        try
                        {
                            File.AppendAllText(GetFilePath(moduleName), "\n" + content + "\n\r", Encoding.UTF8);
                        }
                        catch (Exception e)
                        {
                            Debug.Log(string.Format("Write to log failed :{0}\t EXCEPTION:{1}", mFilePath, e.Message));
                        }
                    }

#if UNITY_EDITOR
                    string editorContent = string.Format("[{0}][<color={1}>{2}</color>] --> <color={3}>{4}</color>", timeInfo, stackInfoColor, stackInfo, messageColor, msg);
                    content = string.Format(stringformat, level, editorContent);
#endif
                    if (LogManager.Instance.Config.IsLogConsoleEnable)
                    {
                        action(content);
                    }
                }
            }
            catch (Exception e)
            {
                Debug.Log(string.Format("Failed :{0}\t EXCEPTION:{1}", mFilePath, e.Message));
            }
        }
示例#7
0
 private static void Log(string module, object msg, Loglevels level = Loglevels.All)
 {
     LogManager.Instance.Log(module, msg, level);
 }
示例#8
0
 /// <summary>
 /// Interaction with Charisma
 /// </summary>
 /// <param name="token">A valid play-though token.</param>
 /// <param name="loglevel">Log levels for advanced debugging.</param>
 public Playthrough(string token, Loglevels loglevel)
 {
     Token = token;
     HTTPManager.Logger.Level = loglevel;
 }