npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@mr_fozan/log.js

v1.0.5

Published

A logging library using Mongoose for MongoDB

Downloads

95

Readme

@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.