Skip to content

Commit 69ad22f

Browse files
committed
Cleans up all console logs.
Only unimportant things remain, which should be cleaned up in the future.
1 parent 8e2a0a2 commit 69ad22f

File tree

12 files changed

+54
-73
lines changed

12 files changed

+54
-73
lines changed

functions/achievements-background.mts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import BikeTagClient, { Achievement, Game, Player, Tag } from 'biketag'
22
import { getSupportedGames } from '../src/common'
3-
import { getBikeTagClientOpts } from './common'
3+
import { getBikeTagClientOpts, log } from './common'
44
import { HttpStatusCode } from './common/constants'
55
import { BackgroundProcessResults } from './common/types'
66

@@ -60,13 +60,13 @@ export const assignAchievements = async (): Promise<BackgroundProcessResults> =>
6060
if (players.length > 20) {
6161
/// Only award achievements if at least 20 players have logged in
6262
} else {
63-
console.log(`[${game.name}] does not have enough players to award achievements`)
63+
log(`[${game.name}] does not have enough players to award achievements`, { playersCount: players.length }, 'warn')
6464
}
6565
}
6666
}
6767
}
6868
} else {
69-
console.log('couldnt get games', gamesResponse)
69+
log('couldnt get games', gamesResponse, 'error')
7070
}
7171

7272
return {
@@ -79,12 +79,12 @@ export default async (req: Request) => {
7979
const { results, errors } = await assignAchievements()
8080

8181
if (results.length) {
82-
console.log('achievements assigning attempted', { results })
82+
log('achievements assigning attempted', { results }, 'info')
8383
return new Response(JSON.stringify(results), {
8484
status: errors ? HttpStatusCode.BadRequest : HttpStatusCode.Ok,
8585
})
8686
} else {
87-
console.log('nothing to report')
87+
log('nothing to report')
8888
return new Response('', {
8989
status: errors ? HttpStatusCode.BadRequest : HttpStatusCode.Ok,
9090
})

functions/autopost-background.mts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
getActiveQueueForGame,
44
getBikeTagClientOpts,
55
getWinningTagForCurrentRound,
6+
log,
67
setNewBikeTagPost,
78
} from './common'
89
import { HttpStatusCode } from './common/constants'
@@ -17,7 +18,6 @@ export const autoPostNewBikeTags = async (): Promise<BackgroundProcessResults> =
1718
}
1819

1920
// if (!isRequestAllowed()) {}
20-
console.log('Running autoPostNewBikeTags')
2121

2222
const adminBiketagOpts = getBikeTagClientOpts(
2323
{ method: 'get' } as unknown as Request,
@@ -47,10 +47,10 @@ export const autoPostNewBikeTags = async (): Promise<BackgroundProcessResults> =
4747
: 0
4848

4949
if (autoPostSetting === 0) {
50-
console.log('autopost not set, skipping game', game.name)
50+
log('autopost not set, skipping game', game.name)
5151
continue
5252
} else {
53-
console.log(`autopost set to ${autoPostSetting} minutes, checking game`, game.name)
53+
log(`autopost set to ${autoPostSetting} minutes, checking game`, game.name, 'info')
5454
}
5555

5656
const thisGameConfig = {
@@ -67,7 +67,7 @@ export const autoPostNewBikeTags = async (): Promise<BackgroundProcessResults> =
6767
const activeQueue = await getActiveQueueForGame(game, nonAdminBiketag)
6868

6969
if (activeQueue.completedTags.length && activeQueue.timedOutTags.length === 0) {
70-
console.log('completed tags found but none timed out', { game, activeQueue })
70+
log('completed tags found but none timed out', { game, activeQueue }, 'info')
7171
} else if (activeQueue.completedTags.length && activeQueue.timedOutTags.length) {
7272
const currentBikeTagResponse = await adminBiketag.getTag(undefined, { source: imageSource }) // the "current" mystery tag to be updated from the main album
7373
if (!currentBikeTagResponse.success) {
@@ -88,10 +88,10 @@ export const autoPostNewBikeTags = async (): Promise<BackgroundProcessResults> =
8888
)
8989

9090
if (autoSelectedWinningTag) {
91-
console.log('winning tag found, setting new BikeTag post', {
91+
log('winning tag found, setting new BikeTag post', {
9292
game: game.slug,
9393
autoSelectedWinningTag,
94-
})
94+
}, 'info')
9595
const setNewBikeTagPostResults = await setNewBikeTagPost(
9696
game,
9797
autoSelectedWinningTag,
@@ -106,7 +106,7 @@ export const autoPostNewBikeTags = async (): Promise<BackgroundProcessResults> =
106106
}
107107
}
108108
} else {
109-
console.log('couldnt get games', gamesResponse)
109+
log('couldnt get games', gamesResponse, 'error')
110110
}
111111

112112
return {
@@ -119,13 +119,13 @@ export default async () => {
119119
const { results, errors } = await autoPostNewBikeTags()
120120

121121
if (results.length) {
122-
console.log('autopost attempted', { results })
122+
log('autopost attempted', { results }, 'info')
123123

124124
return new Response(JSON.stringify(results), {
125125
status: errors ? HttpStatusCode.BadRequest : HttpStatusCode.Ok,
126126
})
127127
} else {
128-
console.log('nothing to report')
128+
log('nothing to report', 'info')
129129
return new Response('', {
130130
status: errors ? HttpStatusCode.BadRequest : HttpStatusCode.Ok,
131131
})

functions/autopost-clear.mts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
getActiveQueueForGame,
55
getBikeTagClientOpts,
66
isRequestAllowed,
7+
log,
78
} from './common'
89
import { HttpStatusCode } from './common/constants'
910
import { BackgroundProcessResults } from './common/types'
@@ -44,7 +45,7 @@ export const autoClearQueue = async (req: Request): Promise<BackgroundProcessRes
4445
if (twentyFourHoursAgo > mostRecentTag.mysteryTime * 1000 && !forceClear) {
4546
const errorMessage =
4647
'Most recent tag was created more than 24 hours ago. Please clear the queue manually.'
47-
console.log(errorMessage)
48+
log('cannot continue', errorMessage, 'error')
4849
return {
4950
results: [errorMessage],
5051
errors: true,
@@ -55,7 +56,7 @@ export const autoClearQueue = async (req: Request): Promise<BackgroundProcessRes
5556
const allTags = (await nonAdminBiketag.getQueue({ game: adminBiketagOpts.game }, { source: imageSource })).data
5657

5758
if (allTags.length) {
58-
console.log('all tags found', { game, allTags })
59+
log('all tags found', { game, allTags }, 'info')
5960
const archiveAndClearQueueResults = await archiveAndClearQueue(
6061
allTags,
6162
game,
@@ -67,14 +68,14 @@ export const autoClearQueue = async (req: Request): Promise<BackgroundProcessRes
6768
errors = archiveAndClearQueueResults.errors
6869
} else {
6970
const nothingToDoMessage = 'no tags found'
70-
console.log(nothingToDoMessage)
71+
log('nothing to do', nothingToDoMessage)
7172
results.push(nothingToDoMessage)
7273
}
7374
} else {
7475
const { queuedTags } = await getActiveQueueForGame(game, adminBiketag)
7576

7677
if (queuedTags.length) {
77-
console.log('non-winning tag(s) found', { game, queuedTags })
78+
log('non-winning tag(s) found', { game, queuedTags })
7879
const archiveAndClearQueueResults = await archiveAndClearQueue(
7980
queuedTags,
8081
game,
@@ -86,7 +87,7 @@ export const autoClearQueue = async (req: Request): Promise<BackgroundProcessRes
8687
errors = archiveAndClearQueueResults.errors
8788
} else {
8889
const nothingToDoMessage = 'no non-winning tags found'
89-
console.log(nothingToDoMessage)
90+
log('nothing to do', nothingToDoMessage)
9091
results.push(nothingToDoMessage)
9192
}
9293
}
@@ -101,13 +102,13 @@ export default async (req: Request) => {
101102
const { results, errors } = await autoClearQueue(req)
102103

103104
if (results.length) {
104-
console.log('queue cleared', { results })
105+
log('queue cleared', { results }, 'info')
105106

106107
return new Response(JSON.stringify(results), {
107108
status: errors ? HttpStatusCode.BadRequest : HttpStatusCode.Ok,
108109
})
109110
} else {
110-
console.log('queue not cleared')
111+
log('queue not cleared', 'no results found', 'error')
111112
return new Response('', {
112113
status: errors ? HttpStatusCode.BadRequest : HttpStatusCode.Ok,
113114
})

functions/autopost-notify.mts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import BikeTagClient, { Game } from 'biketag'
2-
import { BackgroundProcessResults, getBikeTagClientOpts, getPayloadOpts, isRequestAllowed, sendNewBikeTagNotifications } from './common'
2+
import { BackgroundProcessResults, getBikeTagClientOpts, getPayloadOpts, isRequestAllowed, log, sendNewBikeTagNotifications } from './common'
33
import { HttpStatusCode } from './common/constants'
44

55
export const autoNotifyNewBikeTagPosted = async (req: Request): Promise<BackgroundProcessResults> => {
@@ -37,7 +37,7 @@ export const autoNotifyNewBikeTagPosted = async (req: Request): Promise<Backgrou
3737
)
3838
if (twoMostRecentTags.data?.length !== 2) {
3939
const errorMessage = 'Could not retrieve two most recent tags.'
40-
console.log(errorMessage, { twoMostRecentTags })
40+
log(errorMessage, { twoMostRecentTags }, 'error')
4141
return {
4242
results: [errorMessage],
4343
errors: true,
@@ -49,7 +49,7 @@ export const autoNotifyNewBikeTagPosted = async (req: Request): Promise<Backgrou
4949

5050
if (twentyFourHoursAgo > winningTag.mysteryTime * 1000 && !payloadOpts.force) {
5151
const errorMessage = 'Most recent tag was created more than 24 hours ago.'
52-
console.log(errorMessage)
52+
log('cannot continue', errorMessage, 'error')
5353
return {
5454
results: [errorMessage],
5555
errors: true,
@@ -66,14 +66,14 @@ export const autoNotifyNewBikeTagPosted = async (req: Request): Promise<Backgrou
6666
payloadOpts.skipEmails,
6767
payloadOpts.skipSocials,
6868
).catch((err) => {
69-
console.log('error sending notifications', err)
69+
log('error sending notifications', err, 'error')
7070
})
7171

7272
if (notificationsSent?.length) {
7373
results = await Promise.allSettled(notificationsSent)
7474
.then((r) => r.map((p: any) => p.value))
7575
.catch((e) => {
76-
console.log('error sending notifications', { e })
76+
log('error sending notifications', { e }, 'error')
7777
return []
7878
})
7979
}
@@ -88,12 +88,12 @@ export default async (req: Request) => {
8888
const { results, errors } = await autoNotifyNewBikeTagPosted(req)
8989

9090
if (results.length) {
91-
console.log('notifications sent', { results })
91+
log('notifications sent', { results }, 'info')
9292
return new Response(JSON.stringify(results), {
9393
status: errors ? HttpStatusCode.BadRequest : HttpStatusCode.Ok
9494
})
9595
} else {
96-
console.log('no notifications sent')
96+
log('no notifications sent', 'info')
9797
return new Response('', {
9898
status: errors ? HttpStatusCode.BadRequest : HttpStatusCode.Ok,
9999
})

functions/common/methods.ts

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,7 @@ export const sendEmail = async (to: string, subject: string, locals: any, templa
733733
}
734734

735735
if (!html.length) {
736-
console.log(ErrorMessage.NoHtmlLoaded, { templateFilePath, htmlTemplateFilePath })
736+
log(ErrorMessage.NoHtmlLoaded, { templateFilePath, htmlTemplateFilePath }, 'error')
737737
return null
738738
}
739739

@@ -791,7 +791,7 @@ export const sendEmailsToAmbassadors = async (
791791

792792
for (const ambassador of ambassadors) {
793793
if (ambassador.email) {
794-
console.log(`sending ${emailName} email to BikeTag Ambassador: ${ambassador.email}`)
794+
log(`sending ${emailName} email to BikeTag Ambassador`, { email: ambassador.email }, 'info')
795795
emailSent = await sendEmail(
796796
ambassador.email,
797797
emailSubject,
@@ -808,7 +808,7 @@ export const sendEmailsToAmbassadors = async (
808808
if (sendToAdmin) {
809809
const biketagAdminEmail = process.env.ADMIN_EMAIL ?? ''
810810
if (biketagAdminEmail?.length) {
811-
console.log(`sending ${emailName} email to BikeTag Administrator: ${biketagAdminEmail}`)
811+
log(`sending ${emailName} email to BikeTag Administrator:`, {biketagAdminEmail}, 'info')
812812
emailSent = await sendEmail(
813813
biketagAdminEmail,
814814
emailSubject,
@@ -1094,7 +1094,7 @@ export const handleAuth0ProfileRequest = async (req: Request, profile: any): Pro
10941094
const biketagAdminOpts = getBikeTagClientOpts(req, true)
10951095

10961096
/// Create the player profile in sanity
1097-
console.log('creating the player in sanity', { data, biketagAdminOpts })
1097+
log('creating the player in sanity', { data, biketagAdminOpts })
10981098
const updatedPlayerResponse = await createBikeTagPlayerProfile(
10991099
data,
11001100
biketagAdminOpts.game,
@@ -1151,7 +1151,7 @@ export const handleAuth0ProfileRequest = async (req: Request, profile: any): Pro
11511151
}
11521152
} else {
11531153
/// Invalid data
1154-
console.log(ErrorMessage.InvalidRequestData, data, profileType)
1154+
log(ErrorMessage.InvalidRequestData, { data, profileType }, 'error')
11551155
body = ErrorMessage.InvalidRequestData
11561156
statusCode = HttpStatusCode.BadRequest
11571157
}
@@ -1180,7 +1180,7 @@ export const handleAuth0ProfileRequest = async (req: Request, profile: any): Pro
11801180
if (typeof response.data === 'string') {
11811181
body = response.data
11821182
} else if (Array.isArray(response.data)) {
1183-
if (response.data?.length) console.log('well how did this happen?')
1183+
if (response.data?.length) log('well how did this happen?', { 'response.data': response.data }, 'warn')
11841184
body = ''
11851185
} else {
11861186
const profileDataResponse = profile.isBikeTagAmbassador
@@ -1302,7 +1302,7 @@ const uploadImageToBlueSkyFromURL = async (agent: AtpAgent, url: string) => {
13021302

13031303
const uploadResponse = await agent.uploadBlob(img)
13041304
if (!uploadResponse.success) {
1305-
console.log(ErrorMessage.ImageUploadFailed, { uploadResponse })
1305+
log(ErrorMessage.ImageUploadFailed, { uploadResponse }, 'error')
13061306
throw new Error(ErrorMessage.ImageUploadFailed)
13071307
}
13081308
return uploadResponse.data.blob
@@ -1330,7 +1330,7 @@ export const sendBikeTagPostNotificationToBlueSky = async (
13301330
const bskyPass = process.env.BSKY_PASS
13311331
const bskyServer = process.env.BSKY_SERVER ?? 'https://bsky.social'
13321332

1333-
console.log('sending bluesky on behalf of ' + bskyUser)
1333+
log('sending bluesky on behalf of ' + bskyUser, {winningTagnumber, bskyUser})
13341334

13351335
const agent = new AtpAgent({
13361336
service: bskyServer,
@@ -1377,7 +1377,7 @@ export const sendBikeTagPostNotificationToBlueSky = async (
13771377
return `bluesky::${postCreated.cid}`
13781378
}
13791379
} catch (e: any) {
1380-
console.log({ blueskyError: e })
1380+
log('error sending bluesky notification', { blueskyError: e }, 'error')
13811381
}
13821382

13831383
return `bluesky::failed`
@@ -1406,13 +1406,11 @@ export const sendBikeTagPostNotificationToWebhook = (
14061406
const mysteryImageUrl = getImageSized(imageSource, winningTag.mysteryImageUrl, 'l')
14071407
const foundImageUrl = getImageSized(imageSource, currentTag.foundImageUrl, 'l')
14081408

1409-
if (process.env.DEBUG_A === 'true') {
1410-
console.log('sending notification webhook timestamp', {
1411-
timestamp,
1412-
foundTime: currentTag.foundTime,
1413-
tz: game.region.tz,
1414-
})
1415-
}
1409+
log('sending notification webhook timestamp', {
1410+
timestamp,
1411+
foundTime: currentTag.foundTime,
1412+
tz: game.region.tz,
1413+
})
14161414

14171415
let data = {}
14181416
switch (type) {
@@ -1776,7 +1774,7 @@ const getAuthManagementToken = async () => {
17761774
// client_secret: process.env.A_M_CS,
17771775
// audience: process.env.A_AUDIENCE,
17781776
// })
1779-
console.log(ErrorMessage.getAuthManagementToken, e.message)
1777+
log(ErrorMessage.getAuthManagementToken, e.message, 'error')
17801778
}
17811779
}
17821780

0 commit comments

Comments
 (0)