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

logify-ts

v1.0.0

Published

A powerful and flexible logging library for JS/TS projects

Downloads

3

Readme

Features 🚀

  • 🔴 Multiple log levels (ERROR, WARN, INFO, DEBUG)
  • 🎨 Customizable formatters (Text and JSON)
  • 🔌 Extensible transport system (Console and File included)
  • ⚙️ Fully configurable
  • 📱 React and Next.js(and any JS lib) friendly
  • 🛡️ Written in TypeScript for type safety

Installation 📦

npm install logify-ts

Quick Start 🏃‍♂️

Here's an example of how to use the logger in a Next.js API route:

  1. Create a file called logger.ts
your-project
    |_ app 
    |_ public
    |_ logger.ts 👈

Add the following code in logger.ts file

import { Logger, LogLevel, ConsoleTransport, FileTransport, JsonFormatter } from 'logify-ts';

export const logger = new Logger({
    level: LogLevel.DEBUG,
    transports: [
        new ConsoleTransport(),
        new FileTransport('app.log', new JsonFormatter())
    ]
});

[!NOTE] Logify is a flexible logging library that allows you to easily configure multiple transports and formatters for your logs.

  1. Use logger in an API route Create a file api/test/route.ts inside app dir
your-project
    |_ app 
    |  |_api 👈
    |    |_test 👈
    |       |_route.ts 👈
    |
    |_ public
    |_ logger.ts 
import { logger } from "@/logger";
import { NextRequest, NextResponse } from "next/server";

export async function GET(req: NextRequest) {
    logger.info(`Incoming GET request to /api/logger`);

    // Log request details
    logger.debug('Request details', {
        url: req.url,
        method: req.method,
        headers: Object.fromEntries(req.headers),
    });

    // Log query parameters
    const searchParams = req.nextUrl.searchParams;
    logger.debug('Query parameters', Object.fromEntries(searchParams));

    try {
        // Simulate some processing
        const result = await someAsyncOperation();

        logger.info('Operation successful', { result });

        return NextResponse.json({
            message: "success",
            status: 200,
            data: result
        });
    } catch (error) {
        logger.error('Error in GET /api/logger', {
            error: error instanceof Error ? error.message : 'Unknown error',
            stack: error instanceof Error ? error.stack : undefined
        });

        return NextResponse.json({
            message: "Internal server error",
            status: 500,
        }, { status: 500 });
    } finally {
        logger.debug('Request processing completed');
    }
}

async function someAsyncOperation() {
    await new Promise(resolve => setTimeout(resolve, 100));
    return { key: 'value' };
}

[!NOTE] This example provides a practical, real-world use case of your logger in a Next.js API route. It's concise yet informative, showing how to log different types of information at various stages of request processing.

🤝 Contributing

Contributions are what make the open-source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

  • Fork the Project
  • Create your Feature Branch (git checkout -b feature/AmazingFeature)
  • Commit your Changes (git commit -m 'Add some AmazingFeature')
  • Push to the Branch (git push origin feature/AmazingFeature)
  • Open a Pull Request

License 📄

LogSage is MIT licensed. See the LICENSE file for details.

Support 🆘

If you encounter any issues or have questions, please file an issue on GitHub issue tracker.

Built with ❤️ by mutasim

Happy Logging! 🎉