### Hierarchical Logging Output Example Source: https://pub.dev/documentation/logging/latest/index.html Shows the expected output from the hierarchical logging configuration, illustrating which messages are logged and by which listeners. ```text [LOG1][FINE+] LOG_01 FINE (√√) [ROOT][WARNING+] LOG_01 FINE (√√) [LOG1][FINE+] LOG_01 WARNING (√) [ROOT][WARNING+] LOG_01 WARNING (√) [LOG2][WARNING+] LOG_02 WARNING (√√) [ROOT][WARNING+] LOG_02 WARNING (√√) ``` -------------------------------- ### Initialize Logging with Print Handler Source: https://pub.dev/documentation/logging/latest/index.html Configures the root logger to log all messages (Level.ALL) to the console using `print`. This is a basic setup for debugging. ```dart Logger.root.level = Level.ALL; Logger.root.onRecord.listen((record) { print('${record.level.name}: ${record.time}: ${record.message}'); }); ``` -------------------------------- ### Create or Find Logger by Name Source: https://pub.dev/documentation/logging/latest/logging/Logger/Logger.html Use this factory constructor to get a Logger instance. It ensures that a single Logger object is associated with a given name, returning the existing instance if one is already created. ```dart factory Logger(String name) => _loggers.putIfAbsent(name, () => Logger._named(name)); ``` -------------------------------- ### Get All Attached Loggers Source: https://pub.dev/documentation/logging/latest/logging/Logger/attachedLoggers.html Retrieves all loggers that are currently attached to the system. Loggers created with Logger.detached are not included in this collection. ```dart static Iterable get attachedLoggers => _loggers.values; ``` -------------------------------- ### Get Logger Level Source: https://pub.dev/documentation/logging/latest/logging/Logger/level.html Retrieves the effective logging level for this logger, considering parent loggers if hierarchical logging is enabled. ```APIDOC ## get level ### Description Effective level considering the levels established in this logger's parents (when hierarchicalLoggingEnabled is true). ### Method GET (conceptual) ### Endpoint Logger.level ### Response #### Success Response (200) - **level** (Level) - The effective logging level. ``` -------------------------------- ### Get Logger Level Source: https://pub.dev/documentation/logging/latest/logging/Logger/level.html Retrieves the effective logging level. This considers parent loggers if hierarchical logging is enabled. If not, it returns the root logger's level. ```dart Level get level { Level effectiveLevel; if (parent == null) { // We're either the root logger or a detached logger. Return our own // level. effectiveLevel = _level!; } else if (!hierarchicalLoggingEnabled) { effectiveLevel = root._level!; } else { effectiveLevel = _level ?? parent!.level; } // ignore: unnecessary_null_comparison assert(effectiveLevel != null); return effectiveLevel; } ``` -------------------------------- ### fine method Source: https://pub.dev/documentation/logging/latest/logging/Logger/fine.html Logs a message at level Level.FINE. See log for information on how non-String `message` arguments are handled. ```APIDOC ## fine(Object? message, [Object? error, StackTrace? stackTrace]) ### Description Log message at level Level.FINE. See log for information on how non-String `message` arguments are handled. ### Parameters #### Path Parameters - **message** (Object?) - Optional - The message to log. - **error** (Object?) - Optional - An optional error object to log. - **stackTrace** (StackTrace?) - Optional - An optional stack trace to log. ### Implementation ```dart void fine(Object? message, [Object? error, StackTrace? stackTrace]) => log(Level.FINE, message, error, stackTrace); ``` ``` -------------------------------- ### config method Source: https://pub.dev/documentation/logging/latest/logging/Logger/config.html Logs a message at the Level.CONFIG. Non-String message arguments are handled as described in the log documentation. ```APIDOC ## config ### Description Logs a message at the Level.CONFIG. Non-String message arguments are handled as described in the log documentation. ### Method Signature `void config(Object? message, [Object? error, StackTrace? stackTrace])` ### Parameters - **message** (Object?) - Optional - The message to log. - **error** (Object?) - Optional - An error object to log. - **stackTrace** (StackTrace?) - Optional - A stack trace to log. ### Implementation ```dart void config(Object? message, [Object? error, StackTrace? stackTrace]) => log(Level.CONFIG, message, error, stackTrace); ``` ``` -------------------------------- ### Logger Constructors Source: https://pub.dev/documentation/logging/latest/logging/Logger-class.html Provides methods for creating Logger instances. ```APIDOC ## Logger(String name) ### Description Create or find a Logger by name. ### Method Constructor ``` ```APIDOC ## Logger.detached(String name) ### Description Creates a new detached Logger. ### Method Factory Constructor ``` -------------------------------- ### Level Methods Source: https://pub.dev/documentation/logging/latest/logging/Level-class.html Methods available for Level instances. ```APIDOC ## Methods ### compareTo(Level other) → int *Description*: Compares this object to another object. ### noSuchMethod(Invocation invocation) → dynamic *Description*: Invoked when a nonexistent method or property is accessed. ### toString() → String *Description*: A string representation of this object. ``` -------------------------------- ### Logger Constructor Source: https://pub.dev/documentation/logging/latest/logging/Logger/Logger.html Creates or retrieves a Logger instance by its name. Subsequent calls with the same name will return the same instance. ```APIDOC ## Logger Constructor ### Description Creates or finds a Logger by name. Calling `Logger(name)` will return the same instance whenever it is called with the same string name. Loggers created with this constructor are retained indefinitely and available through `attachedLoggers`. ### Signature ```dart Logger(String name) ``` ### Parameters #### Path Parameters - **name** (String) - Required - The name of the logger to create or retrieve. ``` -------------------------------- ### Level Constructor Source: https://pub.dev/documentation/logging/latest/logging/Level-class.html Creates a new Level instance with a given name and integer value. ```APIDOC ## Level(String name, int value) ### Description Constructs a new Level with the specified name and value. ### Parameters - **name** (String) - The name of the logging level. - **value** (int) - The integer value representing the level's priority. ``` -------------------------------- ### LogRecord Constructor Source: https://pub.dev/documentation/logging/latest/logging/LogRecord/LogRecord.html The LogRecord constructor initializes a new log record with essential information such as level, message, and logger name. Optional parameters like error, stack trace, zone, and object can also be provided. ```APIDOC ## LogRecord Constructor ### Description Initializes a new log record. ### Parameters - **level** (Level) - Required - The logging level. - **message** (String) - Required - The log message. - **loggerName** (String) - Required - The name of the logger. - **error** (Object?) - Optional - An error object associated with the log. - **stackTrace** (StackTrace?) - Optional - The stack trace associated with the log. - **zone** (Zone?) - Optional - The zone associated with the log. - **object** (Object?) - Optional - An arbitrary object associated with the log. ### Implementation Details - `time` is automatically set to the current time (`DateTime.now()`). - `sequenceNumber` is automatically assigned using an internal counter (`LogRecord._nextNumber++`). ``` -------------------------------- ### Logger config Method Implementation Source: https://pub.dev/documentation/logging/latest/logging/Logger/config.html This is the implementation of the config method, which calls the general log method with Level.CONFIG. ```dart void config(Object? message, [Object? error, StackTrace? stackTrace]) => log(Level.CONFIG, message, error, stackTrace); ``` -------------------------------- ### Logger.info Implementation Source: https://pub.dev/documentation/logging/latest/logging/Logger/info.html This is the implementation of the info method, which calls the internal log function with Level.INFO. ```dart void info(Object? message, [Object? error, StackTrace? stackTrace]) => log(Level.INFO, message, error, stackTrace); ``` -------------------------------- ### Logging Properties Source: https://pub.dev/documentation/logging/latest/logging Properties to configure hierarchical logging and stack trace recording. ```APIDOC ## Properties - `hierarchicalLoggingEnabled` (bool): Whether to allow fine-grain logging and configuration of loggers in a hierarchy. (getter/setter pair) - `recordStackTraceAtLevel` (Level): Automatically record stack traces for any message of this level or above. (getter/setter pair) ``` -------------------------------- ### LogRecord Implementation Source: https://pub.dev/documentation/logging/latest/logging/LogRecord/LogRecord.html The implementation of the LogRecord constructor initializes time and sequenceNumber, and assigns provided parameters. ```dart LogRecord(this.level, this.message, this.loggerName, [this.error, this.stackTrace, this.zone, this.object]) : time = DateTime.now(), sequenceNumber = LogRecord._nextNumber++; ``` -------------------------------- ### finer method Source: https://pub.dev/documentation/logging/latest/logging/Logger/finer.html Logs a message at Level.FINER. See log for information on how non-String `message` arguments are handled. ```APIDOC ## finer method ### Description Log message at level Level.FINER. See log for information on how non-String `message` arguments are handled. ### Signature ```dart void finer(Object? message, [Object? error, StackTrace? stackTrace]) ``` ### Parameters * **message** (Object?) - The message to log. Can be any object. * **error** (Object?) - An optional error object to log. * **stackTrace** (StackTrace?) - An optional stack trace to log. ### Implementation ```dart void finer(Object? message, [Object? error, StackTrace? stackTrace]) => log(Level.FINER, message, error, stackTrace); ``` ``` -------------------------------- ### Listen for Log Level Changes Source: https://pub.dev/documentation/logging/latest/index.html Sets up a listener for changes in the root logger's level. This is useful for dynamically adjusting logging verbosity. ```dart Logger.root.onLevelChanged.listen((level) { print('The new log level is $level'); }); ``` -------------------------------- ### Logger.fine Method Implementation Source: https://pub.dev/documentation/logging/latest/logging/Logger/fine.html This is the implementation of the fine method, which calls the internal log method with Level.FINE. ```dart void fine(Object? message, [Object? error, StackTrace? stackTrace]) => log(Level.FINE, message, error, stackTrace); ``` -------------------------------- ### LogRecord Constructor Signature Source: https://pub.dev/documentation/logging/latest/logging/LogRecord/LogRecord.html Defines the parameters for creating a LogRecord, including level, message, logger name, and optional error, stack trace, zone, and object. ```dart LogRecord( 1. Level level, 2. String message, 3. String loggerName, [ 4. Object? error, 5. StackTrace? stackTrace, 6. Zone? zone, 7. Object? object, ]) ``` -------------------------------- ### Predefined Level Constants Source: https://pub.dev/documentation/logging/latest/logging/Level-class.html Constants representing standard logging levels. ```APIDOC ## Constants ### ALL → const Level *Description*: Special key to turn on logging for all levels (value = 0). ### CONFIG → const Level *Description*: Key for static configuration messages (value = 700). ### FINE → const Level *Description*: Key for tracing information (value = 500). ### FINER → const Level *Description*: Key for fairly detailed tracing (value = 400). ### FINEST → const Level *Description*: Key for highly detailed tracing (value = 300). ### INFO → const Level *Description*: Key for informational messages (value = 800). ### LEVELS → const List *Description*: A list of all predefined Level constants. ### OFF → const Level *Description*: Special key to turn off all logging (value = 2000). ### SEVERE → const Level *Description*: Key for serious failures (value = 1000). ### SHOUT → const Level *Description*: Key for extra debugging loudness (value = 1200). ### WARNING → const Level *Description*: Key for potential problems (value = 900). ``` -------------------------------- ### Level Constructor Source: https://pub.dev/documentation/logging/latest/logging/Level/Level.html The Level constructor initializes a new log level with a name and a numerical value. ```APIDOC ## Level Constructor ### Description Initializes a new log level with a name and a numerical value. ### Signature ```dart const Level(String name, int value) ``` ### Parameters - **name** (String) - The name of the log level (e.g., "INFO", "WARNING"). - **value** (int) - The numerical value associated with the log level. ``` -------------------------------- ### LogRecord Methods Source: https://pub.dev/documentation/logging/latest/logging/LogRecord-class.html Available methods for the LogRecord class. ```APIDOC ## Methods - **noSuchMethod(Invocation invocation) → dynamic** Invoked when a nonexistent method or property is accessed. Inherited. - **toString() → String** A string representation of this object. Overrides the default implementation. ``` -------------------------------- ### Configure Hierarchical Logging Source: https://pub.dev/documentation/logging/latest/index.html Enables hierarchical logging and configures different levels for the root logger and specific loggers. Demonstrates how log messages are filtered and routed based on logger levels and listeners. ```dart hierarchicalLoggingEnabled = true; Logger.root.level = Level.WARNING; Logger.root.onRecord.listen((record) { print('[ROOT][WARNING+] ${record.message}'); }); final log1 = Logger('FINE+'); log1.level = Level.FINE; log1.onRecord.listen((record) { print('[LOG1][FINE+] ${record.message}'); }); // log2 inherits LEVEL value of WARNING from `Logger.root` final log2 = Logger('WARNING+'); log2.onRecord.listen((record) { print('[LOG2][WARNING+] ${record.message}'); }); // Will NOT print because FINER is too low level for `Logger.root`. log1.finer('LOG_01 FINER (X)'); // Will print twice ([LOG1] & [ROOT]) log1.fine('LOG_01 FINE (√√)'); // Will print ONCE because `log1` only uses root listener. log1.warning('LOG_01 WARNING (√)'); // Will never print because FINE is too low level. log2.fine('LOG_02 FINE (X)'); // Will print twice ([LOG2] & [ROOT]) because warning is sufficient for all // loggers' levels. log2.warning('LOG_02 WARNING (√√)'); // Will never print because `info` is filtered by `Logger.root.level` of // `Level.WARNING`. log2.info('INFO (X)'); ``` -------------------------------- ### info method Source: https://pub.dev/documentation/logging/latest/logging/Logger/info.html Logs a message at Level.INFO. Handles non-String messages as described in the log documentation. ```APIDOC ## info ### Description Logs a message at Level.INFO. See log for information on how non-String `message` arguments are handled. ### Method Signature `void info(Object? message, [Object? error, StackTrace? stackTrace])` ### Parameters #### message - **message** (Object?) - The message to log. #### error - **error** (Object?) - An optional error object to log. #### stackTrace - **stackTrace** (StackTrace?) - An optional stack trace to log. ### Implementation ```dart void info(Object? message, [Object? error, StackTrace? stackTrace]) => log(Level.INFO, message, error, stackTrace); ``` ``` -------------------------------- ### Define INFO Constant Source: https://pub.dev/documentation/logging/latest/logging/Level/INFO-constant.html This snippet shows the implementation of the static const Level INFO, used for informational messages. ```dart static const Level INFO = Level('INFO', 800); ``` -------------------------------- ### LogRecord Properties Source: https://pub.dev/documentation/logging/latest/logging/LogRecord-class.html Details about the properties available on a LogRecord instance. ```APIDOC ## Properties - **error** (Object?) Associated error (if any) when recording errors messages. Read-only. - **hashCode** (int) The hash code for this object. Inherited. - **level** (Level) The logging level for this record. Read-only. - **loggerName** (String) Logger where this record is stored. Read-only. - **message** (String) The log message. Read-only. - **object** (Object?) Non-string message passed to Logger. Read-only. - **runtimeType** (Type) A representation of the runtime type of the object. Inherited. - **sequenceNumber** (int) Unique sequence number greater than all log records created before it. Read-only. - **stackTrace** (StackTrace?) Associated stackTrace (if any) when recording errors messages. Read-only. - **time** (DateTime) Time when this record was created. Read-only. - **zone** (Zone?) Zone of the calling code which resulted in this LogRecord. Read-only. ``` -------------------------------- ### Define Default Logging Level Source: https://pub.dev/documentation/logging/latest/logging/defaultLevel-constant.html Sets the default logging level to INFO. This constant is used when no specific level is provided. ```javascript const defaultLevel = Level.INFO; ``` -------------------------------- ### Level Properties Source: https://pub.dev/documentation/logging/latest/logging/Level-class.html Properties available for Level instances. ```APIDOC ## Properties ### hashCode → int *Description*: The hash code for this object. ### name → String *Description*: The name of the logging level. ### runtimeType → Type *Description*: A representation of the runtime type of the object. ### value → int *Description*: Unique value for this level. Used to order levels, so filtering can exclude messages whose level is under certain value. ``` -------------------------------- ### Create a Named Logger Source: https://pub.dev/documentation/logging/latest/index.html Instantiates a `Logger` with a specific name. Using unique names helps identify the source of log messages. ```dart final log = Logger('MyClassName'); ``` -------------------------------- ### LogRecord toString Implementation Source: https://pub.dev/documentation/logging/latest/logging/LogRecord/toString.html This implementation of the toString method formats a LogRecord into a human-readable string. It includes the log level name, the logger's name, and the log message. This is useful for debugging and logging purposes. ```dart @override String toString() => '[${level.name}] $loggerName: $message'; ``` -------------------------------- ### Define Logging Level Constructor Source: https://pub.dev/documentation/logging/latest/logging/Level/Level.html Use this constructor to create a new logging level, assigning it a name and an integer value. This is the primary way to define custom logging levels. ```dart const Level(this.name, this.value); ``` -------------------------------- ### warning Source: https://pub.dev/documentation/logging/latest/logging/Logger/warning.html Logs a message at Level.WARNING. Handles non-String messages as described in the log documentation. ```APIDOC ## warning ### Description Log message at level Level.WARNING. See log for information on how non-String `message` arguments are handled. ### Method Signature ```dart void warning(Object? message, [Object? error, StackTrace? stackTrace]) ``` ### Parameters * **message** (Object?) - The message to log. * **error** (Object?) - An optional error object. * **stackTrace** (StackTrace?) - An optional stack trace. ### Implementation ```dart void warning(Object? message, [Object? error, StackTrace? stackTrace]) => log(Level.WARNING, message, error, stackTrace); ``` ``` -------------------------------- ### Define CONFIG Constant for Logging Source: https://pub.dev/documentation/logging/latest/logging/Level/CONFIG-constant.html This snippet shows the implementation of the static CONFIG constant for logging. It is used for static configuration messages and has a predefined integer value. ```dart static const Level CONFIG = Level('CONFIG', 700); ``` -------------------------------- ### compareTo Method Signature Source: https://pub.dev/documentation/logging/latest/logging/Level/compareTo.html Compares this Level object to another Level object. Returns a negative integer if this Level is ordered before the other, a positive integer if this Level is ordered after the other, and zero if they are ordered together. ```APIDOC ## compareTo Method ### Description Compares this object to another object. Returns a value like a Comparator when comparing `this` to `other`. That is, it returns a negative integer if `this` is ordered before `other`, a positive integer if `this` is ordered after `other`, and zero if `this` and `other` are ordered together. The `other` argument must be a value that is comparable to this object. ### Method Signature ```dart @override int compareTo(Level other) ``` ### Implementation ```dart @override int compareTo(Level other) => value - other.value; ``` ``` -------------------------------- ### operator < Source: https://pub.dev/documentation/logging/latest/logging/Level/operator_less.html Compares the current logging level with another level to determine if it is less than the other. ```APIDOC ## operator < ### Description Compares the current logging level with another level to determine if it is less than the other. ### Method Signature ```dart bool operator <(Level other) ``` ### Parameters * **other** (Level) - The logging level to compare against. ### Returns * (bool) - True if the current level's value is less than the other level's value, false otherwise. ### Implementation ```dart bool operator <(Level other) => value < other.value; ``` ``` -------------------------------- ### Logger.shout Method Implementation Source: https://pub.dev/documentation/logging/latest/logging/Logger/shout.html This is the implementation of the shout method, which calls the internal log method with Level.SHOUT. ```dart void shout(Object? message, [Object? error, StackTrace? stackTrace]) => log(Level.SHOUT, message, error, stackTrace); ``` -------------------------------- ### shout method Source: https://pub.dev/documentation/logging/latest/logging/Logger/shout.html Logs a message at Level.SHOUT. Non-String `message` arguments are handled as described in the log documentation. ```APIDOC ## shout(Object? message, [Object? error, StackTrace? stackTrace]) ### Description Logs a message at level Level.SHOUT. See log for information on how non-String `message` arguments are handled. ### Method Signature `void shout(Object? message, [Object? error, StackTrace? stackTrace])` ### Parameters #### message - **message** (Object?) - Optional - The message to log. #### error - **error** (Object?) - Optional - An error object to log. #### stackTrace - **stackTrace** (StackTrace?) - Optional - A stack trace to log. ### Implementation ```dart void shout(Object? message, [Object? error, StackTrace? stackTrace]) => log(Level.SHOUT, message, error, stackTrace); ``` ``` -------------------------------- ### log Method Signature Source: https://pub.dev/documentation/logging/latest/logging/Logger/log.html Adds a log record for a message at a particular logLevel if isLoggable(logLevel) is true. Use this method to create log entries for user-defined levels. To record a message at a predefined level (e.g. Level.INFO, Level.WARNING, etc) you can use their specialized methods instead (e.g. info, warning, etc). ```APIDOC ## log Method ### Description Adds a log record for a `message` at a particular `logLevel` if `isLoggable(logLevel)` is true. Use this method to create log entries for user-defined levels. To record a message at a predefined level (e.g. Level.INFO, Level.WARNING, etc) you can use their specialized methods instead (e.g. info, warning, etc). If `message` is a Function, it will be lazy evaluated. Additionally, if `message` or its evaluated value is not a String, then 'toString()' will be called on the object and the result will be logged. The log record will contain a field holding the original object. The log record will also contain a field for the zone in which this call was made. This can be advantageous if a log listener wants to handler records of different zones differently (e.g. group log records by HTTP request if each HTTP request handler runs in it's own zone). If this record is logged at a level equal to or higher than recordStackTraceAtLevel and `stackTrace` is `null` or StackTrace.empty it will be defaulted to the current stack trace for this call. ### Parameters #### Path Parameters - **logLevel** (Level) - Required - The logging level for this message. - **message** (Object?) - Optional - The message to log. Can be a String, a Function that returns a String, or any other Object. - **error** (Object?) - Optional - An error object associated with the log message. - **stackTrace** (StackTrace?) - Optional - A stack trace associated with the log message. - **zone** (Zone?) - Optional - The zone in which the log was recorded. ``` -------------------------------- ### Logger.finest Method Implementation Source: https://pub.dev/documentation/logging/latest/logging/Logger/finest.html This is the implementation of the `finest` method, which calls the `log` method with `Level.FINEST`. ```dart void finest(Object? message, [Object? error, StackTrace? stackTrace]) => log(Level.FINEST, message, error, stackTrace); ``` -------------------------------- ### operator > Source: https://pub.dev/documentation/logging/latest/logging/Level/operator_greater.html Compares if the current logging level is greater than another level. ```APIDOC ## operator > ### Description Compares if the current logging level is greater than another level. ### Method Signature ```dart bool operator >(Level other) ``` ### Parameters - **other** (Level) - The logging level to compare against. ### Returns - **bool** - True if the current level's value is greater than the other level's value, false otherwise. ### Implementation ```dart bool operator >(Level other) => value > other.value; ``` ``` -------------------------------- ### severe method Source: https://pub.dev/documentation/logging/latest/logging/Logger/severe.html Logs a message at Level.SEVERE. Non-String messages are handled as described in the log documentation. ```APIDOC ## severe method ### Description Log message at level Level.SEVERE. See log for information on how non-String `message` arguments are handled. ### Signature ```dart void severe(Object? message, [Object? error, StackTrace? stackTrace]) ``` ### Parameters * `message` (Object?) - The message to log. Can be any object. * `error` (Object?, optional) - An error object to include with the log message. * `stackTrace` (StackTrace?, optional) - A stack trace to include with the log message. ### Implementation ```dart void severe(Object? message, [Object? error, StackTrace? stackTrace]) => log(Level.SEVERE, message, error, stackTrace); ``` ``` -------------------------------- ### Logger Root Implementation Source: https://pub.dev/documentation/logging/latest/logging/Logger/root.html This is the top-level root Logger instance. It is declared as a static final Logger with an empty string name. ```dart static final Logger root = Logger(''); ``` -------------------------------- ### Initialize Hierarchical Logging Enabled Source: https://pub.dev/documentation/logging/latest/logging/hierarchicalLoggingEnabled.html Sets the hierarchicalLoggingEnabled property to false by default. When false, all hierarchical logging is merged into the root logger. ```dart bool hierarchicalLoggingEnabled = false; ``` -------------------------------- ### Logger onRecord Implementation Source: https://pub.dev/documentation/logging/latest/logging/Logger/onRecord.html The implementation of the onRecord getter, which returns a stream of LogRecord objects by calling _getStream(). ```dart Stream get onRecord => _getStream(); ``` -------------------------------- ### Log Message at FINER Level Source: https://pub.dev/documentation/logging/latest/logging/Logger/finer.html Use this method to log detailed information that is useful for debugging but not critical for normal operation. It internally calls the `log` method with `Level.FINER`. ```dart void finer(Object? message, [Object? error, StackTrace? stackTrace]) => log(Level.FINER, message, error, stackTrace); ``` -------------------------------- ### FINER Constant Implementation Source: https://pub.dev/documentation/logging/latest/logging/Level/FINER-constant.html Defines the FINER logging level constant. Use this for fairly detailed tracing information. ```dart static const Level FINER = Level('FINER', 400); ``` -------------------------------- ### Logger Level Name Implementation Source: https://pub.dev/documentation/logging/latest/logging/Level/name.html This shows the declaration of the final String 'name' property for a logging level. ```dart final String name; ``` -------------------------------- ### Log Method Implementation Source: https://pub.dev/documentation/logging/latest/logging/Logger/log.html This method adds a log record for a message at a particular logLevel. It handles lazy evaluation of function messages, converts non-string messages to strings, and automatically captures the current stack trace if the log level is high enough and no stack trace is provided. Zone information is also captured. ```dart void log(Level logLevel, Object? message, [Object? error, StackTrace? stackTrace, Zone? zone]) { Object? object; if (isLoggable(logLevel)) { if (message is Function) { message = (message as Object? Function())(); } String msg; if (message is String) { msg = message; } else { msg = message.toString(); object = message; } if ((stackTrace == null || stackTrace == StackTrace.empty) && logLevel >= recordStackTraceAtLevel) { stackTrace = StackTrace.current; error ??= 'autogenerated stack trace for $logLevel $msg'; } zone ??= Zone.current; final record = LogRecord(logLevel, msg, fullName, error, stackTrace, zone, object); if (parent == null) { _publish(record); } else if (!hierarchicalLoggingEnabled) { root._publish(record); } else { Logger? target = this; while (target != null) { target._publish(record); target = target.parent; } } } } ``` -------------------------------- ### Implement compareTo for Logging Level Source: https://pub.dev/documentation/logging/latest/logging/Level/compareTo.html Compares this Level object to another Level object based on their integer values. Returns a negative integer if this level is ordered before the other, a positive integer if this level is ordered after the other, and zero if they are ordered together. This implementation subtracts the other level's value from this level's value. ```dart @override int compareTo(Level other) => value - other.value; ``` -------------------------------- ### finest method Source: https://pub.dev/documentation/logging/latest/logging/Logger/finest.html Logs a message at Level.FINEST. Handles non-String messages, optional errors, and stack traces. ```APIDOC ## finest ### Description Log message at level Level.FINEST. See log for information on how non-String `message` arguments are handled. ### Method Signature `void finest(Object? message, [Object? error, StackTrace? stackTrace])` ### Parameters * **message** (Object?) - The message to log. Can be any object. * **error** (Object?) - An optional error object to log. * **stackTrace** (StackTrace?) - An optional stack trace to log. ### Implementation ```dart void finest(Object? message, [Object? error, StackTrace? stackTrace]) => log(Level.FINEST, message, error, stackTrace); ``` ``` -------------------------------- ### Logger Methods Source: https://pub.dev/documentation/logging/latest/logging/Logger-class.html Methods for logging messages at different levels and managing loggable status. ```APIDOC ## config(Object? message, [Object? error, StackTrace? stackTrace]) ### Description Log message at level Level.CONFIG. ### Method Instance Method ``` ```APIDOC ## fine(Object? message, [Object? error, StackTrace? stackTrace]) ### Description Log message at level Level.FINE. ### Method Instance Method ``` ```APIDOC ## finer(Object? message, [Object? error, StackTrace? stackTrace]) ### Description Log message at level Level.FINER. ### Method Instance Method ``` ```APIDOC ## finest(Object? message, [Object? error, StackTrace? stackTrace]) ### Description Log message at level Level.FINEST. ### Method Instance Method ``` ```APIDOC ## info(Object? message, [Object? error, StackTrace? stackTrace]) ### Description Log message at level Level.INFO. ### Method Instance Method ``` ```APIDOC ## isLoggable(Level value) ### Description Whether a message for `value`'s level is loggable in this logger. ### Method Instance Method ``` ```APIDOC ## log(Level logLevel, Object? message, [Object? error, StackTrace? stackTrace, Zone? zone]) ### Description Adds a log record for a `message` at a particular `logLevel` if `isLoggable(logLevel)` is true. ### Method Instance Method ``` ```APIDOC ## severe(Object? message, [Object? error, StackTrace? stackTrace]) ### Description Log message at level Level.SEVERE. ### Method Instance Method ``` ```APIDOC ## shout(Object? message, [Object? error, StackTrace? stackTrace]) ### Description Log message at level Level.SHOUT. ### Method Instance Method ``` ```APIDOC ## warning(Object? message, [Object? error, StackTrace? stackTrace]) ### Description Log message at level Level.WARNING. ### Method Instance Method ``` -------------------------------- ### toString Method Implementation Source: https://pub.dev/documentation/logging/latest/logging/Level/toString.html Overrides the default toString method to return the name of the logging level. This is useful for debugging and logging. ```dart @override String toString() => name; ``` -------------------------------- ### time property Source: https://pub.dev/documentation/logging/latest/logging/LogRecord/time.html The `time` property is a `DateTime` object indicating when the log record was created. ```APIDOC ## time property ### Description Time when this record was created. ### Type DateTime ### Implementation ```dart final DateTime time; ``` ``` -------------------------------- ### Define Logging Levels Constant Source: https://pub.dev/documentation/logging/latest/logging/Level/LEVELS-constant.html This constant defines the complete list of logging levels available in the system. It is used for configuration and to iterate through all possible levels. ```dart static const List LEVELS = [ ALL, FINEST, FINER, FINE, CONFIG, INFO, WARNING, SEVERE, SHOUT, OFF ]; ``` -------------------------------- ### Level Operators Source: https://pub.dev/documentation/logging/latest/logging/Level-class.html Operators for comparing Level instances. ```APIDOC ## Operators ### operator <(Level other) → bool *Description*: Checks if this level is less than another level. ### operator <=(Level other) → bool *Description*: Checks if this level is less than or equal to another level. ### operator ==(Object other) → bool *Description*: The equality operator. Checks if this level is equal to another object. ### operator >(Level other) → bool *Description*: Checks if this level is greater than another level. ### operator >=(Level other) → bool *Description*: Checks if this level is greater than or equal to another level. ``` -------------------------------- ### Define FINE Logging Level Constant Source: https://pub.dev/documentation/logging/latest/logging/Level/FINE-constant.html This constant is used to define the FINE logging level, typically for detailed tracing information. ```dart static const Level FINE = Level('FINE', 500); ``` -------------------------------- ### onRecord Property Source: https://pub.dev/documentation/logging/latest/logging/Logger/onRecord.html Returns a stream of messages added to this Logger. You can listen for messages using the standard stream APIs. ```APIDOC ## onRecord Property ### Description Returns a stream of messages added to this Logger. You can listen for messages using the standard stream APIs. ### Example ```dart logger.onRecord.listen((record) { ... }); ``` ### Signature `Stream get onRecord` ``` -------------------------------- ### Logger Class Source: https://pub.dev/documentation/logging/latest/logging Use a Logger to log debug messages. ```APIDOC ## Class: Logger ### Description Use a Logger to log debug messages. ``` -------------------------------- ### Logger Static Properties Source: https://pub.dev/documentation/logging/latest/logging/Logger-class.html Static properties of the Logger class. ```APIDOC ## attachedLoggers → Iterable ### Description All attached Loggers in the system. ### Property Type no setter ``` ```APIDOC ## root → Logger ### Description Top-level root Logger. ### Property Type final ``` -------------------------------- ### Logging Level hashCode Implementation Source: https://pub.dev/documentation/logging/latest/logging/Level/hashCode.html This snippet shows the implementation of the hashCode getter for a logging level object. It returns the 'value' property, which is assumed to be the state affecting equality. ```dart @override int get hashCode => value; ``` -------------------------------- ### Log Debug and Error Messages Source: https://pub.dev/documentation/logging/latest/index.html Logs a debug message upon successful async operation and an error message with stack trace if the operation fails. The `fine` message is only evaluated if the log level is sufficient. ```dart var future = doSomethingAsync().then((result) { log.fine('Got the result: $result'); processResult(result); }).catchError((e, stackTrace) => log.severe('Oh noes!', e, stackTrace)); ``` -------------------------------- ### Create a Detached Logger Source: https://pub.dev/documentation/logging/latest/logging/Logger/Logger.detached.html Use the factory constructor `Logger.detached` to create a new Logger instance. This logger is independent and will not be garbage collected. ```dart factory Logger.detached(String name) => Logger._internal(name, null, {}); ``` -------------------------------- ### toString() Method Source: https://pub.dev/documentation/logging/latest/logging/LogRecord/toString.html Overrides the default toString method to provide a formatted string representation of the LogRecord, including its level, logger name, and message. This is primarily used for debugging and logging purposes. ```APIDOC ## toString() ### Description Provides a string representation of the LogRecord object, useful for debugging and logging. ### Method Signature String toString() ### Implementation ```dart @override String toString() => '[${level.name}] $loggerName: $message'; ``` ### Usage Notes This method is intended for debugging and logging. It formats the output to include the log level, the name of the logger that generated the record, and the log message itself. ``` -------------------------------- ### Logger Properties Source: https://pub.dev/documentation/logging/latest/logging/Logger-class.html Properties of the Logger class. ```APIDOC ## children → Map ### Description Children in the hierarchy of loggers, indexed by their simple names. ### Property Type final ``` ```APIDOC ## fullName → String ### Description The full name of this logger, which includes the parent's full name. ### Property Type no setter ``` ```APIDOC ## level ↔ Level ### Description Effective level considering the levels established in this logger's parents (when hierarchicalLoggingEnabled is true). ### Property Type getter/setter pair ``` ```APIDOC ## name → String ### Description Simple name of this logger. ### Property Type final ``` ```APIDOC ## onLevelChanged → Stream ### Description Returns a stream of level values set to this Logger. ### Property Type no setter ``` ```APIDOC ## onRecord → Stream ### Description Returns a stream of messages added to this Logger. ### Property Type no setter ``` ```APIDOC ## parent → Logger? ### Description Parent of this logger in the hierarchy of loggers. ### Property Type final ``` -------------------------------- ### SEVERE Constant Implementation Source: https://pub.dev/documentation/logging/latest/logging/Level/SEVERE-constant.html Defines the static constant for the SEVERE log level. ```dart static const Level SEVERE = Level('SEVERE', 1000); ``` -------------------------------- ### Level Class Source: https://pub.dev/documentation/logging/latest/logging Represents the levels to control logging output. Logging can be enabled to include all levels above a certain Level. Levels are ordered using an integer value Level.value. ```APIDOC ## Class: Level ### Description Levels to control logging output. Logging can be enabled to include all levels above certain Level. Levels are ordered using an integer value Level.value. The predefined Level constants below are sorted as follows (in descending order): Level.SHOUT, Level.SEVERE, Level.WARNING, Level.INFO, Level.CONFIG, Level.FINE, Level.FINER, Level.FINEST, and Level.ALL. ### Constants - `defaultLevel` (const Level): The default Level. ``` -------------------------------- ### LogRecord Operators Source: https://pub.dev/documentation/logging/latest/logging/LogRecord-class.html Operators available for the LogRecord class. ```APIDOC ## Operators - **operator ==(Object other) → bool** The equality operator. Checks if this LogRecord is equal to another object. Inherited. ``` -------------------------------- ### Log a warning message Source: https://pub.dev/documentation/logging/latest/logging/Logger/warning.html Use this method to log messages that indicate a potential issue or unexpected event. Non-String messages are handled according to the log documentation. ```dart void warning(Object? message, [Object? error, StackTrace? stackTrace]) => log(Level.WARNING, message, error, stackTrace); ``` -------------------------------- ### Logger onLevelChanged Implementation Source: https://pub.dev/documentation/logging/latest/logging/Logger/onLevelChanged.html This is the internal implementation of the onLevelChanged stream, which uses a broadcast stream controller to manage level change events. ```dart Stream get onLevelChanged { _levelChangedController ??= StreamController.broadcast(sync: true); return _levelChangedController!.stream; } ``` -------------------------------- ### toString Method Source: https://pub.dev/documentation/logging/latest/logging/Level/toString.html The toString method overrides the default object string representation to provide the name of the logging level. This is useful for debugging and logging. ```APIDOC ## toString() ### Description Returns a string representation of the logging level. ### Method Signature String toString() ### Implementation ``` @override String toString() => name; ``` ### Usage This method is automatically called when the logging level object is converted to a string, for example, when logging the level itself. ``` -------------------------------- ### Define ALL Logging Level Constant Source: https://pub.dev/documentation/logging/latest/logging/Level/ALL-constant.html This constant is used to represent a level that captures all log messages. Its value is 0. ```dart static const Level ALL = Level('ALL', 0); ``` -------------------------------- ### Listen to Log Records Source: https://pub.dev/documentation/logging/latest/logging/Logger/onRecord.html Listen for messages added to this Logger using standard stream APIs. This is useful for reacting to log events as they occur. ```dart logger.onRecord.listen((record) { ... }); ``` -------------------------------- ### LogRecord Class Source: https://pub.dev/documentation/logging/latest/logging A log entry representation used to propagate information from Logger to individual handlers. ```APIDOC ## Class: LogRecord ### Description A log entry representation used to propagate information from Logger to individual handlers. ``` -------------------------------- ### onLevelChanged Property Source: https://pub.dev/documentation/logging/latest/logging/Logger/onLevelChanged.html Returns a stream of level values set to this Logger. You can listen for set levels using the standard stream APIs. A state error will be thrown if the level is changed inside the callback. ```APIDOC ## onLevelChanged Property ### Description Returns a stream of level values set to this Logger. You can listen for set levels using the standard stream APIs, for instance: ```dart logger.onLevelChanged.listen((level) { ... }); ``` A state error will be thrown if the level is changed inside the callback. ### Signature `Stream get onLevelChanged` ``` -------------------------------- ### Set recordStackTraceAtLevel to OFF Source: https://pub.dev/documentation/logging/latest/logging/recordStackTraceAtLevel.html Initialize the recordStackTraceAtLevel property to Level.OFF. This is the default behavior and disables automatic stack trace recording for performance reasons. ```java Level recordStackTraceAtLevel = Level.OFF; ``` -------------------------------- ### fullName Property Source: https://pub.dev/documentation/logging/latest/logging/Logger/fullName.html The full name of this logger, which includes the parent's full name. If the logger has a parent, its full name is appended with a dot and the logger's name. Otherwise, it returns just the logger's name. ```APIDOC ## fullName Property ### Description String get fullName The full name of this logger, which includes the parent's full name. ### Implementation ```dart String get fullName => parent?.name.isNotEmpty ?? false ? '${parent!.fullName}.$name' : name; ``` ``` -------------------------------- ### LogRecord zone property declaration Source: https://pub.dev/documentation/logging/latest/logging/LogRecord/zone.html This property holds the Zone where the LogRecord originated. It is nullable. ```dart final Zone? zone; ``` -------------------------------- ### LogRecord stackTrace Property Declaration Source: https://pub.dev/documentation/logging/latest/logging/LogRecord/stackTrace.html This snippet shows the declaration of the nullable stackTrace property within the LogRecord class. It is marked as final, indicating it can only be assigned once. ```dart final StackTrace? stackTrace; ``` -------------------------------- ### Define FINEST Logging Level Source: https://pub.dev/documentation/logging/latest/logging/Level/FINEST-constant.html This constant defines the FINEST logging level with a numerical value of 300, used for highly detailed tracing. ```dart static const Level FINEST = Level('FINEST', 300); ``` -------------------------------- ### Implement Less Than Operator for Log Levels Source: https://pub.dev/documentation/logging/latest/logging/Level/operator_less.html Compares the integer value of the current Level object with another Level object. Use this to check if a log level is less severe than another. ```dart bool operator <(Level other) => value < other.value; ``` -------------------------------- ### Logger fullName Property Implementation Source: https://pub.dev/documentation/logging/latest/logging/Logger/fullName.html This getter returns the full name of the logger. It includes the parent's full name if a parent exists and is not empty, otherwise it returns just the logger's name. ```dart String get fullName => parent?.name.isNotEmpty ?? false ? '${parent!.fullName}.$name' : name; ``` -------------------------------- ### operator == Source: https://pub.dev/documentation/logging/latest/logging/Level/operator_equals.html The equality operator (==) compares two Level objects. It returns true if both objects represent the same logging level, and false otherwise. This method is an override of the default object equality behavior. ```APIDOC ## operator == ### Description Compares this Level object to another object for equality. Returns true if the other object is a Level and has the same value. ### Method operator == ### Parameters #### Path Parameters - **other** (Object) - The object to compare with this Level. ### Response #### Success Response (bool) - **true** if the objects are equal (same level). - **false** if the objects are not equal. ### Implementation ```dart @override bool operator ==(Object other) => other is Level && value == other.value; ``` ``` -------------------------------- ### Define SHOUT Logging Level Source: https://pub.dev/documentation/logging/latest/logging/Level/SHOUT-constant.html This constant is used to define the SHOUT logging level, which is intended for extra debugging loudness. It is implemented as a static const Level with a value of 1200. ```dart static const Level SHOUT = Level('SHOUT', 1200); ``` -------------------------------- ### Log a Severe Message Source: https://pub.dev/documentation/logging/latest/logging/Logger/severe.html Use this method to log critical errors or issues that require immediate attention. It forwards the message, error, and stack trace to the underlying log function. ```dart void severe(Object? message, [Object? error, StackTrace? stackTrace]) => log(Level.SEVERE, message, error, stackTrace); ``` -------------------------------- ### Logger.detached Source: https://pub.dev/documentation/logging/latest/logging/Logger/Logger.detached.html Creates a new detached Logger instance. This logger is independent, has no parent or children, and is not part of the global hierarchical loggers structure. It's useful for local, short-lived loggers that can be garbage-collected. ```APIDOC ## Logger.detached constructor ### Description Creates a new detached Logger. Returns a new Logger instance (unlike `new Logger`, which returns a Logger singleton), which doesn't have any parent or children, and is not a part of the global hierarchical loggers structure. It can be useful when you just need a local short-living logger, which you'd like to be garbage-collected later. ### Method Signature Logger.detached(String name) ### Parameters #### Path Parameters - **name** (String) - Required - The name for the logger. ``` -------------------------------- ### Implement Greater Than Operator for Level Source: https://pub.dev/documentation/logging/latest/logging/Level/operator_greater.html Compares the numerical value of two logging levels. Use this to check if one level is more severe than another. ```dart bool operator >(Level other) => value > other.value; ``` -------------------------------- ### operator >= Source: https://pub.dev/documentation/logging/latest/logging/Level/operator_greater_equal.html Compares two Level instances to check if the first level is greater than or equal to the second level. ```APIDOC ## operator >= ### Description Compares two Level instances to check if the first level is greater than or equal to the second level. ### Method Signature ```dart bool operator >=(Level other) ``` ### Parameters * **other** (Level) - The level to compare against. ### Returns * **bool** - True if the current level is greater than or equal to the other level, false otherwise. ### Implementation ```dart bool operator >=(Level other) => value >= other.value; ``` ``` -------------------------------- ### Listen to Logger Level Changes Source: https://pub.dev/documentation/logging/latest/logging/Logger/onLevelChanged.html Use the standard stream API to listen for level changes on a logger instance. Avoid changing the level within the listener callback to prevent state errors. ```dart logger.onLevelChanged.listen((level) { ... }); ``` -------------------------------- ### Define WARNING Level Constant Source: https://pub.dev/documentation/logging/latest/logging/Level/WARNING-constant.html This snippet shows the implementation of the static const Level WARNING constant, which is assigned the value 900. ```dart static const Level WARNING = Level('WARNING', 900); ``` -------------------------------- ### Logging Level Value Declaration Source: https://pub.dev/documentation/logging/latest/logging/Level/value.html This snippet shows the declaration of the 'value' property as a final integer. It is used to order logging levels for filtering purposes. ```dart final int value; ``` -------------------------------- ### Set Logger Level Source: https://pub.dev/documentation/logging/latest/logging/Logger/level.html Overrides the logging level for this logger and its children. Setting to null inherits the parent's level. ```APIDOC ## set level ### Description Override the level for this particular Logger and its children. Setting this to `null` makes it inherit the parents level. ### Method SET (conceptual) ### Endpoint Logger.level ### Parameters #### Request Body - **value** (Level?) - The new logging level to set. `null` to inherit from parent. ```