Skip to content

Commit

Permalink
chore: Update logger import paths in multiple files
Browse files Browse the repository at this point in the history
  • Loading branch information
wajeht committed Sep 7, 2024
1 parent bed3990 commit 5b76ba3
Show file tree
Hide file tree
Showing 16 changed files with 50 additions and 42 deletions.
3 changes: 1 addition & 2 deletions src/db/knexfile.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import path from 'node:path';
import { logger } from '../utils';
import type { Knex } from 'knex';
import { databaseConfig, appConfig } from '../config';

Expand All @@ -24,7 +23,7 @@ const knexConfig: Knex.Config = {
min: 2,
max: 10,
afterCreate: (conn: any, done: (err: Error | null, conn: any) => void) => {

Check warning on line 25 in src/db/knexfile.ts

View workflow job for this annotation

GitHub Actions / ESLint (22.x)

Unexpected any. Specify a different type

Check warning on line 25 in src/db/knexfile.ts

View workflow job for this annotation

GitHub Actions / ESLint (22.x)

Unexpected any. Specify a different type
logger.info('New database connection established');
console.log('New database connection established');
done(null, conn);
},
},
Expand Down
2 changes: 1 addition & 1 deletion src/db/redis.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Redis from 'ioredis';
import { logger } from '../utils';
import { logger } from '../logger';
import RedisMock from 'ioredis-mock';
import { redisConfig } from '../config';

Expand Down
3 changes: 2 additions & 1 deletion src/jobs/channel/discord.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { DiscordNotificationJobData } from '../discord.job';
import { secret, logger } from '../../utils';
import { secret } from '../../utils';
import { logger } from '../../logger';

type Params = {
username: string;
Expand Down
3 changes: 2 additions & 1 deletion src/jobs/channel/email.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import nodemailer from 'nodemailer';
import { EmailNotificationJobData } from '../email.job';
import { secret, logger } from '../../utils';
import { secret } from '../../utils';
import { logger } from '../../logger';

function template(username: string, message: string, details: Record<string, any> | null) {
return `
Expand Down
2 changes: 1 addition & 1 deletion src/jobs/channel/notification.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { db } from '../../db/db';
import { logger } from '../../utils';
import { logger } from '../../logger';
import { sendEmailNotificationJob } from '../email.job';
import { NotificationJobData } from '../notification.job';
import { sendDiscordNotificationJob } from '../discord.job';
Expand Down
2 changes: 1 addition & 1 deletion src/jobs/channel/sms.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { logger } from '../../utils';
import { logger } from '../../logger';
import twilio from 'twilio';
import { SmsNotificationJobData } from '../sms.job';

Expand Down
2 changes: 1 addition & 1 deletion src/jobs/discord.job.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { logger } from '../utils';
import { logger } from '../logger';
import { sendDiscord } from './channel/discord';
import { setupJob } from '../utils';
import { DiscordConfig } from 'types';
Expand Down
3 changes: 2 additions & 1 deletion src/jobs/email.job.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { sendEmail } from './channel/email';
import { setupJob, logger } from '../utils';
import { setupJob } from '../utils';
import { logger } from '../logger';
import { EmailConfig } from '../types';

export interface EmailNotificationJobData {
Expand Down
4 changes: 2 additions & 2 deletions src/jobs/general-email.job.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { sendGeneralEmail } from '../utils';
import { setupJob, logger } from '../utils';
import { setupJob, sendGeneralEmail } from '../utils';
import { logger } from '../logger';

export interface GeneralEmailJobData {
email: string;
Expand Down
3 changes: 2 additions & 1 deletion src/jobs/notification.job.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { sendNotification } from './channel/notification';
import { setupJob, logger } from '../utils';
import { setupJob } from '../utils';
import { logger } from '../logger';

export interface NotificationJobData {
userId: number;
Expand Down
3 changes: 2 additions & 1 deletion src/jobs/reset-user-monthly-alert-limit.job.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { db } from '../db/db';
import { setupJob, dayjs, logger } from '../utils';
import { setupJob, dayjs } from '../utils';
import { logger } from '../logger';
import { sendGeneralEmailJob } from './general-email.job';

export const resetUserMonthlyAlertLimitJob = setupJob<any>(
Expand Down
3 changes: 2 additions & 1 deletion src/jobs/sms.job.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { sendSms } from './channel/sms';
import { setupJob, logger } from '../utils';
import { setupJob } from '../utils';
import { logger } from '../logger';
import { SmsConfig } from '../types';

export interface SmsNotificationJobData {
Expand Down
27 changes: 27 additions & 0 deletions src/logger.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import pino from 'pino';
import path from 'node:path';
import pretty from 'pino-pretty';

export const logger = pino(
{
level: process.env.PINO_LOG_LEVEL || 'info',
formatters: {
level: (label) => ({ level: label }),
},
timestamp: pino.stdTimeFunctions.isoTime,
},
pino.multistream([
{
stream: pino.destination(
`${path.resolve(process.cwd())}/logs/${new Date().toISOString().split('T')[0]}.log`,
),
},
{
stream: pretty({
translateTime: 'yyyy-mm-dd HH:MM:ss TT',
colorize: true,
ignore: 'hostname,pid',
}),
},
]),
);
3 changes: 2 additions & 1 deletion src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import helmet from 'helmet';
import { db, redis } from './db/db';
import { csrfSync } from 'csrf-sync';
import session from 'express-session';
import { verifyApiKey, logger } from './utils';
import { verifyApiKey } from './utils';
import { logger } from './logger';
import { NotFoundError } from './error';
import rateLimit from 'express-rate-limit';
import connectRedisStore from 'connect-redis';
Expand Down
3 changes: 2 additions & 1 deletion src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { Server } from 'http';
import { AddressInfo } from 'net';
import { appConfig } from './config';
import { db, redis } from './db/db';
import { runMigrations, logger } from './utils';
import { runMigrations } from './utils';
import { logger } from './logger';
import { resetUserMonthlyAlertLimitJob } from './jobs/reset-user-monthly-alert-limit.job';

const server: Server = app.listen(appConfig.port);
Expand Down
26 changes: 0 additions & 26 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import qs from 'qs';
import ejs from 'ejs';
import pino from 'pino';
import axios from 'axios';
import crypto from 'crypto';
import path from 'node:path';
import jwt from 'jsonwebtoken';
import pretty from 'pino-pretty';
import dayjsModule from 'dayjs';
import fs from 'node:fs/promises';
import { Redis } from 'ioredis';
Expand All @@ -18,30 +16,6 @@ import timezone from 'dayjs/plugin/timezone';
import { appConfig, emailConfig, oauthConfig } from './config';
import { GithubUserEmail, GitHubOauthToken, ApiKeyPayload } from './types';

export const logger = pino(
{
level: process.env.PINO_LOG_LEVEL || 'info',
formatters: {
level: (label) => ({ level: label }),
},
timestamp: pino.stdTimeFunctions.isoTime,
},
pino.multistream([
{
stream: pino.destination(
`${path.resolve(process.cwd())}/logs/${new Date().toISOString().split('T')[0]}.log`,
),
},
{
stream: pretty({
translateTime: 'yyyy-mm-dd HH:MM:ss TT',
colorize: true,
ignore: 'hostname,pid',
}),
},
]),
);

export function dayjs(date: string | Date = new Date()) {
dayjsModule.extend(utc);
dayjsModule.extend(timezone);
Expand Down

0 comments on commit 5b76ba3

Please sign in to comment.