logging_on_oslog 1.0.0 copy "logging_on_oslog: ^1.0.0" to clipboard
logging_on_oslog: ^1.0.0 copied to clipboard

PlatformiOSmacOS

Log using os_log on iOS or macOS so that you can check the logs using Console.app on a macOS machine.

example/lib/main.dart

import 'dart:io';

import 'package:flutter/material.dart';
import 'dart:async';

import 'package:logging_on_oslog/logging_on_oslog.dart';
import 'package:logging/logging.dart';

void main() {
  runApp(const MyApp());
}

final appLogger = Logger('ExampleApp');

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  late final StreamSubscription<LogRecord>? _logOnOSLogSubscription;

  var _counter = 0;

  @override
  void initState() {
    super.initState();
    if (Platform.isIOS || Platform.isMacOS) {
      _logOnOSLogSubscription = Logger.root.activateOsLog();
    }
    Logger.root.level = Level.INFO;
  }

  @override
  void dispose() {
    _logOnOSLogSubscription?.cancel();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('logging_on_oslog example app'),
        ),
        body: Center(
          child: Text('Counter: $_counter'),
        ),
        floatingActionButton: FloatingActionButton(
          child: const Icon(Icons.plus_one),
          onPressed: () {
            setState(() {
              _counter++;
            });
            // The first four messages will not appear in Console.app
            // because the level of the logger is Level.INFO (see line 33).
            appLogger.finest('finest! Value: $_counter');
            appLogger.finer('finer! Value: $_counter');
            appLogger.fine('fine! Value: $_counter');
            appLogger.config('config! Value: $_counter');

            // The next four messages will appear in Console.app.
            appLogger.info('info! Value: $_counter');
            appLogger.warning('warning! Value: $_counter');
            appLogger.severe('severe! Value: $_counter');
            appLogger.shout('shout! Value: $_counter');
          },
        ),
      ),
    );
  }
}
3
likes
160
points
1.18k
downloads
screenshot

Publisher

verified publishervolpato.dev

Weekly Downloads

Log using os_log on iOS or macOS so that you can check the logs using Console.app on a macOS machine.

Repository
View/report issues

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

flutter, logging, plugin_platform_interface

More

Packages that depend on logging_on_oslog