Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

winston-prisma-transporter

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

winston-prisma-transporter

Transport Winston logger with Prisma

  • 0.3.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
12
increased by20%
Maintainers
1
Weekly downloads
 
Created
Source

winston-prisma-transporter

Prisma transport for winston@3.x 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

Keywords

FAQs

Package last updated on 02 Oct 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc