dart_frog_request_logger 0.0.2 copy "dart_frog_request_logger: ^0.0.2" to clipboard
dart_frog_request_logger: ^0.0.2 copied to clipboard

A logging helper for dart_frog servers. Supports logging for Google Cloud and local development.

Request Logger ๐Ÿชต #

ci coverage style: very good analysis License: MIT

A middleware for dart_frog that helps write logs.

Features โœจ #

  • ๐ŸŽฏ๐Ÿธ Works out of the box with Dart Frog.
  • โ˜๏ธ Built-in support for console-based logs & Google Cloud Logging.
  • ๐Ÿ“‹ Includes a ton of debugging information, including stacktraces.
  • ๐Ÿงช 100% code coverage verified with Very Good Workflows.

Quickstart ๐Ÿš€ #

This is a simplified example. For a full example visit /examples/dart_frog

Setup ๐Ÿ—๏ธ #

Add the RequestLogger middleware in your top level _middleware.dart file.

import 'package:dart_frog/dart_frog.dart';
import 'package:dart_frog_request_logger/dart_frog_request_logger.dart';
import 'package:request_logger/log_formatters.dart';

Handler middleware(Handler handler) {
  return handler.use(
   provider<RequestLogger>(
      (context) => RequestLogger(
        headers: context.request.headers,
        logFormatter: formatSimpleLog(),
      ),
    ),
  );
}

Write Logs ๐Ÿ“ #

Read the RequestLogger from the RequestContext.

import 'package:dart_frog/dart_frog.dart';
import 'package:dart_frog_request_logger/dart_frog_request_logger.dart';

Response onRequest(RequestContext context) {
  final logger = context.read<RequestLogger>();
  logger.debug('Hello Logs');
  return Response();
}

Using Different Log Formats #

Request logger supports log formats by providing a different LogFormatter when adding your middleware. You can either provide your own or use one of the built-in formatters.

Built-in Formatters #

All of the built in log formats live under package:request_logger/log_formatters.dart.

The built-in loggers currently are:

  • formatSimpleLog(): Formats a log with no particular specification - great for local development.
  • formatCloudLoggingLog(): Formats a log for Google Cloud Logging

Make You Own Formatter #

You can make your own formatter for your own specification! Just make sure it returns a String.

Example:

LogFormatter formatMyCustomLog() => ({
      required Severity severity,
      required String message,
      required Request request,
      Map<String, dynamic>? payload,
      Map<String, dynamic>? labels,
      bool? isError,
      Chain? chain,
      Frame? stackFrame,
    }) {
      return 'My custom log: $message';
    };
3
likes
160
pub points
64%
popularity

Publisher

unverified uploader

A logging helper for dart_frog servers. Supports logging for Google Cloud and local development.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

collection, http, meta, stack_trace

More

Packages that depend on dart_frog_request_logger