codenic_logger 0.2.1 copy "codenic_logger: ^0.2.1" to clipboard
codenic_logger: ^0.2.1 copied to clipboard

outdated

An enhanced logger for providing structured and detailed log messages.

GitHub Workflow Status CodeCov style: very good analysis GitHub GitHub code size in bytes Pub Version

A logger for providing structured and detailed log messages.

This uses the logger package to produce log messages.

Sample detailed log messages

Features #

Use this plugin in your app to:

  • Structurally add log message, details and data.
  • Log messages on multiple log levels – verbose, debug, info, warning, error and wtf.
  • Automatically add a user ID to all log data upon logging.

Getting started #

To get started, just create a Codenic logger instance:

final codenicLogger = CodenicLogger();

const messageLog = MessageLog(message: 'Save age failed', details: 'No internet', data: { 'age': 24 });

codenicLogger.info(messageLog);

Usage #

This section has examples of code for the following tasks:

Logging with different log levels #

final codenicLogger = CodenicLogger();

const messageLog = MessageLog(message: 'Sample message', data: { 'foo': false, 'lorep': 'ipsum' });

codenicLogger.verbose(messageLog);
codenicLogger.debug(messageLog);
codenicLogger.info(messageLog);
codenicLogger.warn(messageLog);
codenicLogger.error(messageLog);
codenicLogger.wtf(messageLog);

Logging an exception #

try {
    throw Exception('Test exception');
} catch (exception, stackTrace) {
    messageLog.details = 'An error occurred';
    codenicLogger.error(
        messageLog,
        error: exception,
        stackTrace: stackTrace,
    );
}
Sample detailed log messages

Setting a user ID #

When a user ID is provided, it will automatically be included in the log data.

codenicLogger.userId = 'sample-uid';
codenicLogger.info(messageLog);
Sample detailed log messages

To remove the user ID, simply set it back to null:

codenic.userId = null;

Customizing the log output #

To customize the log output, provide a custom logger instance:

final logger = Logger(
  printer: PrettyPrinter(
    methodCount: 2, // number of method calls to be displayed
    errorMethodCount: 8, // number of method calls if stacktrace is provided
    lineLength: 120, // width of the output
    colors: true, // Colorful log messages
    printEmojis: true, // Print an emoji for each log message
    printTime: false // Should each log print contain a timestamp
  ),
);

final codenicLogger = CodenicLogger(logger: logger);

For more info, visit the logger package.

Sample Integration: Firebase Crashlytics #

class FirebaseLogger extends CodenicLogger {
  @override
  set userId(String? _userId) {
    super.userId = _userId;
    FirebaseCrashlytics.instance.setUserIdentifier(_userId ?? '');
  }

  @override
  void error(
    MessageLog messageLog, {
    error,
    StackTrace? stackTrace,
  }) {
    super.error(messageLog, error: error, stackTrace: stackTrace);

    FirebaseCrashlytics.instance.recordError(
      error,
      stackTrace,
      reason: messageLog,
    );
  }
}

Additional information #

Contributing to this plugin #

If you would like to contribute to the package, check out the contribution guide.

6
likes
0
pub points
58%
popularity

Publisher

verified publishercodenic.dev

An enhanced logger for providing structured and detailed log messages.

Repository (GitHub)
View/report issues

Documentation

Documentation

License

unknown (LICENSE)

Dependencies

logger, meta

More

Packages that depend on codenic_logger