/// <summary> /// Converts a given log element into a piece of gui content to be displayed /// </summary> GUIContent GetLogLineGUIContent(UberLogger.LogInfo log, bool showTimes, bool showChannels) { var showMessage = log.Message; //Make all messages single line showMessage = showMessage.Replace(UberLogger.Logger.UnityInternalNewLine, " "); // Format the message as follows: // [channel] 0.000 : message <-- Both channel and time shown // 0.000 : message <-- Time shown, channel hidden // [channel] : message <-- Channel shown, time hidden // message <-- Both channel and time hidden var showChannel = showChannels && !string.IsNullOrEmpty(log.Channel); var channelMessage = showChannel ? string.Format("[{0}]", log.Channel) : ""; var channelTimeSeparator = (showChannel && showTimes) ? " " : ""; var timeMessage = showTimes ? string.Format("{0}", log.GetRelativeTimeStampAsString()) : ""; var prefixMessageSeparator = (showChannel || showTimes) ? " : " : ""; showMessage = string.Format("{0}{1}{2}{3}{4}", channelMessage, channelTimeSeparator, timeMessage, prefixMessageSeparator, showMessage ); var content = new GUIContent(showMessage); return(content); }
/// <summary> /// Converts the entire message log to a multiline string /// </summary> public string ExtractLogListToString() { string result = ""; foreach (CountedLog log in RenderLogs) { UberLogger.LogInfo logInfo = log.Log; result += logInfo.GetRelativeTimeStampAsString() + ": " + logInfo.Severity + ": " + logInfo.Message + "\n"; } return(result); }
/// <summary> /// Converts a given log element into a piece of gui content to be displayed /// </summary> GUIContent GetLogLineGUIContent(UberLogger.LogInfo log, bool showTimes) { var showMessage = log.Message; //Make all messages single line showMessage = showMessage.Replace(UberLogger.Logger.UnityInternalNewLine, " "); if (showTimes) { showMessage = log.GetRelativeTimeStampAsString() + ": " + showMessage; } var content = new GUIContent(showMessage, GetIconForLog(log)); return(content); }
/// <summary> /// Converts a given log element into a piece of gui content to be displayed /// </summary> GUIContent GetLogLineGUIContent(UberLogger.LogInfo log, bool showTimes) { var showMessage = log.Message; //Make all messages single line showMessage = showMessage.Replace(System.Environment.NewLine, " "); if (showTimes) { showMessage = log.GetTimeStampAsString() + ": " + showMessage; } var content = new GUIContent(showMessage, GetIconForLog(log)); return(content); }
public CountedLog(UberLogger.LogInfo log, Int32 count) { Log = log; Count = count; }
static void UnityLogInternal(string unityMessage, string unityCallStack, UnityEngine.LogType logType) { //Make sure only one thread can do this at a time. //This should mean that most backends don't have to worry about thread safety (unless they do complicated stuff) lock (Loggers) { //Prevent nasty recursion problems if (!AlreadyLogging) { try { AlreadyLogging = true; var callstack = new List <LogStackFrame>(); LogStackFrame originatingSourceLocation; var unityOnly = GetCallstack(ref callstack, out originatingSourceLocation); if (unityOnly) { return; } //If we have no useful callstack, fall back to parsing Unity's callstack if (callstack.Count == 0) { callstack = GetCallstackFromUnityLog(unityCallStack, out originatingSourceLocation); } LogSeverity severity; switch (logType) { case UnityEngine.LogType.Error: severity = LogSeverity.Error; break; case UnityEngine.LogType.Assert: severity = LogSeverity.Error; break; case UnityEngine.LogType.Exception: severity = LogSeverity.Error; break; case UnityEngine.LogType.Warning: severity = LogSeverity.Warning; break; default: severity = LogSeverity.Message; break; } string filename = ""; int lineNumber = 0; //Finally, parse the error message so we can get basic file and line information if (ExtractInfoFromUnityMessage(unityMessage, ref filename, ref lineNumber)) { callstack.Insert(0, new LogStackFrame(unityMessage, filename, lineNumber)); } var logInfo = new LogInfo(null, "", severity, callstack, originatingSourceLocation, unityMessage); //Add this message to our history RecentMessages.AddLast(logInfo); //Make sure our history doesn't get too big TrimOldMessages(); //Delete any dead loggers and pump them with the new log Loggers.RemoveAll(l => l == null); Loggers.ForEach(l => l.Log(logInfo)); } finally { AlreadyLogging = false; } } } }