Utility - 7TogkID/gaman GitHub Wiki

GamanJS Utility Documentation

Overview

GamanJS provides utilities to streamline backend development. Currently, the utility library includes the Logger module, which simplifies logging at various levels for better debugging and monitoring.


Logger Utility

The Logger utility offers an easy-to-use interface for logging messages at different levels of severity.

Importing Logger

To use the Logger utility, import it from the gaman package:

import { Logger } from "gaman";

Available Methods

Logger.info(message: string)

Logs informational messages that provide general feedback or updates.

Logger.info("Server has started successfully.");

Logger.log(message: string)

Logs standard messages, typically for routine operations.

Logger.log("User connected to the service.");

Logger.debug(message: string)

Logs debug messages intended for development or troubleshooting purposes.

Logger.debug("Debugging connection parameters: { host: 'localhost', port: 3431 }");

Logger.error(message: string)

Logs error messages, useful for reporting issues or exceptions.

Logger.error("Failed to connect to the database.");

Example Usage

Basic Logging

Here’s an example of using the Logger utility to track server operations:

import { Logger } from "gaman";

Logger.info("Server is starting...");
Logger.log("Listening on port 3431.");

try {
  // Simulating a successful operation
  Logger.debug("Attempting to connect to the database...");
  // Simulated operation succeeded
  Logger.info("Connected to the database successfully.");
} catch (error) {
  Logger.error("Database connection failed: " + error.message);
}

Best Practices

  • Use Logger.info for high-level updates and progress.
  • Use Logger.log for normal operations and tracking.
  • Use Logger.debug during development to trace issues or inspect application behavior.
  • Use Logger.error for critical failures or exceptions.

Future Utilities

Additional utility modules may be introduced to expand GamanJS functionality. Stay tuned for updates in future releases.

For more advanced usage and examples, refer to the GamanJS documentation or code samples.