PDLogConfig class

日志配置类,用于全局控制日志的输出行为与文件写入策略。

使用 PDLog.configure 设置全局配置,或通过 PDLog.updateConfigure 更新部分配置。

核心功能

控制台输出控制

  • enabled:是否启用日志输出;
  • minLevel:最小输出级别(低于该级别的日志会被忽略);
  • defaultTag:默认标签,未指定标签时使用;
  • useConsole:是否在 Dart 控制台打印;
  • showTimestamp:是否在输出中加入时间戳;
  • showCaller:是否显示调用者函数信息;
  • ansiEnabled:是否启用 ANSI 颜色(控制台输出)。

本地文件写入(Dart 管理)

日志滚动策略

文件事件监听

敏感数据掩码

  • logMaskingConfig:敏感数据掩码配置,支持字段名匹配和正则匹配脱敏。

示例

PDLog.configure(const PDLogConfig(
  minLevel: LogLevel.debug,
  defaultTag: 'MyApp',
  fileLoggingEnabled: true,
  fileLoggingMinLevel: LogLevel.info,
));

Constructors

PDLogConfig({bool enabled = true, LogLevel minLevel = LogLevel.verbose, String? defaultTag, bool useConsole = true, bool showTimestamp = false, bool ansiEnabled = false, bool showCaller = false, bool fileLoggingEnabled = false, int fileLoggingFlushIntervalMs = 2000, int fileLoggingMaxBufferEntries = 100, int fileLoggingMaxBufferBytes = 64 * 1024, Map<LogLevel, LogStyleConfig> logStyles = kDefaultLogStyles, LogLevel fileLoggingMinLevel = LogLevel.info, LogRetentionStrategy logRetentionStrategy = LogRetentionStrategy.none, int logRetentionCount = 0, int fileEventDedupeWindowMs = 500, int mobileWatchPollingIntervalMs = 2000, LogMaskingConfig logMaskingConfig = const LogMaskingConfig()})
创建日志配置实例。
const

Properties

ansiEnabled bool
是否启用 ANSI 颜色包裹(控制台/平台输出)。
final
defaultTag String?
默认标签。
final
enabled bool
是否启用日志输出。
final
fileEventDedupeWindowMs int
文件事件去重窗口(毫秒)。
final
fileLoggingEnabled bool
是否启用本地文件写入。
final
fileLoggingFlushIntervalMs int
定时刷新间隔(毫秒)。
final
fileLoggingMaxBufferBytes int
缓冲最大字节数。
final
fileLoggingMaxBufferEntries int
缓冲最大条目数。
final
fileLoggingMinLevel LogLevel
写入文件的最小级别阈值。
final
hashCode int
The hash code for this object.
no setterinherited
logMaskingConfig LogMaskingConfig
敏感数据掩码配置。
final
logRetentionCount int
滚动保留的数量。
final
logRetentionStrategy LogRetentionStrategy
日志滚动策略。
final
logStyles Map<LogLevel, LogStyleConfig>
日志颜色样式配置(按级别设置前景色/背景色/样式)。
final
minLevel LogLevel
最小输出级别。
final
mobileWatchPollingIntervalMs int
移动端文件轮询间隔(毫秒)。
final
nativeFileLoggingEnabled bool
是否启用本地文件写入。
no setter
nativeFileLoggingFlushIntervalMs int
定时刷新间隔(毫秒)。
no setter
nativeFileLoggingMaxBufferBytes int
缓冲最大字节数。
no setter
nativeFileLoggingMaxBufferEntries int
缓冲最大条目数。
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
showCaller bool
是否在日志中显示调用者函数信息。
final
showTimestamp bool
是否在日志输出中显示时间戳。
final
useConsole bool
是否在 Dart 控制台打印日志。
final

Methods

copyWith({bool? enabled, LogLevel? minLevel, String? defaultTag, bool? useConsole, bool? showTimestamp, bool? ansiEnabled, bool? showCaller, bool? fileLoggingEnabled, int? fileLoggingFlushIntervalMs, int? fileLoggingMaxBufferEntries, int? fileLoggingMaxBufferBytes, Map<LogLevel, LogStyleConfig>? logStyles, LogLevel? fileLoggingMinLevel, LogRetentionStrategy? logRetentionStrategy, int? logRetentionCount, int? fileEventDedupeWindowMs, int? mobileWatchPollingIntervalMs, LogMaskingConfig? logMaskingConfig, bool? nativeFileLoggingEnabled, int? nativeFileLoggingFlushIntervalMs, int? nativeFileLoggingMaxBufferEntries, int? nativeFileLoggingMaxBufferBytes}) PDLogConfig
复制当前配置并覆盖部分字段。
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited