logging_manager 2.3.1 copy "logging_manager: ^2.3.1" to clipboard
logging_manager: ^2.3.1 copied to clipboard

Provides simple APIs for logging & managing logs. Uses the logger from the logging package.

example/logging_manager_example.dart

import 'package:logging_manager/logging_manager.dart';

void main() {
  final loggingManager = LoggingManager(logger: Logger('MyApp'));

  // or just Logger(''); for getting the root logger.
  final logger = Logger('MyApp');

  testPrinting(logger, 'PrintingColoredLogsTree');
  loggingManager.removeTree();
  testPrinting(logger, 'NotPrintingLogs');
  loggingManager.plantTree(PrintingLogsTree());
  testPrinting(logger, 'PrintingLogsTree');

  final childLogger = loggingManager.getLogger('child_logger');

  testPrinting(childLogger, 'PrintingColoredLogsTree');
  loggingManager.removeTree();
  testPrinting(childLogger, 'NotPrintingLogs');
  loggingManager.plantTree(PrintingLogsTree());
  testPrinting(childLogger, 'PrintingLogsTree');

  /// This won't print anything because the logging manager is managing logs from
  /// MyApp and its children. The logger below is root logger and its not a children
  /// of the logger the above logging manager manages.
  final rootLogger = Logger('');

  testPrinting(rootLogger, 'PrintingColoredLogsTree');
  loggingManager.removeTree();
  testPrinting(rootLogger, 'NotPrintingLogs');
  loggingManager.plantTree(PrintingLogsTree());
  testPrinting(rootLogger, 'PrintingLogsTree');
}

void testPrinting(Logger logger, String treeType) {
  logger.fine(
      '------------------------------------------------------------------');
  logger.config('This is a config from $treeType');
  logger.info('This is a info from $treeType');
  logger.warning('This is a warning from $treeType');
  logger.severe('This is a warning from $treeType');
  logger.shout('This is a shout from $treeType');

  try {
    throw Exception('Fake error');
  } catch (e, s) {
    logger.severe(
      'Severe error caught with stack trace. This is a from $treeType',
      e,
      s,
    );
  }
}
2
likes
120
pub points
17%
popularity

Publisher

verified publishermagnificsoftware.com

Provides simple APIs for logging & managing logs. Uses the logger from the logging package.

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (LICENSE)

Dependencies

ansicolor, logging, meta

More

Packages that depend on logging_manager