Code Monkey home page Code Monkey logo

winston-prisma-transporter's Introduction

winston-prisma-transporter

Prisma transport for [email protected] logger

Installation

base dependencies:

npm install --save winston-prisma-transporter
# OR
pnpm add winston-prisma-transporter  

peer dependencies:

npm install --save winston @prisma/client
# OR
pnpm add winston @prisma/client

Usage

Create models:

generator client {
  provider = "prisma-client-js"
}

datasource db {
  provider = "mysql"
  url      = env("DATABASE_URL")
}

model UserLog {
  id        Int      @id @default(autoincrement()) @db.UnsignedInt
  timestamp DateTime @default(now()) @db.Timestamp(0)
  level     String   @db.Text
  message   String   @db.Text
  meta      Json?
}

Run your prisma migrations and you're ready to go!

Setup with default configs:

import { createLogger, format } from "winston";
import { PrismaClient } from "@prisma/client";
import { PrismaWinstonTransporter } from "winston-prisma-transporter";

const prisma = new PrismaClient();   
const logger = winston.createLogger({
  transports: [
    format: format.json(),
    new PrismaWinstonTransporter({
      level: "http",
      prisma
    }),
  ],
});

Customizations

Out of the box, the logger will log all levels to the Table called UserLog. That can be changed to a different table by passing in the custom table name.

import { createLogger, format } from "winston";
import { PrismaClient } from "@prisma/client";
import { PrismaWinstonTransporter } from "winston-prisma-transporter";

const prisma = new PrismaClient();   
const logger = winston.createLogger({
  transports: [
    format: format.json(),
    new PrismaWinstonTransporter({
      level: "http",
      prisma,
      tableName: "CustomTableName"
    }),
  ],
});

All options avaliable while initiating the transport:

export interface PrismaTransporterOptions extends TransportStreamOptions {
  prisma: PrismaClient;
  tableName?: string;
}

ToDos:

  • Add tests
  • Add eslint support
  • Add ci/cd for tests
  • Add ci/cd for code qul check

winston-prisma-transporter's People

Contributors

wallexd avatar renovate[bot] avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.