1.0.5 • Published 12 months ago

@mr_fozan/log.js v1.0.5

Weekly downloads
-
License
ISC
Repository
github
Last release
12 months ago

@mr_fozan/log.js

A logging library for Node.js using Mongoose and MongoDB. This library allows you to easily create and retrieve log entries in your MongoDB database.

Features

  • Flexible Logging: Create log entries with custom fields.
  • Date Handling: Automatically records the timestamp of log entries.
  • Model-based: Utilizes Mongoose for schema definition and data management.

Installation

To install the library, use npm or yarn:

npm install @mr_fozan/log.js

or

yarn add @mr_fozan/log.js

Usage

Setting Up

First, require the library and configure it with your MongoDB connection string and model name.

const Log = require('@mr_fozan/log.js');

// Initialize the Log class with your database configuration
const log = new Log({
    databaseKey: 'your-mongodb-connection-string',
    name: 'Log' // Model name
});

Creating a Log Entry

Use the create method to add new log entries.

const params = {
    ids: [1, 2, 3], // Example IDs
    text: 'This is a log entry'
};

log.create(params)
    .then(createdLog => {
        console.log('Log entry created:', createdLog);
    })
    .catch(error => {
        console.error('Error creating log entry:', error);
    });

Retrieving Log Entries

Use the get method to find log entries by ID.

const idToSearch = 1;

log.get(idToSearch)
    .then(logs => {
        console.log('Found logs:', logs);
    })
    .catch(error => {
        console.error('Error retrieving logs:', error);
    });

API

Log

  • Constructor

    • new Log({ databaseKey, name })
      • databaseKey (string): The MongoDB connection string.
      • name (string): The name of the Mongoose model.
  • create(params)

    • Parameters
      • params (Object): Parameters for the log entry.
        • ids (Array): An array of IDs associated with the log entry.
        • text (string): The log message.
        • date (number, optional): The timestamp of the log entry.
    • Returns: A promise that resolves to the created log entry.
  • get(id)

    • Parameters
      • id (string): The ID to search for in the logs.
    • Returns: A promise that resolves to an array of log entries that match the ID.

License

This project is licensed under the ISC License - see the LICENSE file for details.

Contact

For any questions or support, please open an issue on the GitHub repository.

You can copy and paste this content into a file named README.md in your project directory. Make sure to update the placeholder values, such as 'your-mongodb-connection-string', with actual information relevant to your project.

1.0.5

12 months ago

1.0.4

12 months ago

1.0.3

12 months ago

1.0.2

12 months ago

1.0.1

12 months ago

1.0.0

12 months ago