]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Refactor AP video logger tags
authorChocobozzz <me@florianbigard.com>
Thu, 3 Jun 2021 14:56:42 +0000 (16:56 +0200)
committerChocobozzz <me@florianbigard.com>
Thu, 3 Jun 2021 14:56:42 +0000 (16:56 +0200)
server/lib/activitypub/videos/refresh.ts
server/lib/activitypub/videos/shared/abstract-builder.ts
server/lib/activitypub/videos/shared/creator.ts
server/lib/activitypub/videos/shared/video-sync-attributes.ts
server/lib/activitypub/videos/updater.ts

index da068cde9eec647215394e1729ef6cc06b256353..71a4e75b0b12520b9a2a8b5cd12b8f8ce2604785 100644 (file)
@@ -8,8 +8,6 @@ import { HttpStatusCode } from '@shared/core-utils'
 import { fetchRemoteVideo, SyncParam, syncVideoExternalAttributes } from './shared'
 import { APVideoUpdater } from './updater'
 
-const lTags = loggerTagsFactory('ap', 'video', 'refresh')
-
 async function refreshVideoIfNeeded (options: {
   video: MVideoThumbnail
   fetchedType: VideoFetchByUrlType
@@ -22,11 +20,13 @@ async function refreshVideoIfNeeded (options: {
     ? options.video as MVideoAccountLightBlacklistAllFiles
     : await VideoModel.loadByUrlAndPopulateAccount(options.video.url)
 
+  const lTags = loggerTagsFactory('ap', 'video', 'refresh', video.uuid, video.url)
+
   try {
     const { videoObject } = await fetchRemoteVideo(video.url)
 
     if (videoObject === undefined) {
-      logger.warn('Cannot refresh remote video %s: invalid body.', video.url, lTags(video.uuid))
+      logger.warn('Cannot refresh remote video %s: invalid body.', video.url, lTags())
 
       await video.setAsRefreshed()
       return video
@@ -42,14 +42,14 @@ async function refreshVideoIfNeeded (options: {
     return video
   } catch (err) {
     if ((err as PeerTubeRequestError).statusCode === HttpStatusCode.NOT_FOUND_404) {
-      logger.info('Cannot refresh remote video %s: video does not exist anymore. Deleting it.', video.url, lTags(video.uuid))
+      logger.info('Cannot refresh remote video %s: video does not exist anymore. Deleting it.', video.url, lTags())
 
       // Video does not exist anymore
       await video.destroy()
       return undefined
     }
 
-    logger.warn('Cannot refresh video %s.', options.video.url, { err, ...lTags(video.uuid) })
+    logger.warn('Cannot refresh video %s.', options.video.url, { err, ...lTags() })
 
     ActorFollowScoreCache.Instance.addBadServerId(video.VideoChannel.Actor.serverId)
 
index f8e4d6aa3aeecbbaffce5448e6f0895344488881..4bd38b40c1834da7f0dcc584cc48167de4684fa5 100644 (file)
@@ -43,7 +43,7 @@ export abstract class APVideoAbstractBuilder {
       video,
       type: ThumbnailType.MINIATURE
     }).catch(err => {
-      logger.warn('Cannot generate thumbnail of %s.', this.videoObject.id, { err, ...this.lTags(video.uuid) })
+      logger.warn('Cannot generate thumbnail of %s.', this.videoObject.id, { err, ...this.lTags() })
 
       return undefined
     })
index ba3f6f77fd416d3fe6f4c09957f68d5393804e8b..767bf06952e347dc31db0e233cfafc8684c7b433 100644 (file)
@@ -1,5 +1,5 @@
 
-import { logger, loggerTagsFactory } from '@server/helpers/logger'
+import { logger, loggerTagsFactory, LoggerTagsFn } from '@server/helpers/logger'
 import { sequelizeTypescript } from '@server/initializers/database'
 import { autoBlacklistVideoIfNeeded } from '@server/lib/video-blacklist'
 import { VideoModel } from '@server/models/video/video'
@@ -9,14 +9,16 @@ import { APVideoAbstractBuilder } from './abstract-builder'
 import { getVideoAttributesFromObject } from './object-to-model-attributes'
 
 export class APVideoCreator extends APVideoAbstractBuilder {
-  protected lTags = loggerTagsFactory('ap', 'video', 'create')
+  protected lTags: LoggerTagsFn
 
   constructor (protected readonly videoObject: VideoObject) {
     super()
+
+    this.lTags = loggerTagsFactory('ap', 'video', 'create', this.videoObject.uuid, this.videoObject.id)
   }
 
   async create (waitThumbnail = false) {
-    logger.debug('Adding remote video %s.', this.videoObject.id, this.lTags(this.videoObject.uuid))
+    logger.debug('Adding remote video %s.', this.videoObject.id, this.lTags())
 
     const channelActor = await this.getOrCreateVideoChannelFromVideoObject()
     const channel = channelActor.VideoChannel
@@ -57,7 +59,7 @@ export class APVideoCreator extends APVideoAbstractBuilder {
           transaction: t
         })
 
-        logger.info('Remote video with uuid %s inserted.', this.videoObject.uuid, this.lTags(videoCreated.uuid))
+        logger.info('Remote video with uuid %s inserted.', this.videoObject.uuid, this.lTags())
 
         return { autoBlacklisted, videoCreated }
       } catch (err) {
index 102d406214f1a8b54a93dbe252ac74e8108e040e..c4e1010054c6a0a1171fc355afba80fd947c41d3 100644 (file)
@@ -62,7 +62,7 @@ function syncRates (type: 'like' | 'dislike', video: MVideo, fetchedVideo: Video
   const cleaner = crawlStartDate => AccountVideoRateModel.cleanOldRatesOf(video.id, type, crawlStartDate)
 
   return crawlCollectionPage<string>(uri, handler, cleaner)
-    .catch(err => logger.error('Cannot add rate of video %s.', video.uuid, { err, rootUrl: uri, ...lTags(video.uuid) }))
+    .catch(err => logger.error('Cannot add rate of video %s.', video.uuid, { err, rootUrl: uri, ...lTags(video.uuid, video.url) }))
 }
 
 function syncShares (video: MVideo, fetchedVideo: VideoObject, isSync: boolean) {
@@ -76,7 +76,7 @@ function syncShares (video: MVideo, fetchedVideo: VideoObject, isSync: boolean)
   const cleaner = crawlStartDate => VideoShareModel.cleanOldSharesOf(video.id, crawlStartDate)
 
   return crawlCollectionPage<string>(uri, handler, cleaner)
-    .catch(err => logger.error('Cannot add shares of video %s.', video.uuid, { err, rootUrl: uri, ...lTags(video.uuid) }))
+    .catch(err => logger.error('Cannot add shares of video %s.', video.uuid, { err, rootUrl: uri, ...lTags(video.uuid, video.url) }))
 }
 
 function syncComments (video: MVideo, fetchedVideo: VideoObject, isSync: boolean) {
@@ -90,5 +90,5 @@ function syncComments (video: MVideo, fetchedVideo: VideoObject, isSync: boolean
   const cleaner = crawlStartDate => VideoCommentModel.cleanOldCommentsOf(video.id, crawlStartDate)
 
   return crawlCollectionPage<string>(uri, handler, cleaner)
-    .catch(err => logger.error('Cannot add comments of video %s.', video.uuid, { err, rootUrl: uri, ...lTags(video.uuid) }))
+    .catch(err => logger.error('Cannot add comments of video %s.', video.uuid, { err, rootUrl: uri, ...lTags(video.uuid, video.url) }))
 }
index 6745e2efd031811165121a30e2edd4c1945347ae..3339611fc02405a121270fdcfa0203fb152fadd6 100644 (file)
@@ -1,6 +1,6 @@
 import { Transaction } from 'sequelize/types'
 import { resetSequelizeInstance } from '@server/helpers/database-utils'
-import { logger, loggerTagsFactory } from '@server/helpers/logger'
+import { logger, loggerTagsFactory, LoggerTagsFn } from '@server/helpers/logger'
 import { sequelizeTypescript } from '@server/initializers/database'
 import { Notifier } from '@server/lib/notifier'
 import { PeerTubeSocket } from '@server/lib/peertube-socket'
@@ -19,7 +19,7 @@ export class APVideoUpdater extends APVideoAbstractBuilder {
 
   private readonly oldVideoChannel: MChannelAccountLight
 
-  protected lTags = loggerTagsFactory('ap', 'video', 'update')
+  protected lTags: LoggerTagsFn
 
   constructor (
     protected readonly videoObject: VideoObject,
@@ -33,12 +33,14 @@ export class APVideoUpdater extends APVideoAbstractBuilder {
     this.oldVideoChannel = this.video.VideoChannel
 
     this.videoFieldsSave = this.video.toJSON()
+
+    this.lTags = loggerTagsFactory('ap', 'video', 'update', video.uuid, video.url)
   }
 
   async update (overrideTo?: string[]) {
     logger.debug(
       'Updating remote video "%s".', this.videoObject.uuid,
-      { videoObject: this.videoObject, ...this.lTags(this.videoObject.uuid) }
+      { videoObject: this.videoObject, ...this.lTags() }
     )
 
     try {
@@ -82,7 +84,7 @@ export class APVideoUpdater extends APVideoAbstractBuilder {
         PeerTubeSocket.Instance.sendVideoViewsUpdate(videoUpdated)
       }
 
-      logger.info('Remote video with uuid %s updated', this.videoObject.uuid, this.lTags(this.videoObject.uuid))
+      logger.info('Remote video with uuid %s updated', this.videoObject.uuid, this.lTags())
 
       return videoUpdated
     } catch (err) {
@@ -158,7 +160,7 @@ export class APVideoUpdater extends APVideoAbstractBuilder {
     }
 
     // This is just a debug because we will retry the insert
-    logger.debug('Cannot update the remote video.', { err, ...this.lTags(this.videoObject.uuid) })
+    logger.debug('Cannot update the remote video.', { err, ...this.lTags() })
     throw err
   }
 }