ghost_logger 1.1.1 copy "ghost_logger: ^1.1.1" to clipboard
ghost_logger: ^1.1.1 copied to clipboard

Can be Unseen but always there. Stealing errors before they steal your users' experience. A flexible logging utility with optional crash reporting integration.

example/lib/main.dart

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

void main() async {
  WidgetsFlutterBinding.ensureInitialized();

  // No need to specify isDebugMode anymore - it defaults to kDebugMode!
  await GhostLogger.configure(
    loggerType: LoggerType.console,
  );

  runApp(const MyApp());
}

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Ghost Logger Example',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MyHomePage(title: 'Ghost Logger Demo'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(widget.title),
      ),
      body: Center(
        child: SingleChildScrollView(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              const Padding(
                padding: EdgeInsets.all(16),
                child: Text(
                  'Stealing errors before they steal your users\' experience',
                  textAlign: TextAlign.center,
                  style: TextStyle(fontSize: 18, fontStyle: FontStyle.italic),
                ),
              ),
              const SizedBox(height: 16),
              const Padding(
                padding: EdgeInsets.symmetric(horizontal: 16),
                child: Text(
                  '✨ Now with convenience methods! ✨',
                  textAlign: TextAlign.center,
                  style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
                ),
              ),
              const SizedBox(height: 32),
              _LogButton(
                label: '⚒️ Log Debug',
                color: Colors.grey,
                onPressed: () {
                  GhostLogger.logDebug(
                    'This is a debug message using convenience method',
                    tag: 'Example',
                  );
                },
              ),
              _LogButton(
                label: '👉 Log Info',
                color: Colors.cyan,
                onPressed: () {
                  GhostLogger.logInfo(
                    'User performed an action',
                    tag: 'Example',
                  );
                },
              ),
              _LogButton(
                label: '⚠️ Log Warning',
                color: Colors.orange,
                onPressed: () {
                  GhostLogger.logWarning(
                    'This might need attention',
                    tag: 'Example',
                  );
                },
              ),
              _LogButton(
                label: '❌ Log Error',
                color: Colors.red,
                onPressed: () {
                  GhostLogger.logError(
                    'An error occurred silently',
                    tag: 'Example',
                    stackTrace: StackTrace.current,
                  );
                },
              ),
              const SizedBox(height: 32),
              const Padding(
                padding: EdgeInsets.symmetric(horizontal: 16),
                child: Text(
                  'Check your console output to see the logged messages',
                  textAlign: TextAlign.center,
                  style: TextStyle(fontSize: 14, color: Colors.grey),
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}

class _LogButton extends StatelessWidget {
  final String label;
  final Color color;
  final VoidCallback onPressed;

  const _LogButton({
    required this.label,
    required this.color,
    required this.onPressed,
  });

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: const EdgeInsets.all(8),
      child: ElevatedButton(
        style: ElevatedButton.styleFrom(
          backgroundColor: color,
          foregroundColor: Colors.white,
        ),
        onPressed: onPressed,
        child: Text(label),
      ),
    );
  }
}
1
likes
0
points
70
downloads

Publisher

unverified uploader

Weekly Downloads

Can be Unseen but always there. Stealing errors before they steal your users' experience. A flexible logging utility with optional crash reporting integration.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter

More

Packages that depend on ghost_logger