Skip to content
Logger

Logger

Logger (hereinafter the “Application”) is a custom logging utility that provides a wrapper around a custom alert monitoring server, enabling applications to pipe errors and log messages to a centralised alerting system.

This section is for those interacting with a live instance of the Application.

Install the package using your preferred package manager:

Terminal window
npm install @nhcarrigan/logger
Terminal window
pnpm add @nhcarrigan/logger
Terminal window
yarn add @nhcarrigan/logger
import { Logger } from "@nhcarrigan/logger";
// Initialize the logger
const logger = new Logger("my-app", "your-api-token");
// Send log messages
await logger.log("info", "Application started successfully");
await logger.log("warn", "This is a warning message");
await logger.log("debug", "Debug information");
// Send error reports
try {
// Your code here
} catch (error) {
await logger.error("functionName", error);
}
new Logger(application: string, token: string, url?: string)

Parameters:

  • application (string): The name of your application (will appear in logs)
  • token (string): Your API token for the monitoring service
  • url (optional string): Custom URL for your own alerting instance (defaults to “https://alerts.spellware.dev”)
log(level: Level, message: string): Promise<void>
Section titled “log(level: Level, message: string): Promise<void>”

Sends a log message to the alerting service.

Parameters:

  • level (Level): The log level - one of “debug”, “info”, or “warn”
  • message (string): The message to send
error(context: string, error: Error): Promise<void>
Section titled “error(context: string, error: Error): Promise<void>”

Sends an error to the alerting service with stack trace information.

Parameters:

  • context (string): A brief description of where the error occurred (e.g., function name)
  • error (Error): The Node.js error object

The Application supports three log levels:

  • "debug": Debug information for development purposes
  • "info": General informational messages
  • "warn": Warning messages that don’t halt execution

By default, the logger sends data to https://alerts.spellware.dev. You can configure it to use your own alerting instance by providing a custom URL in the constructor.

This section is for those interested in running their own instance of the Application.

The Application is built as a TypeScript class that wraps HTTP requests to an alerting server. It provides two main endpoints:

  1. /log - For general log messages
  2. /error - For error reporting with stack traces

Sends structured log data:

{
"application": "your-app-name",
"level": "info",
"message": "Your log message"
}

Sends structured error data:

{
"application": "your-app-name",
"context": "function-name",
"message": "Error message",
"stack": "Stack trace information"
}

All requests require an Authorization header with your API token.

  1. Clone the repository:

    Terminal window
    git clone https://github.com/spellware/logger.git
  2. Install dependencies:

    Terminal window
    pnpm install
  3. Build the project:

    Terminal window
    pnpm run build
  4. Run linting:

    Terminal window
    pnpm run lint
src/
├── index.ts # Main Logger class
└── types/
└── level.ts # Log level type definitions

The project uses:

  • @nhcarrigan/typescript-config for TypeScript configuration
  • @nhcarrigan/eslint-config for ESLint rules
  • ES modules ("type": "module")

This section is for expansions to our legal policies specific to the Application.

This software is licensed under Naomi’s Public Licence. See the LICENSE.md file for complete terms.

Copyright held by Naomi Carrigan.

See PRIVACY.md for privacy policy information.

See TERMS.md for terms of service.

See SECURITY.md for security policy and vulnerability reporting procedures.

This section is for documentation related to contributing to the Application’s codebase.

  1. Read our Code of Conduct
  2. Review our Contributing Guidelines
  3. Fork the repository
  4. Create a feature branch
  5. Make your changes
  6. Submit a Pull Request
  • Follow the existing code style enforced by ESLint
  • Ensure TypeScript compilation passes without errors
  • Add appropriate JSDoc comments for new public methods
  • Test your changes thoroughly

If you encounter bugs or have feature requests:

  1. Check existing issues first
  2. Create a new issue with detailed information
  3. Include reproduction steps for bugs
  4. Tag issues appropriately