proxima_logger_logo

Easy to use, customizable, expandable logger that prints beautiful logs.

๐Ÿ’Ž Proxima Logger is a logging package for your Flutter/Dart app that is easy to use and customize.

๐ŸŽจ It offers a range of options and styles to customize your logs to your heartโ€™s desire. You can print out debug messages and add some color to your logs to make them stand out.

๐Ÿš€ Proxima Logger is also highly extensible, allowing you to send your logs to a remote server for safekeeping and output logs from popular HTTP clients such as Dio.

๐Ÿ™Œ Plus, it has no dependencies, meaning it wonโ€™t add any extra weight to your app or introduce any additional vulnerabilities.

Getting started

  1. Add package to the project:

    dart pub add proxima_logger
    
  2. Create an instance of Proxima Logger. You can set general settings for logging, including the order in which parts of the log are output, the style of the borders, and more if you like.

     final logger = ProximaLogger(
       settings: (logType) => switch (logType) {
         Log.debug => const LogSettings(
             logParts: [
               LogPart.stack,
               LogPart.message,
             ],
             logDecorations: LogDecorations.rounded(),
           ),
         Log.error => const LogSettings(
             logDecorations: LogDecorations.thick(),
           ),
         Log.wtf || Log.nothing => const LogSettings(
             logDecorations: LogDecorations.thin(),
           ),
         _ => const LogSettings(
             logParts: [
               LogPart.stack,
               LogPart.error,
               LogPart.time,
               LogPart.divider,
               LogPart.message,
             ],
             printEmoji: true,
             printTitle: true,
             printLogTypeLabel: true,
           ),
       }
     );
    

Usage

Use logger.log() or logger.info, logger.warning, logger.wtf, etc. anywhere in the program.

logger.log(
    Log.info,
    title: 'Log title',
);

logger.debug(message: 'Debug message');

try {
    //...
} catch (e, s) {
    logger.error(
        title: 'Some error',
        error: e,
        stack: s,
    );
}

Notes

To handle errors automatically, add runZonedGuarded() to main().

void main() {
  bool recordError(Object error, StackTrace stackTrace) {
    logger.log(Log.error, error: error, stack: stackTrace);
    return true;
  }

  void recordFlutterError(FlutterErrorDetails error) {
    logger.log(Log.error, error: error, stack: error.stack);
  }

  FlutterError.onError = recordFlutterError;
  PlatformDispatcher.instance.onError = recordError;

  runApp(const MyApp());
}

You can write your own wrapper over the logger to quickly use the required logging types and conveniently log requests from an http client, such as Dio.

class MyLogger extends ProximaLoggerBase {
  MyLogger({
    super.settings,
    super.typeSettings,
    super.formatter,
    super.decorator,
    super.output,
  });

  void info(String message) {
    log(Log.info, message: message);
  }

  void error(Error error, StackTrace stack, [String? message]) {
    log(Log.error, error: error, stack: stack, message: message);
  }

  void response(Response response) {
    log(
      Log.response,
      title:
          '| ${response.requestOptions.method} | ${response.statusCode} | ${response.requestOptions.path}',
      message: response.data,
    );
  }
}

If necessary, you can implement the LogType class and create your own log types.

enum Log implements ILogType {
  custom(
    label: 'custom',
    emoji: '๐Ÿฆ„',
    ansiPen: AnsiPen.purple(),
  );

  @override
  final String label;
  @override
  final String emoji;
  @override
  final AnsiPen ansiPen;
  @override
  final AnsiPen ansiPenOnBackground;

  const Log({
    required this.label,
    required this.emoji,
    required this.ansiPen,
    this.ansiPenOnBackground = const AnsiPen.black(),
  });
}

Output

image image

Libraries

proxima_logger