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

outdated

An extended logger for providing detailed log messages.

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:

  • Log messages on multiple log levels – verbose, debug, info, warning, error and wtf.
  • Structurally add log message, details and data.
  • 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');
const data = { 'age': 24 };

codenicLogger.info(messageLog, data: data);

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');

const data = { 'foo': false, 'lorep': 'ipsum' };

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

Logging an exception #

try {
    throw Exception('Test exception');
} catch (exception, stackTrace) {
  codenicLogger.error(
    messageLog.copyWith(details: 'error'),
    data: {'foo': false, 'lorep': 'ipsum'},
    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, data: data);
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 message, {
    Map<String, dynamic>? data,
    error,
    StackTrace? stackTrace,
  }) {
    super.error(message, data: data, error: error, stackTrace: stackTrace);

    FirebaseCrashlytics.instance.recordError(
      error,
      stackTrace,
      reason: formatMessageData(message, data),
    );
  }
}

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
54%
popularity

Publisher

verified publishercodenic.dev

An extended logger for providing detailed log messages.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

logger, meta

More

Packages that depend on codenic_logger