@nhcarrigan/logger
@nhcarrigan/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 centralized alerting system.
1. User Documentation
This section is for those interacting with a live instance of the Application.
Installation
Install the package using your preferred package manager:
npm install @nhcarrigan/logger
pnpm add @nhcarrigan/logger
yarn add @nhcarrigan/logger
Quick Start
import { Logger } from "@nhcarrigan/logger";
// Initialize the loggerconst logger = new Logger("my-app", "your-api-token");
// Send log messagesawait logger.log("info", "Application started successfully");await logger.log("warn", "This is a warning message");await logger.log("debug", "Debug information");
// Send error reportstry { // Your code here} catch (error) { await logger.error("functionName", error);}
API Reference
Constructor
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 serviceurl
(optional string): Custom URL for your own alerting instance (defaults to “https://alerts.nhcarrigan.com”)
Methods
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>
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
Log Levels
The Application supports three log levels:
"debug"
: Debug information for development purposes"info"
: General informational messages"warn"
: Warning messages that don’t halt execution
Custom Alerting Server
By default, the logger sends data to https://alerts.nhcarrigan.com
. You can configure it to use your own alerting instance by providing a custom URL in the constructor.
2. Technical Documentation
This section is for those interested in running their own instance of the Application.
Architecture
The Application is built as a TypeScript class that wraps HTTP requests to an alerting server. It provides two main endpoints:
/log
- For general log messages/error
- For error reporting with stack traces
API Endpoints
POST /log
Sends structured log data:
{ "application": "your-app-name", "level": "info", "message": "Your log message"}
POST /error
Sends structured error data:
{ "application": "your-app-name", "context": "function-name", "message": "Error message", "stack": "Stack trace information"}
Authentication
All requests require an Authorization
header with your API token.
Development Setup
-
Clone the repository:
Terminal window git clone https://git.nhcarrigan.com/nhcarrigan/logger.git -
Install dependencies:
Terminal window pnpm install -
Build the project:
Terminal window pnpm run build -
Run linting:
Terminal window pnpm run lint
Project Structure
src/├── index.ts # Main Logger class└── types/ └── level.ts # Log level type definitions
TypeScript Configuration
The project uses:
@nhcarrigan/typescript-config
for TypeScript configuration@nhcarrigan/eslint-config
for ESLint rules- ES modules (
"type": "module"
)
3. Legal Documentation
This section is for expansions to our legal policies specific to the Application.
License
This software is licensed under Naomi’s Public License. See the LICENSE.md file for complete terms.
Copyright
Copyright held by Naomi Carrigan.
Privacy
See PRIVACY.md for privacy policy information.
Terms of Service
See TERMS.md for terms of service.
Security
See SECURITY.md for security policy and vulnerability reporting procedures.
4. Contributing Documentation
This section is for documentation related to contributing to the Application’s codebase.
Getting Started
- Read our Code of Conduct
- Review our Contributing Guidelines
- Fork the repository
- Create a feature branch
- Make your changes
- Submit a Pull Request
Development Guidelines
- 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
Issue Reporting
If you encounter bugs or have feature requests:
- Check existing issues first
- Create a new issue with detailed information
- Include reproduction steps for bugs
- Tag issues appropriately
Contact
- Chat Server: http://chat.nhcarrigan.com
- Email: [email protected]
- Repository: https://git.nhcarrigan.com/nhcarrigan/logger
- Issues: https://git.nhcarrigan.com/nhcarrigan/logger/issues
Package Information
- Package Name: @nhcarrigan/logger
- Version: 1.0.0
- NPM: https://www.npmjs.com/package/@nhcarrigan/logger
- Repository: Git-based repository hosted at git.nhcarrigan.com