PrintFn typedef

PrintFn = void Function(String message, [List<String>? rest])

Signature for a custom print function used by logger.

The middleware calls fn with a single pre-formatted string. The optional rest parameter lets you reuse the same function for custom log lines inside route handlers.

final log = (String message, [List<String>? rest]) {
  if (rest != null && rest.isNotEmpty) {
    print('$message ${rest.join(' ')}');
  } else {
    print(message);
  }
};

app.use(logger(log));

app.post('/blog', (Context c) async {
  final blog = await c.body();
  log('Blog saved:', ['Path: ${blog['url']},', 'ID: ${blog['id']}']);
  // --> POST /blog
  // Blog saved: Path: /blog/example, ID: 1
  // <-- POST /blog 201 4ms
  return c.created(blog);
});

Implementation

typedef PrintFn = void Function(String message, [List<String>? rest]);