Skip to content

A beautiful, lightweight logging library for JavaScript/TypeScript with an elegant popup UI for browser and enhanced terminal output for Node.js.

License

Notifications You must be signed in to change notification settings

shehari007/candy-logger

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

12 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🍬 Candy Logger

A beautiful, lightweight logging library for JavaScript/TypeScript with an elegant popup UI for browser and enhanced terminal output for Node.js.

πŸš€ Live Demo

Try the interactive demo to see all features in action!

✨ Features

  • 🎨 Beautiful Browser UI - Floating, draggable popup logger (dev mode only)
  • πŸ“ Resizable UI - Drag corners to resize the logger (300px-800px Γ— 200px-80vh)
  • πŸ”§ Force UI Mode - Show UI in any environment with forceUI: true
  • πŸ–₯️ Enhanced Terminal Output - Colorful, formatted logs in Node.js
  • πŸ” Filter by Level - Filter logs by type (log, info, warn, error)
  • πŸ”Ž Search Logs - Real-time log search functionality
  • πŸ“‹ Copy to Clipboard - Easy JSON copying
  • πŸ“Œ Pin UI - Keep the logger visible or auto-fade
  • 🎯 Zero Config - Works out of the box
  • πŸš€ Lightweight - Minimal performance impact
  • 🌐 Universal - Works in browser and Node.js

πŸ“¦ Installation

npm install candy-logger

πŸš€ Quick Start

Browser (React, Vue, Angular, etc.)

Option 1: Override Console (Recommended)

All your existing console.log/info/warn/error will automatically use Candy Logger:

import { overrideConsole } from 'candy-logger';

// Call once in your app entry point (e.g., index.js or App.jsx)
overrideConsole();

// Now use console normally - it's automatically enhanced!
console.log('Hello World!');
console.info('User logged in', { userId: 123 });
console.warn('Low memory');
console.error('API failed', errorObject);

Option 2: Use Directly

import candy from 'candy-logger';

candy.log('Application started');
candy.info('User data', { name: 'John', age: 30 });
candy.warn('Warning message');
candy.error('Error occurred', error);

React Example

// src/index.js or src/main.jsx
import React from 'react';
import ReactDOM from 'react-dom/client';
import { overrideConsole } from 'candy-logger';
import App from './App';

// Initialize candy logger once
overrideConsole();

ReactDOM.createRoot(document.getElementById('root')).render(
  <React.StrictMode>
    <App />
  </React.StrictMode>
);

// Now use console anywhere in your app
function MyComponent() {
  const handleClick = () => {
    console.log('Button clicked!');
    console.info('User action', { action: 'click', button: 'submit' });
  };

  return <button onClick={handleClick}>Click Me</button>;
}

Node.js / Express Server

const express = require('express');
const { overrideConsole } = require('candy-logger');

// Enable in development only
if (process.env.NODE_ENV !== 'production') {
  overrideConsole();
}

const app = express();

app.get('/', (req, res) => {
  console.log('Request received');
  console.info('Request details', { method: req.method, path: req.path });
  res.send('Hello World');
});

app.listen(3000, () => {
  console.log('Server running on port 3000');
});

Node.js Scripts (Interactive Terminal UI)

For standalone scripts, you can use the interactive terminal UI:

import { createInteractiveLogger } from 'candy-logger';

const logger = createInteractiveLogger();

logger.log('Processing data...');
logger.info('Progress', { completed: 50, total: 100 });
logger.warn('High memory usage');
logger.error('Failed to process item', errorDetails);

// Interactive features:
// - Mouse: Click filter buttons, scroll with wheel
// - Keys: ↑↓ to navigate, Enter to expand/collapse, 1-5 to filter, C to clear, Q to quit

🎨 UI Features

Browser UI

  • Auto-fade - UI fades when not hovering (pin to keep visible)
  • Draggable - Move the logger anywhere on screen
  • Minimizable - Collapse to save space
  • Filters - Show only specific log types
  • Search - Find logs instantly
  • JSON Formatting - Auto-formatted with syntax highlighting
  • Copy Buttons - Copy JSON with one click

Terminal UI

  • Color-coded - Different colors for each log level
  • Timestamps - Automatic timestamps on all logs
  • JSON Formatting - Pretty-printed JSON objects
  • Interactive Mode - Full-featured TUI for scripts

🎯 API

Methods

candy.log(...args)      // Blue - General logging
candy.info(...args)     // Cyan - Informational messages
candy.warn(...args)     // Yellow - Warnings
candy.error(...args)    // Red - Errors
candy.getStats()        // Get log counts
candy.printStats()      // Print statistics (Node.js only)

Console Override

import { overrideConsole, restoreConsole } from 'candy-logger';

// Override console
const logger = overrideConsole();

// Your code here...
console.log('This uses candy logger');

// Restore original console
restoreConsole(logger);

πŸ”§ Configuration

Development vs Production

The browser UI automatically disables in production:

  • Only shows on localhost, 127.0.0.1, or when NODE_ENV !== 'production'
  • Zero overhead in production builds
  • Logs still work but go to regular console

Interactive Mode (Node.js only)

// For servers - DO NOT use interactive mode
overrideConsole(); // βœ… Good

// For standalone scripts - use interactive mode
createInteractiveLogger(); // βœ… Good for scripts

⚠️ Never use interactive mode in servers - it creates a full-screen UI that blocks your application.

πŸ“ TypeScript Support

Fully typed with TypeScript definitions included:

import candy, { overrideConsole, createInteractiveLogger } from 'candy-logger';

// All methods are fully typed
candy.log('Hello', { typed: true });

🌟 Why Candy Logger?

  • βœ… Zero configuration - Just import and use
  • βœ… Non-intrusive - Doesn't interfere with your code
  • βœ… Production-safe - UI auto-disables in production
  • βœ… Beautiful output - Makes debugging enjoyable
  • βœ… Framework agnostic - Works with React, Vue, Angular, Express, etc.
  • βœ… Lightweight - Minimal bundle size impact

πŸ“‹ Changelog

v1.0.4 (Latest)

πŸ”§ Critical Bug Fix:

  • Fixed constructor singleton bug in overrideConsole() that prevented forceUI: true from working properly
  • Now correctly creates new logger instances with provided options instead of reusing singleton

v1.0.3

πŸ†• New Features:

  • πŸ“ Project Structure - Organized demo files and documentation

πŸ”§ Bug Fixes:

  • Fixed directory structure and file organization
  • Improved demo page styling and functionality
  • Enhanced documentation with demo link

v1.0.2

πŸ†• New Features:

  • πŸ“ Resizable UI - Drag the bottom-right corner to resize the candy logger (300px-800px width, 200px-80vh height)
  • πŸ”§ Force UI Mode - New forceUI option to bypass development-only restriction
  • β‹° Resize Handle - Visual resize indicator in the bottom-right corner

✨ Enhancements:

  • Dynamic height adjustment when resizing
  • Improved minimize behavior (title bar only)
  • Better text alignment in search input
  • Clean minimized state without background overflow

Usage:

// Force UI to show in any environment (including production)
overrideConsole({ forceUI: true });

// The logger UI is now fully resizable - just drag the corner!

v1.0.1

  • Initial stable release with browser UI and terminal features

πŸ“„ License

MIT

🀝 Contributing

Contributions are welcome! Feel free to open issues or submit PRs.

πŸ“§ Support

If you encounter any issues or have questions, please open an issue on GitHub.


Made with 🍬 by shehari007

About

A beautiful, lightweight logging library for JavaScript/TypeScript with an elegant popup UI for browser and enhanced terminal output for Node.js.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published