Skip to content

Commit

Permalink
chore: add pino
Browse files Browse the repository at this point in the history
  • Loading branch information
larwaa committed Jan 11, 2024
1 parent 6ebbcc3 commit f66ff11
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 11 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
"luxon": "^3.4.4",
"node-fetch": "^3.3.2",
"openid-client": "^5.6.4",
"pino": "^8.17.2",
"postmark": "^4.0.2",
"prisma": "^5.8.0",
"yargs": "^17.7.2",
Expand Down
11 changes: 7 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions src/lib/fastify/logging.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import type { FastifyServerOptions } from "fastify";
import type { PinoLoggerOptions } from "fastify/types/logger.js";
import type { LoggerOptions } from "pino";
import { env } from "~/config.js";

/**
* Redact personally identifiable information (PII) from logs
* to try to be GDPR compliant, and avoid storing sensitive data in logs.
*/
const redact: PinoLoggerOptions["redact"] = [
const redact: LoggerOptions["redact"] = [
"*.firstName",
"*.lastName",
"*.email",
Expand All @@ -17,7 +16,7 @@ const redact: PinoLoggerOptions["redact"] = [

export const envToLogger: Record<
"development" | "production" | "test",
Exclude<FastifyServerOptions["logger"], boolean>
Omit<LoggerOptions, "hooks">
> = {
development: {
enabled: env.LOG_ENABLED,
Expand Down
5 changes: 3 additions & 2 deletions src/services/mail/worker.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { User } from "@prisma/client";
import type { Processor } from "bullmq";
import type { Logger } from "pino";
import type { MailService } from "./index.js";

type UserRepository = {
Expand All @@ -9,16 +10,16 @@ type UserRepository = {
const MailWorker = (
mailService: MailService,
userRepository: UserRepository,
log?: Logger,
): Processor<
{ subject: string; receiverId: string },
{ status: string },
"waitlist" | "welcome"
> => {
return async (job) => {
log?.info({ job: { name: job.name, data: job.data } }, "starting job");
const { subject, receiverId } = job.data;
console.log("sending email", job.name);
const user = await userRepository.get(receiverId);
console.log("Sending email to", user.id);
switch (job.name) {
case "waitlist":
await mailService.send({
Expand Down
4 changes: 3 additions & 1 deletion src/worker.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Worker } from "bullmq";
import { Redis } from "ioredis";
import { pino } from "pino";
import { env } from "./config.js";
import { envToLogger } from "./lib/fastify/logging.js";
import postmark from "./lib/postmark.js";
import prisma from "./lib/prisma.js";
import { UserRepository } from "./repositories/users/index.js";
Expand All @@ -12,7 +14,7 @@ export function initWorkers() {
keepAlive: 1_000 * 60 * 3, // 3 minutes
maxRetriesPerRequest: 0,
});

const logger = pino(envToLogger[env.NODE_ENV]);
const mailService = new MailService(postmark, env.NO_REPLY_EMAIL);
const userRepository = new UserRepository(prisma);
const worker = new Worker<
Expand Down

0 comments on commit f66ff11

Please sign in to comment.