summit-logger
v1.0.5
Published
A logger/debug tool for Summit University Dev Students. Creates "pretty-print" log messages, pleasant to the eye and easy to digest. (Summit University All Rights Reserved)
Downloads
13
Maintainers
Readme
summit-logger
A lightweight and easy-to-use logging/debugging tool specifically designed for Summit University development students. summit-logger
provides "pretty-printed" log messages in the browser console, making debugging a more pleasant and efficient experience.
Features
Namespaces: Organize your logs using namespaces (e.g., SummitUniversity:Main
, SummitUniversity:Auth
).
Extensible Namespaces: Create sub-namespaces for even finer-grained control (e.g., SummitUniversity:Main:UI
, SummitUniversity:Auth:Login
).
Filtering: Enable or disable logs based on namespaces using localStorage
. Use wildcards (*
) for broad filtering.
Pretty Printing: Logs are formatted with timestamps and distinct colors, making them easy to read and understand. Objects and arrays are nicely formatted using JSON.stringify
with indentation.
Data Type Handling: Handles various data types, just like console.log
(objects, arrays, strings, numbers, booleans, null, undefined, symbols).
Easy to Use: Simple API with a familiar console.log
-like interface.
Persistent Debugging: Uses localStorage
to remember which logs are enabled across page reloads.
MIT License: Freely use and modify the package.
Installation
yarn add summit-logger
Usage
1. Import and Create a Logger
import _summitLogger from "summit-logger";
export const logger = _summitLogger("APP");
2. Extend Loggers for Components
Each component can create its own logger by extending the main APP
logger:
import { logger } from "./App";
const loginLogger = logger.extend("Login");
const spaLogger = logger.extend("SPA");
3. Log Messages
logger.log("Application started");
loginLogger.log("User clicked login", { username: "Alice" });
spaLogger.log("User navigated to dashboard");
Example Output in Console
APP: Application started
APP:Login: User clicked login { username: "Alice" }
APP:SPA: User navigated to dashboard
4. Enable or Disable Logging
Use localStorage
to control logging dynamically:
Enable Specific Logs
localStorage.setItem("debug", "APP,APP:Login");
Enable All Logs
localStorage.setItem("debug", "*");
Disable Logging
localStorage.removeItem("debug");
API Reference
log(message, ...args)
Logs a message to the console with optional additional data.
logger.log("Hello, world!");
logger.log("User details", { id: 1, name: "John Doe" });
extend(subspace)
Creates a sub-logger under the current namespace.
const authLogger = logger.extend("Auth");
authLogger.log("Authentication started");
enable()
Enables logging for this logger's namespace.
logger.enable();
disable()
Disables logging for this logger's namespace.
logger.disable();
License
This project is licensed under the MIT License - see the LICENSE file for details.
Contributing
Pull requests are welcome! For major changes, please open an issue first to discuss what you would like to change.
Author
Developed and maintained by Summit University.