Files
dingyuntian 11d88c146c feat(log-kit): 重构文件日志系统支持异步结构化日志
- 使用 ConcurrentQueue + 后台线程批量写入
- 新增 LogLevel、LogCategory、LogEntry、LogFormatter
- 新增 GameLog 业务日志入口
- 新增 LogSettingsProfiles 平台化配置
- 支持按 session 分文件、大小轮转与队列满时低优先级丢弃
2026-07-08 15:20:53 +08:00

144 lines
4.8 KiB
C#

namespace AibisDream.Kit
{
internal readonly struct LogSettingsProfile
{
public readonly bool Enabled;
public readonly bool EchoToConsole;
public readonly LogLevel MinLevel;
public readonly LogLevel ConsoleMinLevel;
public readonly int QueueCapacity;
public readonly int BatchSize;
public readonly int FlushIntervalMilliseconds;
public readonly int ShutdownDrainMilliseconds;
public readonly long MaxFileBytes;
public readonly long MaxTotalBytes;
public readonly int MaxSessionFiles;
public readonly bool IncludeWarningStackTrace;
public LogSettingsProfile(
bool enabled,
bool echoToConsole,
LogLevel minLevel,
LogLevel consoleMinLevel,
int queueCapacity,
int batchSize,
int flushIntervalMilliseconds,
int shutdownDrainMilliseconds,
long maxFileBytes,
long maxTotalBytes,
int maxSessionFiles,
bool includeWarningStackTrace)
{
Enabled = enabled;
EchoToConsole = echoToConsole;
MinLevel = minLevel;
ConsoleMinLevel = consoleMinLevel;
QueueCapacity = queueCapacity;
BatchSize = batchSize;
FlushIntervalMilliseconds = flushIntervalMilliseconds;
ShutdownDrainMilliseconds = shutdownDrainMilliseconds;
MaxFileBytes = maxFileBytes;
MaxTotalBytes = maxTotalBytes;
MaxSessionFiles = maxSessionFiles;
IncludeWarningStackTrace = includeWarningStackTrace;
}
}
internal static class LogSettingsProfiles
{
private const long Megabyte = 1024L * 1024L;
public static LogSettingsProfile Current
{
get
{
#if UNITY_EDITOR
return Editor;
#elif UNITY_ANDROID
#if DEVELOPMENT_BUILD
return AndroidDevelopment;
#else
return AndroidRelease;
#endif
#else
#if DEVELOPMENT_BUILD
return StandaloneDevelopment;
#else
return StandaloneRelease;
#endif
#endif
}
}
private static LogSettingsProfile Editor => new LogSettingsProfile(
enabled: false,
echoToConsole: true,
minLevel: LogLevel.Info,
consoleMinLevel: LogLevel.Debug,
queueCapacity: 2048,
batchSize: 128,
flushIntervalMilliseconds: 1000,
shutdownDrainMilliseconds: 1000,
maxFileBytes: 10L * Megabyte,
maxTotalBytes: 100L * Megabyte,
maxSessionFiles: 20,
includeWarningStackTrace: false);
private static LogSettingsProfile AndroidDevelopment => new LogSettingsProfile(
enabled: true,
echoToConsole: true,
minLevel: LogLevel.Info,
consoleMinLevel: LogLevel.Debug,
queueCapacity: 1024,
batchSize: 64,
flushIntervalMilliseconds: 1500,
shutdownDrainMilliseconds: 1000,
maxFileBytes: 5L * Megabyte,
maxTotalBytes: 30L * Megabyte,
maxSessionFiles: 6,
includeWarningStackTrace: false);
private static LogSettingsProfile AndroidRelease => new LogSettingsProfile(
enabled: true,
echoToConsole: true,
minLevel: LogLevel.Warning,
consoleMinLevel: LogLevel.Warning,
queueCapacity: 1024,
batchSize: 64,
flushIntervalMilliseconds: 1500,
shutdownDrainMilliseconds: 1000,
maxFileBytes: 5L * Megabyte,
maxTotalBytes: 30L * Megabyte,
maxSessionFiles: 6,
includeWarningStackTrace: false);
private static LogSettingsProfile StandaloneDevelopment => new LogSettingsProfile(
enabled: true,
echoToConsole: true,
minLevel: LogLevel.Info,
consoleMinLevel: LogLevel.Debug,
queueCapacity: 2048,
batchSize: 128,
flushIntervalMilliseconds: 1000,
shutdownDrainMilliseconds: 1000,
maxFileBytes: 10L * Megabyte,
maxTotalBytes: 100L * Megabyte,
maxSessionFiles: 20,
includeWarningStackTrace: false);
private static LogSettingsProfile StandaloneRelease => new LogSettingsProfile(
enabled: true,
echoToConsole: true,
minLevel: LogLevel.Info,
consoleMinLevel: LogLevel.Info,
queueCapacity: 2048,
batchSize: 128,
flushIntervalMilliseconds: 1000,
shutdownDrainMilliseconds: 1000,
maxFileBytes: 10L * Megabyte,
maxTotalBytes: 100L * Megabyte,
maxSessionFiles: 20,
includeWarningStackTrace: false);
}
}