Skip to content

Commit 2d17880

Browse files
Added custom logger lib.
1 parent 366e703 commit 2d17880

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

src/app/api/location/route.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { NextRequest, NextResponse } from 'next/server'
22
import prisma from '@/lib/db'
3-
import { withLogging } from '@/lib/logger'
3+
import { withLogging, logger } from '@/lib/logger'
44

55
export const POST = withLogging(async (request: NextRequest) => {
66
try {
77
const locationData = await request.json()
8-
console.log('locationData', locationData)
8+
logger.info('locationData', locationData)
99
// Validate required fields
1010
if (!locationData) {
11-
console.log('Invalid location data:', locationData)
11+
logger.info('Invalid location data:', locationData)
1212
return NextResponse.json({ error: 'Invalid location data.' }, { status: 400 })
1313
}
1414

@@ -28,7 +28,7 @@ export const POST = withLogging(async (request: NextRequest) => {
2828
})
2929

3030
if (!subscription) {
31-
console.log('Subscription not found for subscriptionId:', locationData.subscriptionId)
31+
logger.info('Subscription not found for subscriptionId:', locationData.subscriptionId)
3232
return NextResponse.json({ error: 'Subscription not found.' }, { status: 404 })
3333
}
3434

@@ -67,14 +67,14 @@ export const POST = withLogging(async (request: NextRequest) => {
6767
},
6868
})
6969

70-
console.log('Location added:', newLocation)
70+
logger.info('Location added:', newLocation)
7171
return NextResponse.json(
7272
{ message: 'Location added successfully.', location: newLocation },
7373
{ status: 201 }
7474
)
7575
} catch (error) {
76-
console.log('Error saving location:', error) //error()
77-
console.log(error.stack)
76+
logger.info('Error saving location:', error) //error()
77+
logger.info(error.stack)
7878
return NextResponse.json({ error: 'Failed to save location.' }, { status: 500 })
7979
} finally {
8080
await prisma.$disconnect()

src/app/api/notifications/mass-notification/route.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import webpush, { WebPushError } from 'web-push'
33
import { messaging } from 'firebase-admin'
44
import { sendNotification, SubscriptionRecord } from '../../../../lib/notifications'
55
import prisma from '@/lib/db'
6-
import { withLogging } from '@/lib/logger'
6+
import { withLogging, logger } from '@/lib/logger'
77

88
export const POST = withLogging(async (request: NextRequest) => {
99
try {
@@ -35,7 +35,7 @@ export const POST = withLogging(async (request: NextRequest) => {
3535

3636
return NextResponse.json({ success: true, message: 'Notifications sent successfully' })
3737
} catch (error) {
38-
console.error('Error sending notifications:', error)
38+
logger.error('Error sending notifications:', error)
3939
return NextResponse.json({ error: 'Internal Server Error' }, { status: 500 })
4040
}
4141
})

src/app/api/notifications/subscribe/route.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { NextRequest, NextResponse } from 'next/server'
22
import prisma from '@/lib/db'
3-
import { withLogging } from '@/lib/logger'
3+
import { withLogging, logger } from '@/lib/logger'
44

55
export const POST = withLogging(async (request: NextRequest) => {
66
try {
77
const subscription = await request.json()
88

9-
console.log('Subscription data:', subscription)
9+
logger.info('Subscription data:', subscription)
1010

1111
// Validate required fields
1212
if (!subscription.endpoint || !subscription.type) {
@@ -71,8 +71,8 @@ export const POST = withLogging(async (request: NextRequest) => {
7171
{ status: 201 }
7272
)
7373
} catch (error) {
74-
console.log(error.stack)
75-
console.log('Error saving subscription:', error)
74+
logger.info(error.stack)
75+
logger.info('Error saving subscription:', error)
7676
return NextResponse.json({ error: 'Failed to save subscription.' }, { status: 500 })
7777
} finally {
7878
await prisma.$disconnect()

0 commit comments

Comments
 (0)