Skip to main content

logsmith 2.0.0 copy "logsmith: ^2.0.0" to clipboard
logsmith: ^2.0.0 copied to clipboard

A declarative structured-logging library — typed attrs, themed output, six formats (text, JSON, YAML, TOML, Mace, logfmt), and categorical stdout/stderr routing.

example/logsmith_example.dart

import 'dart:io';

import 'package:logsmith/logsmith.dart';

Future<void> main() async {
  final terminal = TerminalLogger.singleLine(name: 'example');
  terminal.info('application started', attrs: {'port': 8080});
  terminal.withAttrs({'request_id': 'req-42'}).success('request accepted');

  TerminalLogger.multiline(name: 'worker').warning(
    'retrying\nupstream unavailable',
    attrs: {
      'retry': {'attempt': 2, 'delay': const Duration(milliseconds: 250)},
    },
  );

  final machine = MachineLogger(name: 'audit');
  machine.info('machine-readable event', attrs: {'ok': true});

  final directory = await Directory.systemTemp.createTemp('logsmith-example-');
  try {
    final path = '${directory.path}${Platform.pathSeparator}events.jsonl';
    final file = FileLogger(path, name: 'audit', append: false);
    file.info('signed in', attrs: {'user_id': 42});
    file.error('permission denied', attrs: {'resource': '/admin'});
    await file.close();

    stdout.writeln('\nFile JSON Lines:\n${await File(path).readAsString()}');
  } finally {
    if (directory.existsSync()) {
      await directory.delete(recursive: true);
    }
  }
}
0
likes
160
points
151
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

A declarative structured-logging library — typed attrs, themed output, six formats (text, JSON, YAML, TOML, Mace, logfmt), and categorical stdout/stderr routing.

Repository (GitHub)
View/report issues

Topics

#logging #structured-logging #terminal #ansi #cli

License

BSD-3-Clause (license)

Dependencies

toml

More

Packages that depend on logsmith