]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/activitypub/videos/updater.ts
Refactor AP video logger tags
[github/Chocobozzz/PeerTube.git] / server / lib / activitypub / videos / updater.ts
index 11c177a68278a4fa1e79b715dd1874ed8f55b3d2..3339611fc02405a121270fdcfa0203fb152fadd6 100644 (file)
@@ -1,6 +1,6 @@
 import { Transaction } from 'sequelize/types'
 import { resetSequelizeInstance } from '@server/helpers/database-utils'
-import { logger } 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,6 +19,8 @@ export class APVideoUpdater extends APVideoAbstractBuilder {
 
   private readonly oldVideoChannel: MChannelAccountLight
 
+  protected lTags: LoggerTagsFn
+
   constructor (
     protected readonly videoObject: VideoObject,
     private readonly video: MVideoAccountLightBlacklistAllFiles
@@ -31,10 +33,15 @@ 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 })
+    logger.debug(
+      'Updating remote video "%s".', this.videoObject.uuid,
+      { videoObject: this.videoObject, ...this.lTags() }
+    )
 
     try {
       const channelActor = await this.getOrCreateVideoChannelFromVideoObject()
@@ -77,7 +84,7 @@ export class APVideoUpdater extends APVideoAbstractBuilder {
         PeerTubeSocket.Instance.sendVideoViewsUpdate(videoUpdated)
       }
 
-      logger.info('Remote video with uuid %s updated', this.videoObject.uuid)
+      logger.info('Remote video with uuid %s updated', this.videoObject.uuid, this.lTags())
 
       return videoUpdated
     } catch (err) {
@@ -121,7 +128,7 @@ export class APVideoUpdater extends APVideoAbstractBuilder {
     this.video.views = videoData.views
     this.video.isLive = videoData.isLive
 
-    // Ensures we update the updated video attribute
+    // Ensures we update the updatedAt attribute, even if main attributes did not change
     this.video.changed('updatedAt', true)
 
     return this.video.save({ transaction }) as Promise<MVideoFullLight>
@@ -153,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 })
+    logger.debug('Cannot update the remote video.', { err, ...this.lTags() })
     throw err
   }
 }