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

@intelika/logger

v1.2.0

Published

Nestjs logger module designed by intelika-ai team

Downloads

59

Readme

@intelika/logger

Streamline your app's logging with @Intelika/logger, the ultimate tool for sending logs to Discord, Telegram, and beyond with just one line of code.

Installation

Use the package manager of your choice to install the package:

npm:

npm install @intelika/logger

yarn:

yarn add @intelika/logger

Emitters

Usage

the package can be used in any JavaScript or TypeScript project. Here are some examples of how to use it in different environments.

[!NOTE] The package is designed to be used with TypeScript, but it can also be used in JavaScript projects.

Nest.js

import { Module } from '@nestjs/common';
import { LogModule } from '@intelika/logger';

@Module({
    imports: [
       LogModule.forRoot({
            isGlobal: true,
            discordWebhook:  'https://discord.com/api/webhooks/...' // optional
        }),
    ],
  providers: [],
  exports: [],
})
export class AppModule {}

// cats.service.ts

import { Injectable } from '@nestjs/common';
import { LogService } from '@intelika/logger';

@Injectable()
export class CatsService {
  constructor(private readonly logger: LogService) {}

    findAll(): string {
        this.logger.log(message).context(CatsService.name).into(Emitter.CONSOLE)
        return 'This action returns all cats';
    }

    findOne(id: number): string {
        this.logger.log(message).context("findOne").into(Emitter.DISCORD)
        return `This action returns a #${id} cat`;
    }
}

everywhere else

import { LogService, Emitter } from '@intelika/logger';

const logger = new LogService('myContext');

// --- OR --- 

// const logger = new LogService({
//   context: 'myContext',
//   discordWebhook: 'https://discord.com/api/webhooks/...'
// })

// const logger = new LogService({
//   telegram: {
//     chatId: '1234567890',
//     token: '1234567890:ABC-DEF1234ghIkl-zyx57W2v1u123ew11'
//   },
//   context: 'myContext'
// })

// const logger = new LogService(bootstrap.name)

// Log a message to the console
logger.log('Hello, world!').into(Emitter.CONSOLE);

// Log a warning to Discord
logger.warn('Something might be wrong...').into(Emitter.DISCORD);

// Log an error to Telegram
logger.error('Something went wrong!').into(Emitter.TELEGRAM);

[!TIP]

 const logger = new LogService({
  telegram: {
    chatId: '1234567890',
    token: '1234567890:ABC-DEF1234ghIkl-zyx57W2v1u123ew11'
  },
  context: 'myContext'
})

you can use the telegram emitter by providing the chatId and the token of your bot.

[!TIP]

 const logger = new LogService({
  discordWebhook: 'https://discord.com/api/webhooks/...',
  context: 'myContext'
})

you can use the discord emitter by providing the webhook url.

[!TIP]

const logService = new LogService('TestContext', {
 file: {
   path: './logs',
   includeDateInFilename: true,
   fileFormat: 'log',
   messageFormat: 'DATE - LEVEL | CONTEXT | MESSAGE'
 }
})

you can use the file emitter by providing the path of the file, the file format, and the message format.

Examples

you can find more examples in the examples directory.

API

LogService

The main class of the package. Use it to create a new logger.

constructor(context: string | OptionsWithContext)

Creates a new logger. The context can be a string or an object with options.

log(...msg: any[])

Logs a message with the level 'INFO'.

warn(...msg: any[])

Logs a message with the level 'WARN'.

error(...msg: any[])

Logs a message with the level 'ERROR'.

Message

This class is used internally to create a new message.

context(context: string)

Sets the context of the message.

is(level: LogLevel)

Sets the level of the message.

into(emitter: Emitter)

Sends the message to the specified emitter.

Emitters

The package supports the following emitters:

  • CONSOLE: Logs the message to the console.
  • DISCORD: Sends the message to a Discord channel.
  • TELEGRAM: Sends the message to a Telegram chat.
  • FILE: Logs the message to a file.

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

License

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