public static void SetLogLevel(string CategoryName, MDLogLevel LogLevel) { LogProperties[CategoryName] = new MDLogProperties(LogLevel); }
/// <summary> /// Logs the message (supports formatting) in accordance with the LogProperties set for the specified log category /// </summary> /// <param name="CategoryName">The category to log in</param> /// <param name="LogLevel">The log level</param> /// <param name="Message">The message</param> /// <param name="Args">Arguments</param> public static void Log(string CategoryName, MDLogLevel LogLevel, string Message, params object[] Args) { // TODO - Get calling method's name automatically: https://stackoverflow.com/a/5443690 bool LogFile = true; bool LogConsole = true; MDConfiguration Config = MDStatics.GetGameInstance().GetConfiguration(); if (Config.HasValue(MDConfiguration.ConfigurationSections.Logging, CategoryName)) { MDLogLevel ConfigLogLevel = Config.GetEnum <MDLogLevel>(MDConfiguration.ConfigurationSections.Logging, CategoryName, MDLogLevel.Trace); LogFile = ConfigLogLevel <= LogLevel || LogLevel == MDLogLevel.Force; LogConsole = ConfigLogLevel <= LogLevel || LogLevel == MDLogLevel.Force; } else if (LogProperties.ContainsKey(CategoryName)) { MDLogProperties LogProps = LogProperties[CategoryName]; LogFile = LogProps.FileLogLevel <= LogLevel || LogLevel == MDLogLevel.Force; LogConsole = LogProps.ConsoleLogLevel <= LogLevel || LogLevel == MDLogLevel.Force; } else { MDLogLevel DefaultLogLevel = Config.GetEnum <MDLogLevel>(MDConfiguration.ConfigurationSections.Logging, MDConfiguration.DEFAULT_LOG_LEVEL, MDLogLevel.Trace); LogFile = DefaultLogLevel <= LogLevel || LogLevel == MDLogLevel.Force; LogConsole = DefaultLogLevel <= LogLevel || LogLevel == MDLogLevel.Force; } if (LogFile || LogConsole) { int PeerID = MDStatics.GetPeerId(); MDNetMode NetMode = MDStatics.GetNetMode(); string ClientID = "PEER " + PeerID; if (NetMode == MDNetMode.Standalone) { ClientID = "STANDALONE"; } else if (NetMode == MDNetMode.Server) { ClientID = "SERVER"; } string FullMessage = "[" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "]" + "[" + (Godot.Engine.GetIdleFrames() % 1000).ToString("D3") + "]" + "[" + ClientID + "] " + "[" + CategoryName + "::" + LogLevel + "] " + string.Format(Message, Args); if (LogFile) { LogToFile(FullMessage); } if (LogConsole) { LogToConsole(FullMessage); } } if (LogLevel == MDLogLevel.Fatal) { DebugBreak(); } }
/// <summary> /// Adds log category properties to be referenced when making logs of that type /// </summary> /// <param name="CategoryName">The category name</param> /// <param name="LogProps">The logging properties</param> public static void AddLogCategoryProperties(string CategoryName, MDLogProperties LogProps) { LogProperties[CategoryName] = LogProps; }