/// <summary> /// Returns the last Message of the saved message queue /// </summary> /// <returns>PostboxLogMessage object or NULL if empty</returns> public PostboxLogMessage GetMessage() { PostboxLogMessage output = null; if (unreadedMessages.Count > 0) { output = unreadedMessages.Dequeue(); } return(output); }
/// <summary> /// Add current Message to Textbox-Output. /// </summary> /// <param name="output">LogMessage from Logbook</param> /// <param name="clamp">Character count for max dawed text.</param> private void PrintInTextbox(PostboxLogMessage output, int clamp) { if (Textbox) { // Prepair Textbox string TextOutputString = output != null ? Textbox.text + output.Print() + "\r\n" : Textbox.text; TextOutputString = TextOutputString.Substring((TextOutputString.Length - clamp < 0 ? 0 : TextOutputString.Length - clamp)); // Show Text in Box switch (output.NotificationLevel) { case PostboxLogbook.NotificationType.Notification: if (ShowNotificationInTextbox && outputInTextfield) { Textbox.text = TextOutputString; } break; case PostboxLogbook.NotificationType.Warning: if (ShowWarningInTextbox && outputInTextfield) { Textbox.text = TextOutputString; } break; case PostboxLogbook.NotificationType.Error: if (ShowErrorInTextbox && outputInTextfield) { Textbox.text = TextOutputString; } break; case PostboxLogbook.NotificationType.APICalls: if (ShowAPICallsInTextbox && outputInTextfield) { Textbox.text = TextOutputString; } break; default: break; } } else { Debug.LogWarning("You have to assign a Textbox to use Output in Textfield."); } }
/// <summary> /// Show the next bufferd Message of the PostboxLogbook /// </summary> public void PrintNextMessage() { output = PostboxLogbook.Instance.GetMessage(); if (output == null) { return; } // Print in Textbox if (outputInTextfield) { PrintInTextbox(output, TextClamp); } // Print in Debug-Log if (outputInDebugLog) { PrintInDebuglog(output); } }
/// <summary> /// Logging an Message /// </summary> /// <param name="text">Notification Text</param> /// <param name="level">Level of Notification (Notification, Warning, Error, APICalls)</param> public void Log(string text, NotificationType level) { if (!useFileSystem) { return; } DateTime date = DateTime.Now; if (CheckDirectory(filesystemPath)) { using (System.IO.StreamWriter file = new System.IO.StreamWriter(@filesystemPath + String.Format("logfile-{0}-{1}-{2}-{3}-{4}.txt", appId, session_identifier, date.Year, date.Month, date.Day), true)) { PostboxLogMessage LogMessage = new PostboxLogMessage(text, date, level); unreadedMessages.Enqueue(LogMessage); file.WriteLine(String.Format("{0} - [{1}] {2}", LogMessage.Time, LogMessage.NotificationLevel, LogMessage.Message)); } } }
/// <summary> /// Show LogMessages in Editor Console Window. /// The Level NotificationType of the Message Objekt effects on the type of output. /// (notification, warning, error) /// </summary> /// <param name="output">PostboxLogMessage Object</param> private void PrintInDebuglog(PostboxLogMessage output) { switch (output.NotificationLevel) { case PostboxLogbook.NotificationType.Notification: if (ShowNotificationInDebug) { Debug.Log(output.Print()); } break; case PostboxLogbook.NotificationType.Warning: if (ShowWarningInDebug) { Debug.LogWarning(output.Print()); } break; case PostboxLogbook.NotificationType.Error: if (ShowErrorInDebug) { Debug.LogError(output.Print()); } break; case PostboxLogbook.NotificationType.APICalls: if (ShowAPICallsInDebug) { Debug.Log(output.Print()); } break; default: break; } }