ghost_logger 1.0.0 copy "ghost_logger: ^1.0.0" to clipboard
ghost_logger: ^1.0.0 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();

  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 - Now with Colors!'),
    );
  }
}

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 colored terminal output! ✨',
                  textAlign: TextAlign.center,
                  style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
                ),
              ),
              const SizedBox(height: 32),
              _LogButton(
                label: '⚒️ Log Debug (Gray)',
                color: Colors.grey,
                onPressed: () {
                  GhostLogger.log(
                    message:
                        'This is a debug message - check your terminal to see it in gray!',
                    level: LogLevel.debug,
                    tag: 'Example',
                  );
                },
              ),
              _LogButton(
                label: '👉 Log Info (Cyan)',
                color: Colors.cyan,
                onPressed: () {
                  GhostLogger.log(
                    message:
                        'User performed an action - check your terminal to see it in cyan!',
                    level: LogLevel.info,
                    tag: 'Example',
                  );
                },
              ),
              _LogButton(
                label: '⚠️ Log Warning (Yellow)',
                color: Colors.orange,
                onPressed: () {
                  GhostLogger.log(
                    message:
                        'This might need attention - check your terminal to see it in yellow!',
                    level: LogLevel.warning,
                    tag: 'Example',
                  );
                },
              ),
              _LogButton(
                label: '❌ Log Error (Red)',
                color: Colors.red,
                onPressed: () {
                  GhostLogger.log(
                    message:
                        'An error occurred silently - check your terminal to see it in red!',
                    level: LogLevel.error,
                    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 colored 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
72
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