using UnityEngine; public class LogPrintf { static LogLevel logLevel = LogLevel.LOG_LEVEL_ERROR; public static void SetLogLevel(LogLevel _loglevel) { logLevel = _loglevel; } public static void DebugLog(string msg) { _LogPrintf(msg, LogLevel.LOG_LEVEL_DEBUG); } public static void WarningLog(string msg) { _LogPrintf(msg, LogLevel.LOG_LEVEL_WARNING); } public static void ErrorLog(string msg) { _LogPrintf(msg, LogLevel.LOG_LEVEL_ERROR); } static void _LogPrintf(string msg, LogLevel _logLevel = LogLevel.LOG_LEVEL_DEBUG) { if (logLevel == (int)LogLevel.LOG_LEVEL_OFF) { return; } if (_logLevel <= logLevel) { if (_logLevel == LogLevel.LOG_LEVEL_DEBUG) { Debug.Log(msg); } if (_logLevel == LogLevel.LOG_LEVEL_WARNING) { Debug.LogWarning(msg); } if (_logLevel == LogLevel.LOG_LEVEL_ERROR) { Debug.LogError(msg); } } } } public enum LogLevel { LOG_LEVEL_OFF = 0, //0:关闭日志 LOG_LEVEL_DEBUG = 1, //1:Debug默认该级别 LOG_LEVEL_WARNING = 2, //2: warnning LOG_LEVEL_ERROR = 3 //3: error }