graceful library

Support for log files and process termination handling.

Enable graceful exiting by returning bootstrap(...) directly from your main and by defining a custom shutdown function.

import 'package:graceful/graceful.dart';

void main(List<String> args) => bootstrap(run, args, onExit: onExit);

void run(List<String> args) {
  // Your code...
}

Future<int> onExit() async {
  // Perform cleanup...

  print('Exited gracefully');
  return 0; // Exit code 0
}

Constants

allSignals → const List<ProcessSignal>

Properties

isDebugMode bool
no setter

Functions

bootstrap(BodyFunc body, {List<String> args = const [], ExitFunc? onExit, Iterable<ProcessSignal> signals = allSignals, bool exitAfterBody = true, bool? enableChildProcess = ifNotDebugging, bool? enableLogFiles = ifNotDebugging, String fileOut = 'logs/out.log', String fileErr = 'logs/err.log', Logger formatterStd = logPassthrough, Logger formatterFile = logTimestamp}) → void
Allows running this program with a custom exiting function and optional file logging.
exitGracefully() → void
Calls the onExit() handler that was passed in bootstrap() and exits the Dart VM process immediately after.
isProcessRunning(int pid) Future<bool>
logPassthrough(String line) String
logTimestamp(String line) String

Typedefs

Logger = String Function(String line)