1.0.9 • Published 10 months ago

raven-log v1.0.9

Weekly downloads
-
License
ISC
Repository
-
Last release
10 months ago

Raven Log

A lightweight logging utility for sending logs to a configured endpoint.

Installation

Use the package manager npm to install Raven.

npm install raven-log

Usage

1. Importing and Initializing Raven

To start using Raven, first import it and create an instance with your specific configuration.

import raven, { RavenLog } from 'raven-log';

// Create an instance of Raven with your configuration
const ravenInstance = raven.create({
  apiUrl: 'https://your-backend-api-url', // The backend endpoint for sending logs
  application: 'Your App Name',           // The name of your application
});

2. Creating a Log Entry

Once you have an instance, create individual log entries using the RavenLog class. Each log entry allows for customizable properties.

const ravenLog = new RavenLog({
  shortDescription: 'This is a 404 test log', // Required, brief description of the log
  detailedDescription: 'This is the longer description of the 404 test log which occurred...', // Optional, detailed description
  service: 'Your Service Which Produced The Log', // Optional, name of the service responsible
  level: 2,                                      // Optional, severity level of the log (e.g., 1 = Info, 2 = Warning, 3 = Error)
  user: 'John Doe',                              // Optional, user associated with the log
  path: '/some-super-test-route',                // Optional, route or path related to the log event
  statusCode: 404,                               // Optional, HTTP status code (if applicable)
  timestamp: new Date()                          // Optional default is new Date()
});

3. Using Raven Log

With your log entry created, you can use the following methods with your ravenInstance.

// Display the log in the console
ravenInstance.console(ravenLog);

// Send the log to the backend API specified in the instance's configuration
ravenInstance.send(ravenLog);

// Display the current configuration of the instance in the console
ravenInstance.showConfig();

// Show the Raven logo in the console
ravenInstance.showRavenArt();

Example

import raven, { RavenLog } from 'raven-log';

// Initialize an instance
const ravenInstance = raven.create({
  apiUrl: 'https://your-backend-api-url',
  application: 'Example App',
});

// Create a log entry
const exampleLog = new RavenLog({
  shortDescription: 'Example log entry',
  detailedDescription: 'Detailed information about this log entry...',
  service: 'Example Service',
  level: 1,
  user: 'Alice Doe',
  path: '/example-path',
  statusCode: 400,
});

// Log to console and send to API
ravenInstance.console(exampleLog);
try {
  const response = await ravenInstance.send(exampleLog);
} catch (error) {
  console.error(error);
}

// Display config and show the logo
ravenInstance.showConfig();
ravenInstance.showRavenArt();

Api Reference

create(config): Creates and returns a new Raven instance.
apiUrl (string): The endpoint to send logs to.
application (string): The application name.
console(log): Logs the entry to the console.
send(log): Sends the log to the specified API.
showConfig(): Displays the current instance configuration in the console.
showRavenArt(): Shows the Raven logo art in the console.

License

ISC

1.0.9

10 months ago

1.0.8

10 months ago

1.0.7

10 months ago

1.0.6

10 months ago

1.0.5

10 months ago

1.0.4

10 months ago

1.0.2

10 months ago

1.0.1

10 months ago

1.0.3

10 months ago

1.0.0

11 months ago