Skip to content

ActivityPub-federated video streaming platform using P2P directly in your web browser

Refactor logger and add context

Chocobozzz328fb1d66b73
diff --git a/packages/tests/src/api/server/logs.ts b/packages/tests/src/api/server/logs.ts
index 396f213b27..10a2d23ff0 100644
--- a/packages/tests/src/api/server/logs.ts
+++ b/packages/tests/src/api/server/logs.ts
@@ -1,6 +1,5 @@
/* oxlint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
-import { expect } from 'chai'
import { HttpStatusCode } from '@peertube/peertube-models'
import {
cleanupTests,
@@ -11,6 +10,7 @@ import {
setAccessTokensToServers,
waitJobs
} from '@peertube/peertube-server-commands'
+import { expect } from 'chai'
describe('Test logs', function () {
let server: PeerTubeServer
@@ -112,6 +112,29 @@ describe('Test logs', function () {
}
})
+ it('Should tag transcoding job logs with the video uuid', async function () {
+ this.timeout(60000)
+
+ await server.config.enableMinimumTranscoding()
+
+ const now = new Date()
+
+ const { uuid } = await server.videos.upload({ attributes: { name: 'video 6b' } })
+ await waitJobs([ server ])
+
+ const body = await logsCommand.getLogs({ startDate: now, level: 'debug', tagsOneOf: [ uuid ] })
+ const logsString = JSON.stringify(body)
+
+ expect(body).to.not.have.lengthOf(0)
+ expect(logsString.includes('Processing transcoding job')).to.be.true
+
+ for (const line of body) {
+ expect(line.tags).to.contain(uuid)
+ }
+
+ await server.config.disableTranscoding()
+ })
+
it('Should log ping/HTTP requests', async function () {
const now = new Date()
diff --git a/packages/tests/src/server-helpers/youtube-dl.ts b/packages/tests/src/server-helpers/youtube-dl.ts
index 25451f8364..7d32fa2511 100644
--- a/packages/tests/src/server-helpers/youtube-dl.ts
+++ b/packages/tests/src/server-helpers/youtube-dl.ts
@@ -1,12 +1,11 @@
/* oxlint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
+import { YoutubeDLCLI } from '@peertube/peertube-server/core/helpers/youtube-dl/youtube-dl-cli.js'
+import { CONFIG } from '@peertube/peertube-server/core/initializers/config.js'
import { expect } from 'chai'
import { mkdtemp, rm, writeFile } from 'fs/promises'
import { tmpdir } from 'os'
import { join } from 'path'
-import { YoutubeDLCLI } from '@peertube/peertube-server/core/helpers/youtube-dl/youtube-dl-cli.js'
-import { logger } from '@peertube/peertube-server/core/helpers/logger.js'
-import { CONFIG } from '@peertube/peertube-server/core/initializers/config.js'
describe('YoutubeDLCLI', function () {
describe('wrapWithJSRuntimeOptions', function () {
@@ -136,9 +135,10 @@ describe('YoutubeDLCLI', function () {
it('Should log an error and continue when the cookies file is missing', async function () {
const originalTmpPersistentDirDescriptor = Object.getOwnPropertyDescriptor(CONFIG.STORAGE, 'TMP_PERSISTENT_DIR')
const originalCookiesEnabledDescriptor = Object.getOwnPropertyDescriptor(CONFIG.IMPORT.VIDEOS.HTTP.COOKIES, 'ENABLED')
- const originalLoggerError = logger.error
+ const originalStdoutWrite = process.stdout.write.bind(process.stdout)
const tempDir = await mkdtemp(join(tmpdir(), 'peertube-cookies-'))
- const loggedMessages: any[][] = []
+ const cookiesFile = join(tempDir, 'youtube-cookies.txt')
+ let loggedOutput = ''
Object.defineProperty(CONFIG.STORAGE, 'TMP_PERSISTENT_DIR', {
get: () => tempDir,
@@ -149,22 +149,24 @@ describe('YoutubeDLCLI', function () {
get: () => true,
configurable: true
})
+ // The logger writes to stdout, and its module-private logger instance can't be reached from here:
+ // capture the console transport output instead of trying to mock the logger
+ process.stdout.write = ((chunk: any, ...args: any[]) => {
+ loggedOutput += chunk.toString()
- ;(logger as any).error = (...args: any[]) => {
- loggedMessages.push(args)
- }
+ return originalStdoutWrite(chunk, ...args)
+ }) as typeof process.stdout.write
try {
const inputArgs = [ '--dump-json', '-f', 'best' ]
const result: string[] = await cli.wrapWithCookiesOptions(inputArgs)
expect(result).to.deep.equal(inputArgs)
- expect(loggedMessages).to.have.lengthOf(1)
- expect(loggedMessages[0][0]).to.contain('yt-dlp cookies are enabled but the cookies file %s does not exist')
+ expect(loggedOutput).to.contain('yt-dlp cookies are enabled but the cookies file ' + cookiesFile + ' does not exist')
} finally {
Object.defineProperty(CONFIG.STORAGE, 'TMP_PERSISTENT_DIR', originalTmpPersistentDirDescriptor)
Object.defineProperty(CONFIG.IMPORT.VIDEOS.HTTP.COOKIES, 'ENABLED', originalCookiesEnabledDescriptor)
- ;(logger as any).error = originalLoggerError
+ process.stdout.write = originalStdoutWrite
await rm(tempDir, { recursive: true, force: true })
}
})
diff --git a/server/core/controllers/activitypub/inbox.ts b/server/core/controllers/activitypub/inbox.ts
index 6d9777bdbb..cb2625ec59 100644
--- a/server/core/controllers/activitypub/inbox.ts
+++ b/server/core/controllers/activitypub/inbox.ts
@@ -2,7 +2,7 @@ import { Activity, ActivityPubCollection, ActivityPubOrderedCollection, HttpStat
import { InboxManager } from '@server/lib/activitypub/inbox-manager.js'
import express from 'express'
import { isActivityValid } from '../../helpers/custom-validators/activitypub/activity.js'
-import { logger } from '../../helpers/logger.js'
+import { createLogger } from '../../helpers/logger.js'
import {
accountHandleGetValidatorFactory,
activityPubRateLimiter,
@@ -13,6 +13,8 @@ import {
} from '../../middlewares/index.js'
import { activityPubValidator } from '../../middlewares/validators/activitypub/activity.js'
+const logger = createLogger()
+
const inboxRouter = express.Router()
inboxRouter.post(
diff --git a/server/core/controllers/activitypub/outbox.ts b/server/core/controllers/activitypub/outbox.ts
index cee848415a..8080b8b28d 100644
--- a/server/core/controllers/activitypub/outbox.ts
+++ b/server/core/controllers/activitypub/outbox.ts
@@ -4,7 +4,7 @@ import { activityPubCollectionPagination } from '@server/lib/activitypub/collect
import { getContextFilter } from '@server/lib/activitypub/context.js'
import { MActorLight } from '@server/types/models/index.js'
import express from 'express'
-import { logger } from '../../helpers/logger.js'
+import { createLogger } from '../../helpers/logger.js'
import { getVideoAudience } from '../../lib/activitypub/audience.js'
import { buildAnnounceActivity, buildCreateActivity } from '../../lib/activitypub/send/index.js'
import {
@@ -17,6 +17,8 @@ import { apPaginationValidator } from '../../middlewares/validators/activitypub/
import { VideoModel } from '../../models/video/video.js'
import { activityPubResponse } from './utils.js'
+const logger = createLogger()
+
const outboxRouter = express.Router()
outboxRouter.get(
diff --git a/server/core/controllers/api/abuse.ts b/server/core/controllers/api/abuse.ts
index af73e7ab4f..b2f483b320 100644
--- a/server/core/controllers/api/abuse.ts
+++ b/server/core/controllers/api/abuse.ts
@@ -1,6 +1,6 @@
import { abusePredefinedReasonsMap } from '@peertube/peertube-core-utils'
import { AbuseCreate, AbuseState, HttpStatusCode, UserRight } from '@peertube/peertube-models'
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { CONFIG } from '@server/initializers/config.js'
import { createAccountAbuse, createVideoAbuse, createVideoCommentAbuse } from '@server/lib/moderation.js'
import { Notifier } from '@server/lib/notifier/index.js'
@@ -33,6 +33,8 @@ import {
} from '../../middlewares/index.js'
import { AccountModel } from '../../models/account/account.js'
+const logger = createLogger()
+
const abuseRouter = express.Router()
abuseRouter.use(apiRateLimiter)
diff --git a/server/core/controllers/api/blocklist.ts b/server/core/controllers/api/blocklist.ts
index 3b34d96df6..6d52e64466 100644
--- a/server/core/controllers/api/blocklist.ts
+++ b/server/core/controllers/api/blocklist.ts
@@ -1,6 +1,6 @@
import express from 'express'
import { handleToNameAndHost } from '@server/helpers/actors.js'
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { AccountBlocklistModel } from '@server/models/blocklist/account-blocklist.js'
import { getServerActor } from '@server/models/application/application.js'
import { ServerBlocklistModel } from '@server/models/blocklist/server-blocklist.js'
@@ -8,6 +8,8 @@ import { MActorAccountId, MUserAccountId } from '@server/types/models/index.js'
import { BlockStatus } from '@peertube/peertube-models'
import { apiRateLimiter, asyncMiddleware, blocklistStatusValidator, optionalAuthenticate } from '../../middlewares/index.js'
+const logger = createLogger()
+
const blocklistRouter = express.Router()
blocklistRouter.use(apiRateLimiter)
diff --git a/server/core/controllers/api/index.ts b/server/core/controllers/api/index.ts
index 7dc79b8b16..8ef6acd27e 100644
--- a/server/core/controllers/api/index.ts
+++ b/server/core/controllers/api/index.ts
@@ -1,5 +1,5 @@
import { HttpStatusCode } from '@peertube/peertube-models'
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import cors from 'cors'
import express from 'express'
import { abuseRouter } from './abuse.js'
@@ -26,6 +26,8 @@ import { videoPlaylistRouter } from './video-playlist.js'
import { videosRouter } from './videos/index.js'
import { watchedWordsRouter } from './watched-words.js'
+const logger = createLogger()
+
const apiRouter = express.Router()
apiRouter.use(cors({
diff --git a/server/core/controllers/api/oauth-clients.ts b/server/core/controllers/api/oauth-clients.ts
index a9ed9e3309..041b72476d 100644
--- a/server/core/controllers/api/oauth-clients.ts
+++ b/server/core/controllers/api/oauth-clients.ts
@@ -2,10 +2,12 @@ import express from 'express'
import { HttpStatusCode, OAuthClientLocal } from '@peertube/peertube-models'
import { isTestOrDevInstance } from '@peertube/peertube-node-utils'
import { OAuthClientModel } from '@server/models/oauth/oauth-client.js'
-import { logger } from '../../helpers/logger.js'
+import { createLogger } from '../../helpers/logger.js'
import { CONFIG } from '../../initializers/config.js'
import { apiRateLimiter, asyncMiddleware, openapiOperationDoc } from '../../middlewares/index.js'
+const logger = createLogger()
+
const oauthClientsRouter = express.Router()
oauthClientsRouter.use(apiRateLimiter)
diff --git a/server/core/controllers/api/overviews.ts b/server/core/controllers/api/overviews.ts
index d0079c3a93..bcac54dae0 100644
--- a/server/core/controllers/api/overviews.ts
+++ b/server/core/controllers/api/overviews.ts
@@ -1,5 +1,5 @@
import { CategoryOverview, ChannelOverview, TagOverview, VideosOverview } from '@peertube/peertube-models'
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { Hooks } from '@server/lib/plugins/hooks.js'
import { getServerActor } from '@server/models/application/application.js'
import { VideoModel } from '@server/models/video/video.js'
@@ -10,6 +10,8 @@ import { MEMOIZE_TTL, OVERVIEWS } from '../../initializers/constants.js'
import { apiRateLimiter, asyncMiddleware, optionalAuthenticate, videosOverviewValidator } from '../../middlewares/index.js'
import { TagModel } from '../../models/video/tag.js'
+const logger = createLogger()
+
const overviewsRouter = express.Router()
overviewsRouter.use(apiRateLimiter)
diff --git a/server/core/controllers/api/plugins.ts b/server/core/controllers/api/plugins.ts
index 85e458c9ea..180bc9cb22 100644
--- a/server/core/controllers/api/plugins.ts
+++ b/server/core/controllers/api/plugins.ts
@@ -1,5 +1,5 @@
import express from 'express'
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { getFormattedObjects } from '@server/helpers/utils.js'
import { listAvailablePluginsFromIndex } from '@server/lib/plugins/plugin-index.js'
import { PluginManager } from '@server/lib/plugins/plugin-manager.js'
@@ -34,6 +34,8 @@ import {
UserRight
} from '@peertube/peertube-models'
+const logger = createLogger()
+
const pluginRouter = express.Router()
pluginRouter.use(apiRateLimiter)
diff --git a/server/core/controllers/api/runners/jobs-files.ts b/server/core/controllers/api/runners/jobs-files.ts
index 52e7717184..ad6dae81b5 100644
--- a/server/core/controllers/api/runners/jobs-files.ts
+++ b/server/core/controllers/api/runners/jobs-files.ts
@@ -1,5 +1,5 @@
import { FileStorage, RunnerJobState, VideoFileStream } from '@peertube/peertube-models'
-import { logger, loggerTagsFactory } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { proxifyHLS, proxifyWebVideoFile } from '@server/lib/object-storage/index.js'
import { VideoPathManager } from '@server/lib/video-path-manager.js'
import { getStudioTaskFilePath } from '@server/lib/video-studio.js'
@@ -12,7 +12,7 @@ import {
import { MVideoFileStreamingPlaylistVideo, MVideoFileVideo, MVideoFull } from '@server/types/models/index.js'
import express from 'express'
-const lTags = loggerTagsFactory('api', 'runner')
+const logger = createLogger('api', 'runner')
const runnerJobFilesRouter = express.Router()
@@ -62,17 +62,13 @@ async function getMaxQualityAudioFile (req: express.Request, res: express.Respon
const runner = runnerJob.Runner
const video = res.locals.videoFull
- logger.info(
- 'Get max quality separated audio file of video %s of job %s for runner %s',
- video.uuid,
- runnerJob.uuid,
- runner.name,
- lTags(runner.name, runnerJob.id, runnerJob.type)
- )
+ return logger.withContext([ runner.name, runnerJob.id, runnerJob.type ], () => {
+ logger.info('Get max quality separated audio file of video %s of job %s for runner %s', video.uuid, runnerJob.uuid, runner.name)
- const file = video.getMaxQualityFile(VideoFileStream.AUDIO) || video.getMaxQualityFile(VideoFileStream.VIDEO)
+ const file = video.getMaxQualityFile(VideoFileStream.AUDIO) || video.getMaxQualityFile(VideoFileStream.VIDEO)
- return serveVideoFile({ video, file, req, res })
+ return serveVideoFile({ video, file, req, res })
+ })
}
async function getMaxQualityVideoFile (req: express.Request, res: express.Response) {
@@ -80,17 +76,13 @@ async function getMaxQualityVideoFile (req: express.Request, res: express.Respon
const runner = runnerJob.Runner
const video = res.locals.videoFull
- logger.info(
- 'Get max quality file of video %s of job %s for runner %s',
- video.uuid,
- runnerJob.uuid,
- runner.name,
- lTags(runner.name, runnerJob.id, runnerJob.type)
- )
+ return logger.withContext([ runner.name, runnerJob.id, runnerJob.type ], () => {
+ logger.info('Get max quality file of video %s of job %s for runner %s', video.uuid, runnerJob.uuid, runner.name)
- const file = video.getMaxQualityFile(VideoFileStream.VIDEO) || video.getMaxQualityFile(VideoFileStream.AUDIO)
+ const file = video.getMaxQualityFile(VideoFileStream.VIDEO) || video.getMaxQualityFile(VideoFileStream.AUDIO)
- return serveVideoFile({ video, file, req, res })
+ return serveVideoFile({ video, file, req, res })
+ })
}
async function serveVideoFile (options: {
@@ -132,17 +124,13 @@ function getMaxQualityVideoThumbnail (req: express.Request, res: express.Respons
const runner = runnerJob.Runner
const video = res.locals.videoFull
- logger.info(
- 'Get max quality preview file of video %s of job %s for runner %s',
- video.uuid,
- runnerJob.uuid,
- runner.name,
- lTags(runner.name, runnerJob.id, runnerJob.type)
- )
+ return logger.withContext([ runner.name, runnerJob.id, runnerJob.type ], () => {
+ logger.info('Get max quality preview file of video %s of job %s for runner %s', video.uuid, runnerJob.uuid, runner.name)
- const file = video.getBestThumbnail('16:9')
+ const file = video.getBestThumbnail('16:9')
- return res.sendFile(file.getFSPath())
+ return res.sendFile(file.getFSPath())
+ })
}
function getVideoStudioTaskFile (req: express.Request, res: express.Response) {
@@ -151,14 +139,9 @@ function getVideoStudioTaskFile (req: express.Request, res: express.Response) {
const video = res.locals.videoFull
const filename = req.params.filename
- logger.info(
- 'Get video studio task file %s of video %s of job %s for runner %s',
- filename,
- video.uuid,
- runnerJob.uuid,
- runner.name,
- lTags(runner.name, runnerJob.id, runnerJob.type)
- )
+ return logger.withContext([ runner.name, runnerJob.id, runnerJob.type ], () => {
+ logger.info('Get video studio task file %s of video %s of job %s for runner %s', filename, video.uuid, runnerJob.uuid, runner.name)
- return res.sendFile(getStudioTaskFilePath(filename))
+ return res.sendFile(getStudioTaskFilePath(filename))
+ })
}
diff --git a/server/core/controllers/api/runners/jobs.ts b/server/core/controllers/api/runners/jobs.ts
index 11ccc88b5e..bc3a825d98 100644
--- a/server/core/controllers/api/runners/jobs.ts
+++ b/server/core/controllers/api/runners/jobs.ts
@@ -2,6 +2,7 @@ import {
AbortRunnerJobBody,
AcceptRunnerJobResult,
ErrorRunnerJobBody,
+ GenerateStoryboardSuccess,
HttpStatusCode,
ListRunnerJobsQuery,
LiveRTMPHLSTranscodingUpdatePayload,
@@ -15,7 +16,6 @@ import {
RunnerJobUpdatePayload,
ServerErrorCode,
TranscriptionSuccess,
- GenerateStoryboardSuccess,
UserRight,
VODAudioMergeTranscodingSuccess,
VODHLSTranscodingSuccess,
@@ -24,7 +24,7 @@ import {
} from '@peertube/peertube-models'
import { retryTransactionWrapper } from '@server/helpers/database-utils.js'
import { cleanUpReqFiles, createReqFiles } from '@server/helpers/express-utils.js'
-import { logger, loggerTagsFactory } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { generateRunnerJobToken } from '@server/helpers/token-generator.js'
import { MIMETYPES } from '@server/initializers/constants.js'
import { sequelizeTypescript } from '@server/initializers/database.js'
@@ -56,6 +56,8 @@ import { RunnerJobModel } from '@server/models/runner/runner-job.js'
import { RunnerModel } from '@server/models/runner/runner.js'
import express, { UploadFiles } from 'express'
+const logger = createLogger('api', 'runner')
+
const postRunnerJobSuccessVideoFiles = createReqFiles(
[ 'payload[videoFile]', 'payload[resolutionPlaylistFile]', 'payload[vttFile]', 'payload[storyboardFile]' ],
{
@@ -71,8 +73,6 @@ const runnerJobUpdateVideoFiles = createReqFiles(
{ ...MIMETYPES.VIDEO.MIMETYPE_EXT, ...MIMETYPES.M3U8.MIMETYPE_EXT }
)
-const lTags = loggerTagsFactory('api', 'runner')
-
const runnerJobsRouter = express.Router()
// ---------------------------------------------------------------------------
@@ -176,122 +176,132 @@ export {
async function requestRunnerJob (req: express.Request, res: express.Response) {
const runner = res.locals.runner
- const body = req.body as RequestRunnerJobBody
- const availableJobs = await RunnerJobModel.listAvailableJobs(body.jobTypes)
- logger.debug('Runner %s requests for a job.', runner.name, { availableJobs, ...lTags(runner.name) })
+ return logger.withContext([ runner.name ], async () => {
+ const body = req.body as RequestRunnerJobBody
+ const availableJobs = await RunnerJobModel.listAvailableJobs(body.jobTypes)
- const result: RequestRunnerJobResult = {
- availableJobs: availableJobs.map(j => ({
- uuid: j.uuid,
- type: j.type,
- payload: j.payload
- }))
- }
+ logger.debug('Runner %s requests for a job.', runner.name, { availableJobs })
- if (body.version && runner.version !== body.version) {
- runner.version = body.version
- await runner.save()
- }
+ const result: RequestRunnerJobResult = {
+ availableJobs: availableJobs.map(j => ({
+ uuid: j.uuid,
+ type: j.type,
+ payload: j.payload
+ }))
+ }
+
+ if (body.version && runner.version !== body.version) {
+ runner.version = body.version
+ await runner.save()
+ }
- updateLastRunnerContact(req, runner)
+ updateLastRunnerContact(req, runner)
- return res.json(result)
+ return res.json(result)
+ })
}
async function acceptRunnerJob (req: express.Request, res: express.Response) {
const runner = res.locals.runner
const runnerJob = res.locals.runnerJob
- const newRunnerJob = await retryTransactionWrapper(() => {
- return sequelizeTypescript.transaction(async transaction => {
- await runnerJob.reload({ transaction })
+ return logger.withContext([ runner.name, runnerJob.uuid, runnerJob.type ], async () => {
+ const newRunnerJob = await retryTransactionWrapper(() => {
+ return sequelizeTypescript.transaction(async transaction => {
+ await runnerJob.reload({ transaction })
- if (runnerJob.state !== RunnerJobState.PENDING) {
- res.fail({
- type: ServerErrorCode.RUNNER_JOB_NOT_IN_PENDING_STATE,
- message: 'This job is not in pending state anymore',
- status: HttpStatusCode.CONFLICT_409
- })
+ if (runnerJob.state !== RunnerJobState.PENDING) {
+ res.fail({
+ type: ServerErrorCode.RUNNER_JOB_NOT_IN_PENDING_STATE,
+ message: 'This job is not in pending state anymore',
+ status: HttpStatusCode.CONFLICT_409
+ })
- return undefined
- }
+ return undefined
+ }
- runnerJob.state = RunnerJobState.PROCESSING
- runnerJob.processingJobToken = generateRunnerJobToken()
- runnerJob.startedAt = new Date()
- runnerJob.runnerId = runner.id
+ runnerJob.state = RunnerJobState.PROCESSING
+ runnerJob.processingJobToken = generateRunnerJobToken()
+ runnerJob.startedAt = new Date()
+ runnerJob.runnerId = runner.id
- return runnerJob.save({ transaction })
+ return runnerJob.save({ transaction })
+ })
})
- })
- if (!newRunnerJob) return
+ if (!newRunnerJob) return
- newRunnerJob.Runner = runner as RunnerModel
+ newRunnerJob.Runner = runner as RunnerModel
- const result: AcceptRunnerJobResult = {
- job: {
- ...newRunnerJob.toFormattedJSON(),
+ const result: AcceptRunnerJobResult = {
+ job: {
+ ...newRunnerJob.toFormattedJSON(),
- jobToken: newRunnerJob.processingJobToken
+ jobToken: newRunnerJob.processingJobToken
+ }
}
- }
- updateLastRunnerContact(req, runner)
+ updateLastRunnerContact(req, runner)
- logger.info(
- 'Remote runner %s has accepted job %s (%s)',
- runner.name,
- runnerJob.uuid,
- runnerJob.type,
- lTags(runner.name, runnerJob.uuid, runnerJob.type)
- )
+ logger.info(
+ 'Remote runner %s has accepted job %s (%s)',
+ runner.name,
+ runnerJob.uuid,
+ runnerJob.type
+ )
- return res.json(result)
+ return res.json(result)
+ })
}
async function abortRunnerJob (req: express.Request, res: express.Response) {
const runnerJob = res.locals.runnerJob
const runner = runnerJob.Runner
- const body: AbortRunnerJobBody = req.body
- logger.info(
- 'Remote runner %s is aborting job %s (%s)',
- runner.name,
- runnerJob.uuid,
- runnerJob.type,
- { reason: body.reason, ...lTags(runner.name, runnerJob.uuid, runnerJob.type) }
- )
+ return logger.withContext([ runner.name, runnerJob.uuid, runnerJob.type ], async () => {
+ const body: AbortRunnerJobBody = req.body
- const RunnerJobHandler = getRunnerJobHandlerClass(runnerJob)
- await new RunnerJobHandler().abort({ runnerJob })
+ logger.info(
+ 'Remote runner %s is aborting job %s (%s)',
+ runner.name,
+ runnerJob.uuid,
+ runnerJob.type,
+ { reason: body.reason }
+ )
- updateLastRunnerContact(req, runnerJob.Runner)
+ const RunnerJobHandler = getRunnerJobHandlerClass(runnerJob)
+ await new RunnerJobHandler().abort({ runnerJob })
+
+ updateLastRunnerContact(req, runnerJob.Runner)
- return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
+ return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
+ })
}
async function errorRunnerJob (req: express.Request, res: express.Response) {
const runnerJob = res.locals.runnerJob
const runner = runnerJob.Runner
- const body: ErrorRunnerJobBody = req.body
- runnerJob.failures += 1
+ return logger.withContext([ runner.name, runnerJob.uuid, runnerJob.type ], async () => {
+ const body: ErrorRunnerJobBody = req.body
+
+ runnerJob.failures += 1
- logger.error(
- 'Remote runner %s had an error with job %s (%s)',
- runner.name,
- runnerJob.uuid,
- runnerJob.type,
- { errorMessage: body.message, totalFailures: runnerJob.failures, ...lTags(runner.name, runnerJob.uuid, runnerJob.type) }
- )
+ logger.error(
+ 'Remote runner %s had an error with job %s (%s)',
+ runner.name,
+ runnerJob.uuid,
+ runnerJob.type,
+ { errorMessage: body.message, totalFailures: runnerJob.failures }
+ )
- const RunnerJobHandler = getRunnerJobHandlerClass(runnerJob)
- await new RunnerJobHandler().error({ runnerJob, message: body.message })
+ const RunnerJobHandler = getRunnerJobHandlerClass(runnerJob)
+ await new RunnerJobHandler().error({ runnerJob, message: body.message })
- updateLastRunnerContact(req, runnerJob.Runner)
+ updateLastRunnerContact(req, runnerJob.Runner)
- return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
+ return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
+ })
}
// ---------------------------------------------------------------------------
@@ -313,37 +323,40 @@ const jobUpdateBuilders: {
async function updateRunnerJobController (req: express.Request, res: express.Response) {
const runnerJob = res.locals.runnerJob
const runner = runnerJob.Runner
- const body: RunnerJobUpdateBody = req.body
- if (runnerJob.state === RunnerJobState.COMPLETING || runnerJob.state === RunnerJobState.COMPLETED) {
- cleanUpReqFiles(req)
+ return logger.withContext([ runner.name, runnerJob.uuid, runnerJob.type ], async () => {
+ const body: RunnerJobUpdateBody = req.body
- return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
- }
+ if (runnerJob.state === RunnerJobState.COMPLETING || runnerJob.state === RunnerJobState.COMPLETED) {
+ cleanUpReqFiles(req)
- const payloadBuilder = jobUpdateBuilders[runnerJob.type]
- const updatePayload = payloadBuilder
- ? payloadBuilder(body.payload, req.files)
- : undefined
-
- logger.debug(
- 'Remote runner %s is updating job %s (%s)',
- runnerJob.Runner.name,
- runnerJob.uuid,
- runnerJob.type,
- { body, updatePayload, ...lTags(runner.name, runnerJob.uuid, runnerJob.type) }
- )
-
- const RunnerJobHandler = getRunnerJobHandlerClass(runnerJob)
- await new RunnerJobHandler().update({
- runnerJob,
- progress: req.body.progress,
- updatePayload
- })
+ return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
+ }
+
+ const payloadBuilder = jobUpdateBuilders[runnerJob.type]
+ const updatePayload = payloadBuilder
+ ? payloadBuilder(body.payload, req.files)
+ : undefined
+
+ logger.debug(
+ 'Remote runner %s is updating job %s (%s)',
+ runnerJob.Runner.name,
+ runnerJob.uuid,
+ runnerJob.type,
+ { body, updatePayload }
+ )
+
+ const RunnerJobHandler = getRunnerJobHandlerClass(runnerJob)
+ await new RunnerJobHandler().update({
+ runnerJob,
+ progress: req.body.progress,
+ updatePayload
+ })
- updateLastRunnerContact(req, runnerJob.Runner)
+ updateLastRunnerContact(req, runnerJob.Runner)
- return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
+ return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
+ })
}
// ---------------------------------------------------------------------------
@@ -406,24 +419,27 @@ const jobSuccessPayloadBuilders: {
async function postRunnerJobSuccess (req: express.Request, res: express.Response) {
const runnerJob = res.locals.runnerJob
const runner = runnerJob.Runner
- const body: RunnerJobSuccessBody = req.body
- const resultPayload = jobSuccessPayloadBuilders[runnerJob.type](body.payload, req.files)
+ return logger.withContext([ runner.name, runnerJob.uuid, runnerJob.type ], async () => {
+ const body: RunnerJobSuccessBody = req.body
+
+ const resultPayload = jobSuccessPayloadBuilders[runnerJob.type](body.payload, req.files)
- logger.info(
- 'Remote runner %s is sending success result for job %s (%s)',
- runnerJob.Runner.name,
- runnerJob.uuid,
- runnerJob.type,
- { resultPayload, ...lTags(runner.name, runnerJob.uuid, runnerJob.type) }
- )
+ logger.info(
+ 'Remote runner %s is sending success result for job %s (%s)',
+ runnerJob.Runner.name,
+ runnerJob.uuid,
+ runnerJob.type,
+ { resultPayload }
+ )
- const RunnerJobHandler = getRunnerJobHandlerClass(runnerJob)
- await new RunnerJobHandler().complete({ runnerJob, resultPayload })
+ const RunnerJobHandler = getRunnerJobHandlerClass(runnerJob)
+ await new RunnerJobHandler().complete({ runnerJob, resultPayload })
- updateLastRunnerContact(req, runnerJob.Runner)
+ updateLastRunnerContact(req, runnerJob.Runner)
- return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
+ return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
+ })
}
// ---------------------------------------------------------------------------
@@ -433,27 +449,31 @@ async function postRunnerJobSuccess (req: express.Request, res: express.Response
async function cancelRunnerJob (req: express.Request, res: express.Response) {
const runnerJob = res.locals.runnerJob
- logger.info('Cancelling job %s (%s)', runnerJob.uuid, runnerJob.type, lTags(runnerJob.uuid, runnerJob.type))
+ return logger.withContext([ runnerJob.uuid, runnerJob.type ], async () => {
+ logger.info('Cancelling job %s (%s)', runnerJob.uuid, runnerJob.type)
- const RunnerJobHandler = getRunnerJobHandlerClass(runnerJob)
- await new RunnerJobHandler().cancel({ runnerJob })
+ const RunnerJobHandler = getRunnerJobHandlerClass(runnerJob)
+ await new RunnerJobHandler().cancel({ runnerJob })
- return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
+ return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
+ })
}
async function deleteRunnerJob (req: express.Request, res: express.Response) {
const runnerJob = res.locals.runnerJob
- logger.info('Deleting job %s (%s)', runnerJob.uuid, runnerJob.type, lTags(runnerJob.uuid, runnerJob.type))
+ return logger.withContext([ runnerJob.uuid, runnerJob.type ], async () => {
+ logger.info('Deleting job %s (%s)', runnerJob.uuid, runnerJob.type)
- if (runnerJobCanBeCancelled(runnerJob)) {
- const RunnerJobHandler = getRunnerJobHandlerClass(runnerJob)
- await new RunnerJobHandler().cancel({ runnerJob })
- }
+ if (runnerJobCanBeCancelled(runnerJob)) {
+ const RunnerJobHandler = getRunnerJobHandlerClass(runnerJob)
+ await new RunnerJobHandler().cancel({ runnerJob })
+ }
- await runnerJob.destroy()
+ await runnerJob.destroy()
- return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
+ return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
+ })
}
async function listRunnerJobs (req: express.Request, res: express.Response) {
diff --git a/server/core/controllers/api/runners/manage-runners.ts b/server/core/controllers/api/runners/manage-runners.ts
index 1e01bc8d8b..ae0bf58d03 100644
--- a/server/core/controllers/api/runners/manage-runners.ts
+++ b/server/core/controllers/api/runners/manage-runners.ts
@@ -1,5 +1,5 @@
import { HttpStatusCode, ListRunnersQuery, RegisterRunnerBody, UserRight } from '@peertube/peertube-models'
-import { logger, loggerTagsFactory } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { generateRunnerToken } from '@server/helpers/token-generator.js'
import {
apiRateLimiter,
@@ -19,7 +19,7 @@ import {
import { RunnerModel } from '@server/models/runner/runner.js'
import express from 'express'
-const lTags = loggerTagsFactory('api', 'runner')
+const logger = createLogger('api', 'runner')
const manageRunnersRouter = express.Router()
@@ -69,41 +69,48 @@ export {
async function registerRunner (req: express.Request, res: express.Response) {
const body: RegisterRunnerBody = req.body
- const runnerToken = generateRunnerToken()
+ return logger.withContext([ body.name ], async () => {
+ const runnerToken = generateRunnerToken()
- const runner = new RunnerModel({
- runnerToken,
- name: body.name,
- description: body.description,
- lastContact: new Date(),
- ip: req.ip,
- version: body.version,
- runnerRegistrationTokenId: res.locals.runnerRegistrationToken.id
- })
+ const runner = new RunnerModel({
+ runnerToken,
+ name: body.name,
+ description: body.description,
+ lastContact: new Date(),
+ ip: req.ip,
+ version: body.version,
+ runnerRegistrationTokenId: res.locals.runnerRegistrationToken.id
+ })
- await runner.save()
+ await runner.save()
- logger.info('Registered new runner %s', runner.name, { ...lTags(runner.name) })
+ logger.info('Registered new runner %s', runner.name)
- return res.json({ id: runner.id, runnerToken })
+ return res.json({ id: runner.id, runnerToken })
+ })
}
async function unregisterRunner (req: express.Request, res: express.Response) {
const runner = res.locals.runner
- await runner.destroy()
- logger.info('Unregistered runner %s', runner.name, { ...lTags(runner.name) })
+ return logger.withContext([ runner.name ], async () => {
+ await runner.destroy()
+
+ logger.info('Unregistered runner %s', runner.name)
- return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
+ return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
+ })
}
async function deleteRunner (req: express.Request, res: express.Response) {
const runner = res.locals.runner
- await runner.destroy()
+ return logger.withContext([ runner.name ], async () => {
+ await runner.destroy()
- logger.info('Deleted runner %s', runner.name, { ...lTags(runner.name) })
+ logger.info('Deleted runner %s', runner.name)
- return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
+ return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
+ })
}
async function listRunners (req: express.Request, res: express.Response) {
diff --git a/server/core/controllers/api/runners/registration-tokens.ts b/server/core/controllers/api/runners/registration-tokens.ts
index 462c489bbf..a0db7f048e 100644
--- a/server/core/controllers/api/runners/registration-tokens.ts
+++ b/server/core/controllers/api/runners/registration-tokens.ts
@@ -1,5 +1,5 @@
import express from 'express'
-import { logger, loggerTagsFactory } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { generateRunnerRegistrationToken } from '@server/helpers/token-generator.js'
import {
apiRateLimiter,
@@ -15,7 +15,7 @@ import { deleteRegistrationTokenValidator } from '@server/middlewares/validators
import { RunnerRegistrationTokenModel } from '@server/models/runner/runner-registration-token.js'
import { HttpStatusCode, ListRunnerRegistrationTokensQuery, UserRight } from '@peertube/peertube-models'
-const lTags = loggerTagsFactory('api', 'runner')
+const logger = createLogger('api', 'runner')
const runnerRegistrationTokensRouter = express.Router()
@@ -54,7 +54,7 @@ export {
// ---------------------------------------------------------------------------
async function generateRegistrationToken (req: express.Request, res: express.Response) {
- logger.info('Generating new runner registration token.', lTags())
+ logger.info('Generating new runner registration token.')
const registrationToken = new RunnerRegistrationTokenModel({
registrationToken: generateRunnerRegistrationToken()
@@ -66,7 +66,7 @@ async function generateRegistrationToken (req: express.Request, res: express.Res
}
async function deleteRegistrationToken (req: express.Request, res: express.Response) {
- logger.info('Removing runner registration token.', lTags())
+ logger.info('Removing runner registration token.')
const runnerRegistrationToken = res.locals.runnerRegistrationToken
diff --git a/server/core/controllers/api/search/search-video-channels.ts b/server/core/controllers/api/search/search-video-channels.ts
index e263eb5522..b6cd4db7e6 100644
--- a/server/core/controllers/api/search/search-video-channels.ts
+++ b/server/core/controllers/api/search/search-video-channels.ts
@@ -10,7 +10,7 @@ import { buildMutedForSearchIndex, isSearchIndexSearch, isURISearch } from '@ser
import { getServerActor } from '@server/models/application/application.js'
import { HttpStatusCode, ResultList, VideoChannel, VideoChannelsSearchQueryAfterSanitize } from '@peertube/peertube-models'
import { isUserAbleToSearchRemoteURI } from '../../../helpers/express-utils.js'
-import { logger } from '../../../helpers/logger.js'
+import { createLogger } from '../../../helpers/logger.js'
import { getFormattedObjects } from '../../../helpers/utils.js'
import { getOrCreateAPActor, loadActorUrlOrGetFromWebfinger } from '../../../lib/activitypub/actors/index.js'
import {
@@ -27,6 +27,8 @@ import { VideoChannelModel } from '../../../models/video/video-channel.js'
import { MChannelAccountDefault } from '../../../types/models/index.js'
import { searchLocalUrl } from './shared/index.js'
+const logger = createLogger()
+
const searchChannelsRouter = express.Router()
searchChannelsRouter.get(
diff --git a/server/core/controllers/api/search/search-video-playlists.ts b/server/core/controllers/api/search/search-video-playlists.ts
index f1e34fb6f0..941df1d467 100644
--- a/server/core/controllers/api/search/search-video-playlists.ts
+++ b/server/core/controllers/api/search/search-video-playlists.ts
@@ -1,7 +1,7 @@
import express from 'express'
import { sanitizeUrl } from '@server/helpers/core-utils.js'
import { isUserAbleToSearchRemoteURI } from '@server/helpers/express-utils.js'
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { pickSearchPlaylistQuery } from '@server/helpers/query.js'
import { doJSONRequest } from '@server/helpers/requests.js'
import { getFormattedObjects } from '@server/helpers/utils.js'
@@ -27,6 +27,8 @@ import {
} from '../../../middlewares/index.js'
import { searchLocalUrl } from './shared/index.js'
+const logger = createLogger()
+
const searchPlaylistsRouter = express.Router()
searchPlaylistsRouter.get('/video-playlists',
diff --git a/server/core/controllers/api/search/search-videos.ts b/server/core/controllers/api/search/search-videos.ts
index 8ae2bd70c6..78d9dd27a5 100644
--- a/server/core/controllers/api/search/search-videos.ts
+++ b/server/core/controllers/api/search/search-videos.ts
@@ -11,7 +11,7 @@ import { buildMutedForSearchIndex, isSearchIndexSearch, isURISearch } from '@ser
import { getServerActor } from '@server/models/application/application.js'
import express from 'express'
import { buildNSFWFilters, getCountVideos, isUserAbleToSearchRemoteURI } from '../../../helpers/express-utils.js'
-import { logger } from '../../../helpers/logger.js'
+import { createLogger } from '../../../helpers/logger.js'
import { getFormattedObjects } from '../../../helpers/utils.js'
import {
asyncMiddleware,
@@ -29,6 +29,8 @@ import { VideoModel } from '../../../models/video/video.js'
import { MVideoAccountLightBlacklistAllFiles } from '../../../types/models/index.js'
import { searchLocalUrl } from './shared/index.js'
+const logger = createLogger()
+
const searchVideosRouter = express.Router()
searchVideosRouter.get(
diff --git a/server/core/controllers/api/server/contact.ts b/server/core/controllers/api/server/contact.ts
index 29250193fe..cd7b98f7e0 100644
--- a/server/core/controllers/api/server/contact.ts
+++ b/server/core/controllers/api/server/contact.ts
@@ -1,10 +1,12 @@
import express from 'express'
import { ContactForm, HttpStatusCode } from '@peertube/peertube-models'
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { Emailer } from '../../../lib/emailer.js'
import { Redis } from '../../../lib/redis.js'
import { asyncMiddleware, contactAdministratorValidator } from '../../../middlewares/index.js'
+const logger = createLogger()
+
const contactRouter = express.Router()
contactRouter.post('/contact', asyncMiddleware(contactAdministratorValidator), asyncMiddleware(contactAdministrator))
diff --git a/server/core/controllers/api/server/debug.ts b/server/core/controllers/api/server/debug.ts
index 2814f9dac1..3a6ad96817 100644
--- a/server/core/controllers/api/server/debug.ts
+++ b/server/core/controllers/api/server/debug.ts
@@ -7,7 +7,7 @@ import {
UserRegistrationState,
UserRight
} from '@peertube/peertube-models'
-import { logger, loggerTagsFactory } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { CONFIG } from '@server/initializers/config.js'
import { WEBSERVER } from '@server/initializers/constants.js'
import { InboxManager } from '@server/lib/activitypub/inbox-manager.js'
@@ -22,7 +22,7 @@ import { VideoStatsManager } from '@server/lib/stats/video-stats-manager.js'
import express from 'express'
import { asyncMiddleware, authenticate, ensureUserHasRight } from '../../../middlewares/index.js'
-const lTags = loggerTagsFactory('debug-controller')
+const logger = createLogger('debug-controller')
const debugRouter = express.Router()
@@ -73,7 +73,7 @@ async function runCommand (req: express.Request, res: express.Response) {
return res.fail({ message: 'Invalid command' })
}
- logger.info('Executing debug command: ' + body.command, lTags())
+ logger.info('Executing debug command: ' + body.command)
await processors[body.command]()
diff --git a/server/core/controllers/api/server/follows.ts b/server/core/controllers/api/server/follows.ts
index f6fb43b8db..82e70af468 100644
--- a/server/core/controllers/api/server/follows.ts
+++ b/server/core/controllers/api/server/follows.ts
@@ -1,7 +1,7 @@
import express from 'express'
import { HttpStatusCode, ServerFollowCreate, UserRight } from '@peertube/peertube-models'
import { getServerActor } from '@server/models/application/application.js'
-import { logger } from '../../../helpers/logger.js'
+import { createLogger } from '../../../helpers/logger.js'
import { getFormattedObjects } from '../../../helpers/utils.js'
import { sequelizeTypescript } from '../../../initializers/database.js'
import { autoFollowBackIfNeeded } from '../../../lib/activitypub/follow.js'
@@ -29,6 +29,8 @@ import {
} from '../../../middlewares/validators/index.js'
import { ActorFollowModel } from '../../../models/actor/actor-follow.js'
+const logger = createLogger()
+
const serverFollowsRouter = express.Router()
serverFollowsRouter.get(
'/following',
diff --git a/server/core/controllers/api/server/logs.ts b/server/core/controllers/api/server/logs.ts
index 1ebf8053c5..7d7888ea42 100644
--- a/server/core/controllers/api/server/logs.ts
+++ b/server/core/controllers/api/server/logs.ts
@@ -4,12 +4,14 @@ import { join } from 'path'
import { pick } from '@peertube/peertube-core-utils'
import { ClientLogCreate, HttpStatusCode, ServerLogLevel, UserRight } from '@peertube/peertube-models'
import { isArray } from '@server/helpers/custom-validators/misc.js'
-import { logger, mtimeSortFilesDesc } from '@server/helpers/logger.js'
+import { createLogger, mtimeSortFilesDesc } from '@server/helpers/logger.js'
import { CONFIG } from '../../../initializers/config.js'
import { AUDIT_LOG_FILENAME, LOG_FILENAME, MAX_LOGS_OUTPUT_CHARACTERS } from '../../../initializers/constants.js'
import { asyncMiddleware, authenticate, buildRateLimiter, ensureUserHasRight, optionalAuthenticate } from '../../../middlewares/index.js'
import { createClientLogValidator, getAuditLogsValidator, getLogsValidator } from '../../../middlewares/validators/logs.js'
+const logger = createLogger()
+
const createClientLogRateLimiter = buildRateLimiter({
windowMs: CONFIG.RATES_LIMIT.RECEIVE_CLIENT_LOG.WINDOW_MS,
max: CONFIG.RATES_LIMIT.RECEIVE_CLIENT_LOG.MAX
diff --git a/server/core/controllers/api/server/redundancy.ts b/server/core/controllers/api/server/redundancy.ts
index 29a80d1185..e9229ac330 100644
--- a/server/core/controllers/api/server/redundancy.ts
+++ b/server/core/controllers/api/server/redundancy.ts
@@ -2,7 +2,7 @@ import express from 'express'
import { HttpStatusCode, UserRight } from '@peertube/peertube-models'
import { JobQueue } from '@server/lib/job-queue/index.js'
import { VideoRedundancyModel } from '@server/models/redundancy/video-redundancy.js'
-import { logger } from '../../../helpers/logger.js'
+import { createLogger } from '../../../helpers/logger.js'
import { removeRedundanciesOfServer, removeVideoRedundancy } from '../../../lib/redundancy.js'
import {
asyncMiddleware,
@@ -20,6 +20,8 @@ import {
updateServerRedundancyValidator
} from '../../../middlewares/validators/redundancy.js'
+const logger = createLogger()
+
const serverRedundancyRouter = express.Router()
serverRedundancyRouter.put(
diff --git a/server/core/controllers/api/server/server-blocklist.ts b/server/core/controllers/api/server/server-blocklist.ts
index c4b467824b..8d0895ad2d 100644
--- a/server/core/controllers/api/server/server-blocklist.ts
+++ b/server/core/controllers/api/server/server-blocklist.ts
@@ -1,5 +1,5 @@
import { AutoMuteList, BlocklistLogAction, HttpStatusCode, UserRight } from '@peertube/peertube-models'
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { CONFIG } from '@server/initializers/config.js'
import { fetchAndValidateAutoMuteList } from '@server/lib/blocklist-subscriptions.js'
import { getServerActor } from '@server/models/application/application.js'
@@ -38,6 +38,8 @@ import { BlocklistLogModel } from '../../../models/blocklist/blocklist-log.js'
import { BlocklistSubscriptionModel } from '../../../models/blocklist/blocklist-subscription.js'
import { ServerBlocklistModel } from '../../../models/blocklist/server-blocklist.js'
+const logger = createLogger()
+
const serverBlocklistRouter = express.Router()
serverBlocklistRouter.get(
diff --git a/server/core/controllers/api/users/index.ts b/server/core/controllers/api/users/index.ts
index 0aeedb2ebb..eac28dc50b 100644
--- a/server/core/controllers/api/users/index.ts
+++ b/server/core/controllers/api/users/index.ts
@@ -9,7 +9,7 @@ import { OAuthTokenModel } from '@server/models/oauth/oauth-token.js'
import { MUserAccountDefault } from '@server/types/models/index.js'
import express from 'express'
import { auditLoggerFactory, getAuditIdFromRes, UserAuditView } from '../../../helpers/audit-logger.js'
-import { logger, loggerTagsFactory } from '../../../helpers/logger.js'
+import { createLogger } from '../../../helpers/logger.js'
import { generateRandomString, getFormattedObjects } from '../../../helpers/utils.js'
import { sequelizeTypescript } from '../../../initializers/database.js'
import { Emailer } from '../../../lib/emailer.js'
@@ -53,8 +53,9 @@ import { twoFactorRouter } from './two-factor.js'
import { userExportsRouter } from './user-exports.js'
import { userImportRouter } from './user-imports.js'
+const logger = createLogger('api', 'users')
+
const auditLogger = auditLoggerFactory('users')
-const lTags = loggerTagsFactory('api', 'users')
const askResetPasswordRateLimiter = buildRateLimiter({
windowMs: CONFIG.RATES_LIMIT.ASK_SEND_EMAIL.WINDOW_MS,
@@ -165,49 +166,51 @@ export {
async function createUser (req: express.Request, res: express.Response) {
const body: UserCreate = req.body
- const userToCreate = buildUser({
- ...pick(body, [ 'username', 'password', 'email', 'role', 'videoQuota', 'videoQuotaDaily', 'adminFlags' ]),
+ return logger.withContext([ body.username ], async () => {
+ const userToCreate = buildUser({
+ ...pick(body, [ 'username', 'password', 'email', 'role', 'videoQuota', 'videoQuotaDaily', 'adminFlags' ]),
- emailVerified: null
- })
+ emailVerified: null
+ })
- // NB: due to the validator usersAddValidator, password==='' can only be true if we can send the mail.
- const createPassword = userToCreate.password === ''
- if (createPassword) {
- userToCreate.password = await generateRandomString(20)
- }
+ // NB: due to the validator usersAddValidator, password==='' can only be true if we can send the mail.
+ const createPassword = userToCreate.password === ''
+ if (createPassword) {
+ userToCreate.password = await generateRandomString(20)
+ }
- const { user, account, videoChannel } = await createUserAccountAndChannelAndPlaylist({
- userToCreate,
- channelNames: body.channelName && { name: body.channelName, displayName: body.channelName }
- })
+ const { user, account, videoChannel } = await createUserAccountAndChannelAndPlaylist({
+ userToCreate,
+ channelNames: body.channelName && { name: body.channelName, displayName: body.channelName }
+ })
- auditLogger.create(getAuditIdFromRes(res), new UserAuditView(user.toFormattedJSON({ withAdminFlags: true })))
- logger.info('User %s with its channel and account created.', body.username, lTags(user.username))
+ auditLogger.create(getAuditIdFromRes(res), new UserAuditView(user.toFormattedJSON({ withAdminFlags: true })))
+ logger.info('User %s with its channel and account created.', body.username)
- if (createPassword) {
- // This will send an email for newly created users, so then can set their first password
- logger.info('Sending to user %s a create password email', body.username, lTags(user.username))
+ if (createPassword) {
+ // This will send an email for newly created users, so then can set their first password
+ logger.info('Sending to user %s a create password email', body.username)
- const verificationString = await Redis.Instance.setCreatePasswordVerificationString(user.id)
+ const verificationString = await Redis.Instance.setCreatePasswordVerificationString(user.id)
- Emailer.Instance.addPasswordCreateEmailJob({
- username: userToCreate.username,
- to: user.email,
- language: user.getLanguage(),
- createPasswordUrl: getResetPasswordUrl(user, verificationString)
- })
- }
+ Emailer.Instance.addPasswordCreateEmailJob({
+ username: userToCreate.username,
+ to: user.email,
+ language: user.getLanguage(),
+ createPasswordUrl: getResetPasswordUrl(user, verificationString)
+ })
+ }
- Hooks.runAction('action:api.user.created', { body, user, account, videoChannel, req, res })
+ Hooks.runAction('action:api.user.created', { body, user, account, videoChannel, req, res })
- return res.json({
- user: {
- id: user.id,
- account: {
- id: account.id
+ return res.json({
+ user: {
+ id: user.id,
+ account: {
+ id: account.id
+ }
}
- }
+ })
})
}
@@ -215,13 +218,15 @@ async function unblockUser (req: express.Request, res: express.Response) {
const user = res.locals.user
const byUser = res.locals.oauth.token.User
- await changeUserBlock(res, user, false)
+ return logger.withContext([ user.username, byUser.username ], async () => {
+ await changeUserBlock(res, user, false)
- logger.info(`Unblocked user ${user.username} by moderator ${byUser.username}.`, lTags(user.username, byUser.username))
+ logger.info(`Unblocked user ${user.username} by moderator ${byUser.username}.`)
- Hooks.runAction('action:api.user.unblocked', { user, req, res })
+ Hooks.runAction('action:api.user.unblocked', { user, req, res })
- return res.status(HttpStatusCode.NO_CONTENT_204).end()
+ return res.status(HttpStatusCode.NO_CONTENT_204).end()
+ })
}
async function blockUser (req: express.Request, res: express.Response) {
@@ -229,13 +234,15 @@ async function blockUser (req: express.Request, res: express.Response) {
const byUser = res.locals.oauth.token.User
const reason = req.body.reason
- await changeUserBlock(res, user, true, reason)
+ return logger.withContext([ user.username, byUser.username ], async () => {
+ await changeUserBlock(res, user, true, reason)
- logger.info(`Blocked user ${user.username} by moderator ${byUser.username}.`, lTags(user.username, byUser.username))
+ logger.info(`Blocked user ${user.username} by moderator ${byUser.username}.`)
- Hooks.runAction('action:api.user.blocked', { user, req, res })
+ Hooks.runAction('action:api.user.blocked', { user, req, res })
- return res.status(HttpStatusCode.NO_CONTENT_204).end()
+ return res.status(HttpStatusCode.NO_CONTENT_204).end()
+ })
}
function getUser (req: express.Request, res: express.Response) {
@@ -265,89 +272,99 @@ async function removeUser (req: express.Request, res: express.Response) {
const user = res.locals.user
const byUser = res.locals.oauth.token.User
- auditLogger.delete(getAuditIdFromRes(res), new UserAuditView(user.toFormattedJSON()))
+ return logger.withContext([ user.username, byUser.username ], async () => {
+ auditLogger.delete(getAuditIdFromRes(res), new UserAuditView(user.toFormattedJSON()))
- await retryTransactionWrapper(() => {
- return sequelizeTypescript.transaction(t => {
- // Use a transaction to avoid inconsistencies with hooks (account/channel deletion & federation)
- return user.destroy({ transaction: t })
+ await retryTransactionWrapper(() => {
+ return sequelizeTypescript.transaction(t => {
+ // Use a transaction to avoid inconsistencies with hooks (account/channel deletion & federation)
+ return user.destroy({ transaction: t })
+ })
})
- })
- logger.info(`Removed user ${user.username} by moderator ${byUser.username}.`, lTags(user.username, byUser.username))
+ logger.info(`Removed user ${user.username} by moderator ${byUser.username}.`)
- Hooks.runAction('action:api.user.deleted', { user, req, res })
+ Hooks.runAction('action:api.user.deleted', { user, req, res })
- return res.status(HttpStatusCode.NO_CONTENT_204).end()
+ return res.status(HttpStatusCode.NO_CONTENT_204).end()
+ })
}
async function updateUser (req: express.Request, res: express.Response) {
- const body: UserUpdate = req.body
const userToUpdate = res.locals.user
const byUser = res.locals.oauth.token.User
- const oldUserAuditView = new UserAuditView(userToUpdate.toFormattedJSON())
- const roleChanged = body.role !== undefined && body.role !== userToUpdate.role
-
- const keysToUpdate: (keyof UserUpdate)[] = [
- 'password',
- 'email',
- 'emailVerified',
- 'videoQuota',
- 'videoQuotaDaily',
- 'role',
- 'adminFlags',
- 'pluginAuth'
- ]
-
- for (const key of keysToUpdate) {
- if (body[key] !== undefined) userToUpdate.set(key, body[key])
- }
-
- const user = await userToUpdate.save()
-
- // Destroy user token to refresh rights
- if (roleChanged || body.password !== undefined) {
- await OAuthTokenModel.deleteUserToken({ userId: userToUpdate.id })
- }
- auditLogger.update(getAuditIdFromRes(res), new UserAuditView(user.toFormattedJSON({ withAdminFlags: true })), oldUserAuditView)
+ return logger.withContext([ userToUpdate.username, byUser.username ], async () => {
+ const body: UserUpdate = req.body
+ const oldUserAuditView = new UserAuditView(userToUpdate.toFormattedJSON())
+ const roleChanged = body.role !== undefined && body.role !== userToUpdate.role
+
+ const keysToUpdate: (keyof UserUpdate)[] = [
+ 'password',
+ 'email',
+ 'emailVerified',
+ 'videoQuota',
+ 'videoQuotaDaily',
+ 'role',
+ 'adminFlags',
+ 'pluginAuth'
+ ]
+
+ for (const key of keysToUpdate) {
+ if (body[key] !== undefined) userToUpdate.set(key, body[key])
+ }
+
+ const user = await userToUpdate.save()
- logger.info(`Updated user ${user.username} by moderator ${byUser.username}.`, lTags(user.username, byUser.username))
+ // Destroy user token to refresh rights
+ if (roleChanged || body.password !== undefined) {
+ await OAuthTokenModel.deleteUserToken({ userId: userToUpdate.id })
+ }
+
+ auditLogger.update(getAuditIdFromRes(res), new UserAuditView(user.toFormattedJSON({ withAdminFlags: true })), oldUserAuditView)
- Hooks.runAction('action:api.user.updated', { user, req, res })
+ logger.info(`Updated user ${user.username} by moderator ${byUser.username}.`)
- // Don't need to send this update to followers, these attributes are not federated
+ Hooks.runAction('action:api.user.updated', { user, req, res })
- return res.status(HttpStatusCode.NO_CONTENT_204).end()
+ // Don't need to send this update to followers, these attributes are not federated
+
+ return res.status(HttpStatusCode.NO_CONTENT_204).end()
+ })
}
async function askResetUserPassword (req: express.Request, res: express.Response) {
const user = res.locals.user
- const verificationString = await Redis.Instance.setResetPasswordVerificationString(user.id)
- Emailer.Instance.addPasswordResetEmailJob({
- username: user.username,
- to: user.email,
- language: user.getLanguage(),
- resetPasswordUrl: getResetPasswordUrl(user, verificationString)
- })
+ return logger.withContext([ user.username ], async () => {
+ const verificationString = await Redis.Instance.setResetPasswordVerificationString(user.id)
+ Emailer.Instance.addPasswordResetEmailJob({
+ username: user.username,
+ to: user.email,
+ language: user.getLanguage(),
+ resetPasswordUrl: getResetPasswordUrl(user, verificationString)
+ })
- logger.info(`User ${user.username} asked password reset.`, lTags(user.username))
+ logger.info(`User ${user.username} asked password reset.`)
- return res.status(HttpStatusCode.NO_CONTENT_204).end()
+ return res.status(HttpStatusCode.NO_CONTENT_204).end()
+ })
}
async function resetUserPassword (req: express.Request, res: express.Response) {
const user = res.locals.user
- user.password = req.body.password
- await user.save()
- await Redis.Instance.removePasswordVerificationString(user.id)
- await OAuthTokenModel.deleteUserToken({ userId: user.id })
+ return logger.withContext([ user.username ], async () => {
+ user.password = req.body.password
+
+ await user.save()
+ await Redis.Instance.removePasswordVerificationString(user.id)
+ await OAuthTokenModel.deleteUserToken({ userId: user.id })
- logger.info(`User ${user.username} reset its password.`, lTags(user.username))
+ logger.info(`User ${user.username} reset its password.`)
- return res.status(HttpStatusCode.NO_CONTENT_204).end()
+ return res.status(HttpStatusCode.NO_CONTENT_204).end()
+ })
}
async function changeUserBlock (res: express.Response, user: MUserAccountDefault, block: boolean, reason?: string) {
diff --git a/server/core/controllers/api/users/registrations.ts b/server/core/controllers/api/users/registrations.ts
index 52c9f6a319..630f1b5240 100644
--- a/server/core/controllers/api/users/registrations.ts
+++ b/server/core/controllers/api/users/registrations.ts
@@ -13,7 +13,7 @@ import { Hooks } from '@server/lib/plugins/hooks.js'
import { UserRegistrationModel } from '@server/models/user/user-registration.js'
import express from 'express'
import { auditLoggerFactory, UserAuditView } from '../../../helpers/audit-logger.js'
-import { logger } from '../../../helpers/logger.js'
+import { createLogger } from '../../../helpers/logger.js'
import { CONFIG } from '../../../initializers/config.js'
import { Notifier } from '../../../lib/notifier/index.js'
import {
@@ -42,6 +42,8 @@ import {
usersRequestRegistrationValidator
} from '../../../middlewares/index.js'
+const logger = createLogger()
+
const auditLogger = auditLoggerFactory('users')
const registrationRateLimiter = buildRateLimiter({
diff --git a/server/core/controllers/api/users/token.ts b/server/core/controllers/api/users/token.ts
index 9e915f0b2d..0f79a3080e 100644
--- a/server/core/controllers/api/users/token.ts
+++ b/server/core/controllers/api/users/token.ts
@@ -1,7 +1,7 @@
import { InvalidGrantError } from '@node-oauth/oauth2-server'
import { ResultList, TokenSession } from '@peertube/peertube-models'
import { buildUUID } from '@peertube/peertube-node-utils'
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { CONFIG } from '@server/initializers/config.js'
import { OTP } from '@server/initializers/constants.js'
import { BypassLogin } from '@server/lib/auth/bypass-login.model.js'
@@ -25,6 +25,8 @@ import { OAuthTokenModel } from '@server/models/oauth/oauth-token.js'
import cookieParser from 'cookie-parser'
import express from 'express'
+const logger = createLogger()
+
const tokensRouter = express.Router()
const loginRateLimiter = buildRateLimiter({
diff --git a/server/core/controllers/api/users/user-imports.ts b/server/core/controllers/api/users/user-imports.ts
index 4a4bee9f1d..1c06fd3357 100644
--- a/server/core/controllers/api/users/user-imports.ts
+++ b/server/core/controllers/api/users/user-imports.ts
@@ -7,13 +7,15 @@ import {
userImportRequestResumableValidator
} from '@server/middlewares/validators/users/user-import.js'
import { HttpStatusCode, UserImportState } from '@peertube/peertube-models'
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { UserImportModel } from '@server/models/user/user-import.js'
import { getFSUserImportFilePath } from '@server/lib/paths.js'
import { move } from 'fs-extra/esm'
import { JobQueue } from '@server/lib/job-queue/job-queue.js'
import { saveInTransactionWithRetries } from '@server/helpers/database-utils.js'
+const logger = createLogger()
+
const userImportRouter = express.Router()
userImportRouter.get(
diff --git a/server/core/controllers/api/video-channel-sync.ts b/server/core/controllers/api/video-channel-sync.ts
index 0a0d1ce690..ec0a2fd559 100644
--- a/server/core/controllers/api/video-channel-sync.ts
+++ b/server/core/controllers/api/video-channel-sync.ts
@@ -1,6 +1,6 @@
import { HttpStatusCode, VideoChannelActivityAction, StreamSyncState } from '@peertube/peertube-models'
import { auditLoggerFactory, getAuditIdFromRes, VideoChannelSyncAuditView } from '@server/helpers/audit-logger.js'
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { sequelizeTypescript } from '@server/initializers/database.js'
import {
apiRateLimiter,
@@ -16,6 +16,8 @@ import { VideoChannelSyncModel } from '@server/models/video/video-channel-sync.j
import { MChannelSyncFormattable } from '@server/types/models/index.js'
import express from 'express'
+const logger = createLogger()
+
const videoChannelSyncRouter = express.Router()
const auditLogger = auditLoggerFactory('channel-syncs')
diff --git a/server/core/controllers/api/video-channels/index.ts b/server/core/controllers/api/video-channels/index.ts
index 22a1e9bae5..02c5863301 100644
--- a/server/core/controllers/api/video-channels/index.ts
+++ b/server/core/controllers/api/video-channels/index.ts
@@ -19,7 +19,7 @@ import express from 'express'
import { auditLoggerFactory, getAuditIdFromRes, VideoChannelAuditView } from '../../../helpers/audit-logger.js'
import { resetSequelizeInstance } from '../../../helpers/database-utils.js'
import { buildNSFWFilters, getCountVideos, isUserAbleToSearchRemoteURI } from '../../../helpers/express-utils.js'
-import { logger } from '../../../helpers/logger.js'
+import { createLogger } from '../../../helpers/logger.js'
import { getFormattedObjects } from '../../../helpers/utils.js'
import { sequelizeTypescript } from '../../../initializers/database.js'
import { sendUpdateActor } from '../../../lib/activitypub/send/index.js'
@@ -63,6 +63,8 @@ import { ownershipChannelRouter } from './ownership.js'
import { channelCollaborators } from './video-channel-collaborators.js'
import { videoChannelLogosRouter } from './video-channel-logos.js'
+const logger = createLogger()
+
const auditLogger = auditLoggerFactory('channels')
const videoChannelRouter = express.Router()
diff --git a/server/core/controllers/api/video-channels/ownership.ts b/server/core/controllers/api/video-channels/ownership.ts
index e2be70e951..6ae4486c97 100644
--- a/server/core/controllers/api/video-channels/ownership.ts
+++ b/server/core/controllers/api/video-channels/ownership.ts
@@ -4,7 +4,7 @@ import { VideoChannelActivityModel } from '@server/models/video/video-channel-ac
import { VideoChannelCollaboratorModel } from '@server/models/video/video-channel-collaborator.js'
import { VideoPlaylistModel } from '@server/models/video/video-playlist.js'
import express from 'express'
-import { logger } from '../../../helpers/logger.js'
+import { createLogger } from '../../../helpers/logger.js'
import { getFormattedObjects } from '../../../helpers/utils.js'
import { sequelizeTypescript } from '../../../initializers/database.js'
import { sendUpdateActor } from '../../../lib/activitypub/send/index.js'
@@ -25,6 +25,8 @@ import {
import { ChangeOwnershipModel } from '../../../models/video/change-ownership.js'
import { VideoChannelModel } from '../../../models/video/video-channel.js'
+const logger = createLogger()
+
const ownershipChannelRouter = express.Router()
ownershipChannelRouter.post(
diff --git a/server/core/controllers/api/video-playlist.ts b/server/core/controllers/api/video-playlist.ts
index 64c1b901a8..5da3d4b3a9 100644
--- a/server/core/controllers/api/video-playlist.ts
+++ b/server/core/controllers/api/video-playlist.ts
@@ -25,7 +25,7 @@ import { MVideoPlaylistFull } from '@server/types/models/index.js'
import express from 'express'
import { resetSequelizeInstance, retryTransactionWrapper } from '../../helpers/database-utils.js'
import { createReqFiles } from '../../helpers/express-utils.js'
-import { logger } from '../../helpers/logger.js'
+import { createLogger } from '../../helpers/logger.js'
import { getFormattedObjects } from '../../helpers/utils.js'
import { MIMETYPES, VIDEO_PLAYLIST_PRIVACIES } from '../../initializers/constants.js'
import { sequelizeTypescript } from '../../initializers/database.js'
@@ -57,6 +57,8 @@ import { AccountModel } from '../../models/account/account.js'
import { VideoPlaylistElementModel } from '../../models/video/video-playlist-element.js'
import { VideoPlaylistModel } from '../../models/video/video-playlist.js'
+const logger = createLogger()
+
const reqThumbnailFile = createReqFiles([ 'thumbnailfile' ], MIMETYPES.IMAGE.MIMETYPE_EXT)
const videoPlaylistRouter = express.Router()
@@ -185,65 +187,67 @@ async function createVideoPlaylist (req: express.Request, res: express.Response)
ownerAccountId: res.locals.videoChannel?.Account.id ?? user.Account.id
}) as MVideoPlaylistFull
- videoPlaylist.url = getLocalVideoPlaylistActivityPubUrl(videoPlaylist) // We use the UUID, so set the URL after building the object
+ await logger.withContext([ videoPlaylist.uuid ], async () => {
+ videoPlaylist.url = getLocalVideoPlaylistActivityPubUrl(videoPlaylist) // We use the UUID, so set the URL after building the object
- const videoChannel = res.locals.videoChannel
+ const videoChannel = res.locals.videoChannel
- if (videoChannel && videoPlaylistInfo.videoChannelId) {
- videoPlaylist.videoChannelId = videoChannel.id
- videoPlaylist.VideoChannel = videoChannel
- }
+ if (videoChannel && videoPlaylistInfo.videoChannelId) {
+ videoPlaylist.videoChannelId = videoChannel.id
+ videoPlaylist.VideoChannel = videoChannel
+ }
- const thumbnailField = req.files?.['thumbnailfile']
- const thumbnailModels = thumbnailField
- ? await createLocalPlaylistThumbnailsFromImage({
- inputPath: thumbnailField[0].path,
- playlist: videoPlaylist,
- automaticallyGenerated: false
- })
- : undefined
+ const thumbnailField = req.files?.['thumbnailfile']
+ const thumbnailModels = thumbnailField
+ ? await createLocalPlaylistThumbnailsFromImage({
+ inputPath: thumbnailField[0].path,
+ playlist: videoPlaylist,
+ automaticallyGenerated: false
+ })
+ : undefined
- const videoPlaylistCreated = await retryTransactionWrapper(() => {
- return sequelizeTypescript.transaction(async t => {
- if (videoPlaylist.videoChannelId) {
- videoPlaylist.videoChannelPosition = await VideoPlaylistModel.getNextPositionOf({
- videoChannelId: videoPlaylist.videoChannelId,
- transaction: t
- })
- }
+ const videoPlaylistCreated = await retryTransactionWrapper(() => {
+ return sequelizeTypescript.transaction(async t => {
+ if (videoPlaylist.videoChannelId) {
+ videoPlaylist.videoChannelPosition = await VideoPlaylistModel.getNextPositionOf({
+ videoChannelId: videoPlaylist.videoChannelId,
+ transaction: t
+ })
+ }
- const videoPlaylistCreated = await videoPlaylist.save({ transaction: t }) as MVideoPlaylistFull
+ const videoPlaylistCreated = await videoPlaylist.save({ transaction: t }) as MVideoPlaylistFull
- if (thumbnailModels) {
- await videoPlaylistCreated.replaceAndSaveThumbnails(thumbnailModels, t)
- }
+ if (thumbnailModels) {
+ await videoPlaylistCreated.replaceAndSaveThumbnails(thumbnailModels, t)
+ }
- // We need more attributes for the federation
- videoPlaylistCreated.OwnerAccount = await AccountModel.load(user.Account.id, t)
- await sendCreateVideoPlaylist(videoPlaylistCreated, t)
+ // We need more attributes for the federation
+ videoPlaylistCreated.OwnerAccount = await AccountModel.load(user.Account.id, t)
+ await sendCreateVideoPlaylist(videoPlaylistCreated, t)
- if (videoChannel) {
- await VideoChannelActivityModel.addPlaylistActivity({
- action: VideoChannelActivityAction.CREATE,
- user,
- channel: videoChannel,
- playlist: videoPlaylistCreated,
- transaction: t
- })
- }
+ if (videoChannel) {
+ await VideoChannelActivityModel.addPlaylistActivity({
+ action: VideoChannelActivityAction.CREATE,
+ user,
+ channel: videoChannel,
+ playlist: videoPlaylistCreated,
+ transaction: t
+ })
+ }
- return videoPlaylistCreated
+ return videoPlaylistCreated
+ })
})
- })
- logger.info('Video playlist with uuid %s created.', videoPlaylist.uuid)
+ logger.info('Video playlist with uuid %s created.', videoPlaylist.uuid)
- return res.json({
- videoPlaylist: {
- id: videoPlaylistCreated.id,
- shortUUID: uuidToShort(videoPlaylistCreated.uuid),
- uuid: videoPlaylistCreated.uuid
- }
+ return res.json({
+ videoPlaylist: {
+ id: videoPlaylistCreated.id,
+ shortUUID: uuidToShort(videoPlaylistCreated.uuid),
+ uuid: videoPlaylistCreated.uuid
+ }
+ })
})
}
@@ -256,161 +260,165 @@ async function updateVideoPlaylist (req: express.Request, res: express.Response)
const thumbnailField = req.files?.['thumbnailfile']
- try {
- // A concurrent request updating the same playlist thumbnails can hit the unique index on thumbnail size
- await retryTransactionWrapper(async () => {
- // Build the thumbnails here so it's rebuilt on retry
- const thumbnailModels = thumbnailField
- ? await createLocalPlaylistThumbnailsFromImage({
- inputPath: thumbnailField[0].path,
- playlist,
- automaticallyGenerated: false
- })
- : undefined
-
- return sequelizeTypescript.transaction(async t => {
- // If this is a retried attempt, sequelize would otherwise think this instance has not changed
- await playlist.reload({ transaction: t })
-
- let removedFromChannel: { id: number, position: number }
-
- const newChannel = res.locals.videoChannel
- const user = res.locals.oauth.token.User
-
- // Had a channel, but the user changed it (to null or another channel)
- if (playlist.videoChannelId && body.videoChannelId !== undefined && body.videoChannelId !== playlist.videoChannelId) {
- await VideoChannelActivityModel.addPlaylistActivity({
- action: VideoChannelActivityAction.REMOVE_CHANNEL_OWNERSHIP,
- user,
- channel: playlist.VideoChannel,
+ await logger.withContext([ playlist.uuid ], async () => {
+ try {
+ // A concurrent request updating the same playlist thumbnails can hit the unique index on thumbnail size
+ await retryTransactionWrapper(async () => {
+ // Build the thumbnails here so it's rebuilt on retry
+ const thumbnailModels = thumbnailField
+ ? await createLocalPlaylistThumbnailsFromImage({
+ inputPath: thumbnailField[0].path,
playlist,
- transaction: t
+ automaticallyGenerated: false
})
-
- removedFromChannel = {
- id: playlist.videoChannelId,
- position: playlist.videoChannelPosition
+ : undefined
+
+ return sequelizeTypescript.transaction(async t => {
+ // If this is a retried attempt, sequelize would otherwise think this instance has not changed
+ await playlist.reload({ transaction: t })
+
+ let removedFromChannel: { id: number, position: number }
+
+ const newChannel = res.locals.videoChannel
+ const user = res.locals.oauth.token.User
+
+ // Had a channel, but the user changed it (to null or another channel)
+ if (playlist.videoChannelId && body.videoChannelId !== undefined && body.videoChannelId !== playlist.videoChannelId) {
+ await VideoChannelActivityModel.addPlaylistActivity({
+ action: VideoChannelActivityAction.REMOVE_CHANNEL_OWNERSHIP,
+ user,
+ channel: playlist.VideoChannel,
+ playlist,
+ transaction: t
+ })
+
+ removedFromChannel = {
+ id: playlist.videoChannelId,
+ position: playlist.videoChannelPosition
+ }
+
+ playlist.videoChannelId = null
+ playlist.VideoChannel = null
}
- playlist.videoChannelId = null
- playlist.VideoChannel = null
- }
-
- if (newChannel && newChannel.id !== playlist.videoChannelId) {
- await VideoChannelActivityModel.addPlaylistActivity({
- action: VideoChannelActivityAction.CREATE_CHANNEL_OWNERSHIP,
- user,
- channel: newChannel,
- playlist,
- transaction: t
- })
-
- playlist.videoChannelPosition = await VideoPlaylistModel.getNextPositionOf({
- videoChannelId: newChannel.id,
- transaction: t
- })
-
- playlist.videoChannelId = newChannel.id
- playlist.VideoChannel = newChannel
- } else if (newChannel) {
- await VideoChannelActivityModel.addPlaylistActivity({
- action: VideoChannelActivityAction.UPDATE,
- user: res.locals.oauth.token.User,
- channel: newChannel,
- playlist,
- transaction: t
- })
- }
+ if (newChannel && newChannel.id !== playlist.videoChannelId) {
+ await VideoChannelActivityModel.addPlaylistActivity({
+ action: VideoChannelActivityAction.CREATE_CHANNEL_OWNERSHIP,
+ user,
+ channel: newChannel,
+ playlist,
+ transaction: t
+ })
+
+ playlist.videoChannelPosition = await VideoPlaylistModel.getNextPositionOf({
+ videoChannelId: newChannel.id,
+ transaction: t
+ })
+
+ playlist.videoChannelId = newChannel.id
+ playlist.VideoChannel = newChannel
+ } else if (newChannel) {
+ await VideoChannelActivityModel.addPlaylistActivity({
+ action: VideoChannelActivityAction.UPDATE,
+ user: res.locals.oauth.token.User,
+ channel: newChannel,
+ playlist,
+ transaction: t
+ })
+ }
- if (body.displayName !== undefined) playlist.name = body.displayName
- if (body.description !== undefined) playlist.description = body.description
+ if (body.displayName !== undefined) playlist.name = body.displayName
+ if (body.description !== undefined) playlist.description = body.description
- if (body.privacy !== undefined) {
- playlist.privacy = forceNumber(body.privacy) as VideoPlaylistPrivacyType
+ if (body.privacy !== undefined) {
+ playlist.privacy = forceNumber(body.privacy) as VideoPlaylistPrivacyType
- if (wasNotPrivatePlaylist === true && playlist.privacy === VideoPlaylistPrivacy.PRIVATE) {
- await sendDeleteVideoPlaylist(playlist, t)
+ if (wasNotPrivatePlaylist === true && playlist.privacy === VideoPlaylistPrivacy.PRIVATE) {
+ await sendDeleteVideoPlaylist(playlist, t)
+ }
}
- }
- const playlistUpdated = await playlist.save({ transaction: t })
+ const playlistUpdated = await playlist.save({ transaction: t })
- if (thumbnailModels) {
- await playlistUpdated.replaceAndSaveThumbnails(thumbnailModels, t)
- }
+ if (thumbnailModels) {
+ await playlistUpdated.replaceAndSaveThumbnails(thumbnailModels, t)
+ }
- const isNewPlaylist = wasPrivatePlaylist && playlistUpdated.privacy !== VideoPlaylistPrivacy.PRIVATE
+ const isNewPlaylist = wasPrivatePlaylist && playlistUpdated.privacy !== VideoPlaylistPrivacy.PRIVATE
- if (isNewPlaylist) {
- await sendCreateVideoPlaylist(playlistUpdated, t)
- } else {
- await sendUpdateVideoPlaylist(playlistUpdated, t)
- }
+ if (isNewPlaylist) {
+ await sendCreateVideoPlaylist(playlistUpdated, t)
+ } else {
+ await sendUpdateVideoPlaylist(playlistUpdated, t)
+ }
- if (removedFromChannel) {
- await VideoPlaylistModel.increasePositionOf({
- videoChannelId: removedFromChannel.id,
- fromPosition: removedFromChannel.position,
- by: -1,
- transaction: t
- })
+ if (removedFromChannel) {
+ await VideoPlaylistModel.increasePositionOf({
+ videoChannelId: removedFromChannel.id,
+ fromPosition: removedFromChannel.position,
+ by: -1,
+ transaction: t
+ })
- await sendPlaylistPositionUpdateOfChannel(removedFromChannel.id, t)
- }
+ await sendPlaylistPositionUpdateOfChannel(removedFromChannel.id, t)
+ }
- logger.info('Video playlist %s updated.', playlist.uuid)
+ logger.info('Video playlist %s updated.', playlist.uuid)
- return playlistUpdated
- })
- }, { retryUniqueConstraintViolation: true })
- } catch (err) {
- logger.debug('Cannot update the video playlist.', { err })
+ return playlistUpdated
+ })
+ }, { retryUniqueConstraintViolation: true })
+ } catch (err) {
+ logger.debug('Cannot update the video playlist.', { err })
- // Leave the instance clean for any other code path that might reuse it after this handler returns
- await resetSequelizeInstance(playlist)
+ // Leave the instance clean for any other code path that might reuse it after this handler returns
+ await resetSequelizeInstance(playlist)
- throw err
- }
+ throw err
+ }
- return res.type('json').status(HttpStatusCode.NO_CONTENT_204).end()
+ return res.type('json').status(HttpStatusCode.NO_CONTENT_204).end()
+ })
}
async function removeVideoPlaylist (req: express.Request, res: express.Response) {
const videoPlaylistInstance = res.locals.videoPlaylistSummary
const positionToDelete = videoPlaylistInstance.videoChannelPosition
- await sequelizeTypescript.transaction(async t => {
- await videoPlaylistInstance.destroy({ transaction: t })
+ await logger.withContext([ videoPlaylistInstance.uuid ], async () => {
+ await sequelizeTypescript.transaction(async t => {
+ await videoPlaylistInstance.destroy({ transaction: t })
- if (videoPlaylistInstance.privacy !== VideoPlaylistPrivacy.PRIVATE) {
- await sendDeleteVideoPlaylist(videoPlaylistInstance, t)
- }
+ if (videoPlaylistInstance.privacy !== VideoPlaylistPrivacy.PRIVATE) {
+ await sendDeleteVideoPlaylist(videoPlaylistInstance, t)
+ }
- if (videoPlaylistInstance.videoChannelId) {
- await VideoPlaylistModel.increasePositionOf({
- videoChannelId: videoPlaylistInstance.videoChannelId,
- fromPosition: positionToDelete,
- by: -1,
- transaction: t
- })
- }
+ if (videoPlaylistInstance.videoChannelId) {
+ await VideoPlaylistModel.increasePositionOf({
+ videoChannelId: videoPlaylistInstance.videoChannelId,
+ fromPosition: positionToDelete,
+ by: -1,
+ transaction: t
+ })
+ }
- if (videoPlaylistInstance.videoChannelId) {
- await sendPlaylistPositionUpdateOfChannel(videoPlaylistInstance.videoChannelId, t)
+ if (videoPlaylistInstance.videoChannelId) {
+ await sendPlaylistPositionUpdateOfChannel(videoPlaylistInstance.videoChannelId, t)
- await VideoChannelActivityModel.addPlaylistActivity({
- action: VideoChannelActivityAction.DELETE,
- user: res.locals.oauth.token.User,
- channel: videoPlaylistInstance.VideoChannel,
- playlist: videoPlaylistInstance,
- transaction: t
- })
- }
+ await VideoChannelActivityModel.addPlaylistActivity({
+ action: VideoChannelActivityAction.DELETE,
+ user: res.locals.oauth.token.User,
+ channel: videoPlaylistInstance.VideoChannel,
+ playlist: videoPlaylistInstance,
+ transaction: t
+ })
+ }
- logger.info('Video playlist %s deleted.', videoPlaylistInstance.uuid)
- })
+ logger.info('Video playlist %s deleted.', videoPlaylistInstance.uuid)
+ })
- return res.type('json').status(HttpStatusCode.NO_CONTENT_204).end()
+ return res.type('json').status(HttpStatusCode.NO_CONTENT_204).end()
+ })
}
// ---------------------------------------------------------------------------
diff --git a/server/core/controllers/api/videos/blacklist.ts b/server/core/controllers/api/videos/blacklist.ts
index 5cb6203457..72a6b14047 100644
--- a/server/core/controllers/api/videos/blacklist.ts
+++ b/server/core/controllers/api/videos/blacklist.ts
@@ -1,7 +1,7 @@
-import express from 'express'
-import { blacklistVideo, unblacklistVideo } from '@server/lib/video-blacklist.js'
import { HttpStatusCode, UserRight, VideoBlacklistCreate, VideoBlacklistUpdate } from '@peertube/peertube-models'
-import { logger } from '../../../helpers/logger.js'
+import { blacklistVideo, unblacklistVideo } from '@server/lib/video-blacklist.js'
+import express from 'express'
+import { createLogger } from '../../../helpers/logger.js'
import { getFormattedObjects } from '../../../helpers/utils.js'
import { sequelizeTypescript } from '../../../initializers/database.js'
import {
@@ -20,6 +20,8 @@ import {
} from '../../../middlewares/index.js'
import { VideoBlacklistModel } from '../../../models/video/video-blacklist.js'
+const logger = createLogger()
+
const blacklistRouter = express.Router()
blacklistRouter.post(
@@ -73,11 +75,13 @@ async function addVideoToBlacklistController (req: express.Request, res: express
const videoInstance = res.locals.videoWithRights
const body: VideoBlacklistCreate = req.body
- await blacklistVideo(videoInstance, body)
+ await logger.withContext([ videoInstance.uuid ], async () => {
+ await blacklistVideo(videoInstance, body)
- logger.info('Video %s blacklisted.', videoInstance.uuid)
+ logger.info('Video %s blacklisted.', videoInstance.uuid)
- return res.type('json').status(HttpStatusCode.NO_CONTENT_204).end()
+ return res.type('json').status(HttpStatusCode.NO_CONTENT_204).end()
+ })
}
async function updateVideoBlacklistController (req: express.Request, res: express.Response) {
diff --git a/server/core/controllers/api/videos/captions.ts b/server/core/controllers/api/videos/captions.ts
index 51ef75c839..3a63f56a68 100644
--- a/server/core/controllers/api/videos/captions.ts
+++ b/server/core/controllers/api/videos/captions.ts
@@ -6,7 +6,7 @@ import { VideoChannelActivityModel } from '@server/models/video/video-channel-ac
import { VideoJobInfoModel } from '@server/models/video/video-job-info.js'
import express from 'express'
import { createReqFiles } from '../../../helpers/express-utils.js'
-import { logger, loggerTagsFactory } from '../../../helpers/logger.js'
+import { createLogger } from '../../../helpers/logger.js'
import { getFormattedObjects } from '../../../helpers/utils.js'
import { MIMETYPES } from '../../../initializers/constants.js'
import { sequelizeTypescript } from '../../../initializers/database.js'
@@ -20,7 +20,7 @@ import {
} from '../../../middlewares/validators/index.js'
import { VideoCaptionModel } from '../../../models/video/video-caption.js'
-const lTags = loggerTagsFactory('api', 'video-caption')
+const logger = createLogger('api', 'caption')
const reqVideoCaptionAdd = createReqFiles([ 'captionfile' ], MIMETYPES.VIDEO_CAPTIONS.MIMETYPE_EXT)
@@ -58,17 +58,19 @@ export {
// ---------------------------------------------------------------------------
-async function createGenerateVideoCaption (req: express.Request, res: express.Response) {
+function createGenerateVideoCaption (req: express.Request, res: express.Response) {
const video = res.locals.videoWithRights
- const body = req.body as VideoCaptionGenerate
- if (body.forceTranscription === true) {
- await VideoJobInfoModel.abortAllTasks(video.uuid, 'pendingTranscription')
- }
+ return logger.withContext([ video.uuid ], async () => {
+ const body = req.body as VideoCaptionGenerate
+ if (body.forceTranscription === true) {
+ await VideoJobInfoModel.abortAllTasks(video.uuid, 'pendingTranscription')
+ }
- await createTranscriptionTaskIfNeeded(video)
+ await createTranscriptionTaskIfNeeded(video)
- return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
+ return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
+ })
}
async function listVideoCaptions (req: express.Request, res: express.Response) {
@@ -77,73 +79,78 @@ async function listVideoCaptions (req: express.Request, res: express.Response) {
return res.json(getFormattedObjects(data, data.length))
}
-async function createVideoCaption (req: express.Request, res: express.Response) {
+function createVideoCaption (req: express.Request, res: express.Response) {
const videoCaptionPhysicalFile: Express.Multer.File = req.files['captionfile'][0]
const captionPath = videoCaptionPhysicalFile.path
const video = res.locals.videoFull
- const captionLanguage = req.params.captionLanguage
+ return logger.withContext([ video.uuid ], async () => {
+ const captionLanguage = req.params.captionLanguage
- const videoCaption = await createLocalCaption({
- video,
- language: captionLanguage,
- path: captionPath,
- automaticallyGenerated: false
- })
+ const videoCaption = await createLocalCaption({
+ video,
+ language: captionLanguage,
+ path: captionPath,
+ automaticallyGenerated: false
+ })
- if (videoCaption.m3u8Filename) {
- await updateHLSMasterOnCaptionChangeIfNeeded(video)
- }
-
- await retryTransactionWrapper(() => {
- return sequelizeTypescript.transaction(async t => {
- await VideoChannelActivityModel.addVideoActivity({
- action: VideoChannelActivityAction.UPDATE_CAPTIONS,
- user: res.locals.oauth.token.User,
- channel: video.VideoChannel,
- video,
- transaction: t
+ if (videoCaption.m3u8Filename) {
+ await updateHLSMasterOnCaptionChangeIfNeeded(video)
+ }
+
+ await retryTransactionWrapper(() => {
+ return sequelizeTypescript.transaction(async t => {
+ await VideoChannelActivityModel.addVideoActivity({
+ action: VideoChannelActivityAction.UPDATE_CAPTIONS,
+ user: res.locals.oauth.token.User,
+ channel: video.VideoChannel,
+ video,
+ transaction: t
+ })
+
+ scheduleVideoFederation({ video, transaction: t })
})
-
- scheduleVideoFederation({ video, transaction: t })
})
- })
- Hooks.runAction('action:api.video-caption.created', { caption: videoCaption, req, res })
+ Hooks.runAction('action:api.video-caption.created', { caption: videoCaption, req, res })
- return res.status(HttpStatusCode.NO_CONTENT_204).end()
+ return res.status(HttpStatusCode.NO_CONTENT_204).end()
+ })
}
async function deleteVideoCaption (req: express.Request, res: express.Response) {
const video = res.locals.videoFull
const videoCaption = res.locals.videoCaption
- const hasM3U8 = !!videoCaption.m3u8Filename
- await sequelizeTypescript.transaction(async t => {
- await videoCaption.destroy({ transaction: t })
- })
+ return logger.withContext([ video.uuid ], async () => {
+ const hasM3U8 = !!videoCaption.m3u8Filename
- if (hasM3U8) {
- await updateHLSMasterOnCaptionChangeIfNeeded(video)
- }
-
- await retryTransactionWrapper(() => {
- return sequelizeTypescript.transaction(async t => {
- await VideoChannelActivityModel.addVideoActivity({
- action: VideoChannelActivityAction.UPDATE_CAPTIONS,
- user: res.locals.oauth.token.User,
- channel: video.VideoChannel,
- video,
- transaction: t
- })
+ await sequelizeTypescript.transaction(async t => {
+ await videoCaption.destroy({ transaction: t })
+ })
- scheduleVideoFederation({ video, transaction: t })
+ if (hasM3U8) {
+ await updateHLSMasterOnCaptionChangeIfNeeded(video)
+ }
+
+ await retryTransactionWrapper(() => {
+ return sequelizeTypescript.transaction(async t => {
+ await VideoChannelActivityModel.addVideoActivity({
+ action: VideoChannelActivityAction.UPDATE_CAPTIONS,
+ user: res.locals.oauth.token.User,
+ channel: video.VideoChannel,
+ video,
+ transaction: t
+ })
+
+ scheduleVideoFederation({ video, transaction: t })
+ })
})
- })
- logger.info('Video caption %s of video %s deleted.', videoCaption.language, video.uuid, lTags(video.uuid))
+ logger.info('Video caption %s of video %s deleted.', videoCaption.language, video.uuid)
- Hooks.runAction('action:api.video-caption.deleted', { caption: videoCaption, req, res })
+ Hooks.runAction('action:api.video-caption.deleted', { caption: videoCaption, req, res })
- return res.type('json').status(HttpStatusCode.NO_CONTENT_204).end()
+ return res.type('json').status(HttpStatusCode.NO_CONTENT_204).end()
+ })
}
diff --git a/server/core/controllers/api/videos/chapters.ts b/server/core/controllers/api/videos/chapters.ts
index bb4d6f3305..629a6fa135 100644
--- a/server/core/controllers/api/videos/chapters.ts
+++ b/server/core/controllers/api/videos/chapters.ts
@@ -1,5 +1,6 @@
import { HttpStatusCode, VideoChannelActivityAction, VideoChapterUpdate } from '@peertube/peertube-models'
import { retryTransactionWrapper } from '@server/helpers/database-utils.js'
+import { createLogger } from '@server/helpers/logger.js'
import { sequelizeTypescript } from '@server/initializers/database.js'
import { scheduleVideoFederation } from '@server/lib/activitypub/videos/federate.js'
import { replaceChapters } from '@server/lib/video-chapters.js'
@@ -9,6 +10,8 @@ import express from 'express'
import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate } from '../../../middlewares/index.js'
import { updateVideoChaptersValidator, videoGetValidatorFactory } from '../../../middlewares/validators/index.js'
+const logger = createLogger('api', 'chapter')
+
const videoChaptersRouter = express.Router()
videoChaptersRouter.get(
@@ -42,21 +45,23 @@ async function replaceVideoChapters (req: express.Request, res: express.Response
const body = req.body as VideoChapterUpdate
const video = res.locals.videoFull
- await retryTransactionWrapper(() => {
- return sequelizeTypescript.transaction(async t => {
- await replaceChapters({ video, chapters: body.chapters, transaction: t })
+ await logger.withContext([ video.uuid ], async () => {
+ await retryTransactionWrapper(() => {
+ return sequelizeTypescript.transaction(async t => {
+ await replaceChapters({ video, chapters: body.chapters, transaction: t })
- await VideoChannelActivityModel.addVideoActivity({
- action: VideoChannelActivityAction.UPDATE_CHAPTERS,
- user: res.locals.oauth.token.User,
- channel: video.VideoChannel,
- video,
- transaction: t
- })
+ await VideoChannelActivityModel.addVideoActivity({
+ action: VideoChannelActivityAction.UPDATE_CHAPTERS,
+ user: res.locals.oauth.token.User,
+ channel: video.VideoChannel,
+ video,
+ transaction: t
+ })
- scheduleVideoFederation({ video, transaction: t })
+ scheduleVideoFederation({ video, transaction: t })
+ })
})
- })
- return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
+ return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
+ })
}
diff --git a/server/core/controllers/api/videos/embed-privacy.ts b/server/core/controllers/api/videos/embed-privacy.ts
index c0650b1501..7eb37eb484 100644
--- a/server/core/controllers/api/videos/embed-privacy.ts
+++ b/server/core/controllers/api/videos/embed-privacy.ts
@@ -8,7 +8,7 @@ import {
VideoEmbedPrivacyUpdate
} from '@peertube/peertube-models'
import { getAuthUser } from '@server/helpers/express-utils.js'
-import { logger, loggerTagsFactory } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { VIDEO_EMBED_PRIVACY_POLICIES, WEBSERVER } from '@server/initializers/constants.js'
import { scheduleVideoFederation } from '@server/lib/activitypub/videos/index.js'
import { checkCanManageVideo } from '@server/middlewares/validators/shared/videos.js'
@@ -25,7 +25,8 @@ import {
updateVideoEmbedPrivacyValidator
} from '../../../middlewares/validators/index.js'
-const lTags = loggerTagsFactory('api', 'video', 'embed-privacy')
+const logger = createLogger('api', 'video', 'embed-privacy')
+
const videoEmbedPrivacyRouter = express.Router()
videoEmbedPrivacyRouter.get(
@@ -107,30 +108,33 @@ async function isVideoEmbedOnDomainAllowed (req: express.Request, res: express.R
return res.json({ domainAllowed, userBypassAllowed } satisfies VideoEmbedPrivacyAllowed)
}
-async function updateVideoEmbedPrivacy (req: express.Request, res: express.Response) {
+function updateVideoEmbedPrivacy (req: express.Request, res: express.Response) {
const video = res.locals.videoFull
- const body = req.body as VideoEmbedPrivacyUpdate
- await VideoPasswordModel.sequelize.transaction(async (t: Transaction) => {
- video.embedPrivacyPolicy = body.policy
+ return logger.withContext([ video.uuid ], async () => {
+ const body = req.body as VideoEmbedPrivacyUpdate
- await video.save({ transaction: t })
+ await VideoPasswordModel.sequelize.transaction(async (t: Transaction) => {
+ video.embedPrivacyPolicy = body.policy
- await VideoEmbedPrivacyDomainModel.deleteAllDomains(video.id, t)
- await VideoEmbedPrivacyDomainModel.addDomains(body.domains, video.id, t)
+ await video.save({ transaction: t })
- await VideoChannelActivityModel.addVideoActivity({
- action: VideoChannelActivityAction.UPDATE_EMBED_POLICY,
- user: res.locals.oauth.token.User,
- channel: video.VideoChannel,
- video,
- transaction: t
- })
+ await VideoEmbedPrivacyDomainModel.deleteAllDomains(video.id, t)
+ await VideoEmbedPrivacyDomainModel.addDomains(body.domains, video.id, t)
- scheduleVideoFederation({ video, transaction: t })
- })
+ await VideoChannelActivityModel.addVideoActivity({
+ action: VideoChannelActivityAction.UPDATE_EMBED_POLICY,
+ user: res.locals.oauth.token.User,
+ channel: video.VideoChannel,
+ video,
+ transaction: t
+ })
- logger.info(`Video embed policy for video with name ${video.name} and uuid ${video.uuid} have been updated`, lTags(video.uuid))
+ scheduleVideoFederation({ video, transaction: t })
+ })
+
+ logger.info(`Video embed policy for video with name ${video.name} and uuid ${video.uuid} have been updated`)
- return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
+ return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
+ })
}
diff --git a/server/core/controllers/api/videos/files.ts b/server/core/controllers/api/videos/files.ts
index 4c9911bccf..42a7979e06 100644
--- a/server/core/controllers/api/videos/files.ts
+++ b/server/core/controllers/api/videos/files.ts
@@ -1,5 +1,5 @@
import { HttpStatusCode, UserRight } from '@peertube/peertube-models'
-import { logger, loggerTagsFactory } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { scheduleVideoFederation } from '@server/lib/activitypub/videos/index.js'
import { updateM3U8AndShaPlaylist } from '@server/lib/hls.js'
import { removeAllWebVideoFiles, removeHLSFile, removeHLSPlaylist, removeWebVideoFile } from '@server/lib/video-file.js'
@@ -18,7 +18,8 @@ import {
videoGetValidatorFactory
} from '../../../middlewares/index.js'
-const lTags = loggerTagsFactory('api', 'video')
+const logger = createLogger('api', 'video')
+
const filesRouter = express.Router()
filesRouter.get(
@@ -77,26 +78,30 @@ async function getVideoFileMetadata (req: express.Request, res: express.Response
async function removeHLSPlaylistController (req: express.Request, res: express.Response) {
const video = res.locals.videoFull
- logger.info('Deleting HLS playlist of %s.', video.url, lTags(video.uuid))
- await removeHLSPlaylist(video)
+ return logger.withContext([ video.uuid ], async () => {
+ logger.info('Deleting HLS playlist of %s.', video.url)
+ await removeHLSPlaylist(video)
- scheduleVideoFederation({ video })
+ scheduleVideoFederation({ video })
- return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
+ return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
+ })
}
async function removeHLSFileController (req: express.Request, res: express.Response) {
const video = res.locals.videoFull
const videoFileId = +req.params.videoFileId
- logger.info('Deleting HLS file %d of %s.', videoFileId, video.url, lTags(video.uuid))
+ return logger.withContext([ video.uuid ], async () => {
+ logger.info('Deleting HLS file %d of %s.', videoFileId, video.url)
- const playlist = await removeHLSFile(video, videoFileId)
- if (playlist) await updateM3U8AndShaPlaylist(video, playlist)
+ const playlist = await removeHLSFile(video, videoFileId)
+ if (playlist) await updateM3U8AndShaPlaylist(video, playlist)
- scheduleVideoFederation({ video })
+ scheduleVideoFederation({ video })
- return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
+ return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
+ })
}
// ---------------------------------------------------------------------------
@@ -104,22 +109,26 @@ async function removeHLSFileController (req: express.Request, res: express.Respo
async function removeAllWebVideoFilesController (req: express.Request, res: express.Response) {
const video = res.locals.videoFull
- logger.info('Deleting Web Video files of %s.', video.url, lTags(video.uuid))
+ return logger.withContext([ video.uuid ], async () => {
+ logger.info('Deleting Web Video files of %s.', video.url)
- await removeAllWebVideoFiles(video)
- scheduleVideoFederation({ video })
+ await removeAllWebVideoFiles(video)
+ scheduleVideoFederation({ video })
- return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
+ return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
+ })
}
async function removeWebVideoFileController (req: express.Request, res: express.Response) {
const video = res.locals.videoFull
-
const videoFileId = +req.params.videoFileId
- logger.info('Deleting Web Video file %d of %s.', videoFileId, video.url, lTags(video.uuid))
- await removeWebVideoFile(video, videoFileId)
- scheduleVideoFederation({ video })
+ return logger.withContext([ video.uuid ], async () => {
+ logger.info('Deleting Web Video file %d of %s.', videoFileId, video.url)
+
+ await removeWebVideoFile(video, videoFileId)
+ scheduleVideoFederation({ video })
- return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
+ return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
+ })
}
diff --git a/server/core/controllers/api/videos/import.ts b/server/core/controllers/api/videos/import.ts
index 8a032cb5da..eae98c5692 100644
--- a/server/core/controllers/api/videos/import.ts
+++ b/server/core/controllers/api/videos/import.ts
@@ -22,7 +22,7 @@ import { join } from 'path'
import { auditLoggerFactory, getAuditIdFromRes, VideoImportAuditView } from '../../../helpers/audit-logger.js'
import { isArray } from '../../../helpers/custom-validators/misc.js'
import { cleanUpReqFiles, createReqFiles } from '../../../helpers/express-utils.js'
-import { logger } from '../../../helpers/logger.js'
+import { createLogger } from '../../../helpers/logger.js'
import { CONFIG } from '../../../initializers/config.js'
import { MIMETYPES } from '../../../initializers/constants.js'
import { JobQueue } from '../../../lib/job-queue/job-queue.js'
@@ -36,6 +36,8 @@ import {
videoImportRetryValidator
} from '../../../middlewares/index.js'
+const logger = createLogger()
+
const auditLogger = auditLoggerFactory('video-imports')
const videoImportsRouter = express.Router()
@@ -140,42 +142,44 @@ async function handleTorrentImport (req: express.Request, res: express.Response,
importType: 'torrent'
})
- const thumbnails = await processThumbnails(req, video)
-
- const videoImport = await insertFromImportIntoDB({
- video,
- thumbnails,
- videoChannel: res.locals.videoChannel,
- tags: body.tags || undefined,
- user,
- videoPasswords: body.videoPasswords,
- videoImportAttributes: {
- magnetUri,
- torrentName,
- state: VideoImportState.PENDING,
- userId: user.id
- }
- })
+ await logger.withContext([ video.uuid ], async () => {
+ const thumbnails = await processThumbnails(req, video)
+
+ const videoImport = await insertFromImportIntoDB({
+ video,
+ thumbnails,
+ videoChannel: res.locals.videoChannel,
+ tags: body.tags || undefined,
+ user,
+ videoPasswords: body.videoPasswords,
+ videoImportAttributes: {
+ magnetUri,
+ torrentName,
+ state: VideoImportState.PENDING,
+ userId: user.id
+ }
+ })
- const payload: VideoImportPayload = {
- type: torrentfile
- ? 'torrent-file'
- : 'magnet-uri',
+ const payload: VideoImportPayload = {
+ type: torrentfile
+ ? 'torrent-file'
+ : 'magnet-uri',
- videoImportId: videoImport.id,
- preventException: false,
- generateTranscription: body.generateTranscription,
- torrentPath: torrentfile?.path ?? null
- }
+ videoImportId: videoImport.id,
+ preventException: false,
+ generateTranscription: body.generateTranscription,
+ torrentPath: torrentfile?.path ?? null
+ }
- videoImport.payload = payload
- await videoImport.save()
+ videoImport.payload = payload
+ await videoImport.save()
- await JobQueue.Instance.createJob({ type: 'video-import', payload })
+ await JobQueue.Instance.createJob({ type: 'video-import', payload })
- auditLogger.create(getAuditIdFromRes(res), new VideoImportAuditView(videoImport.toFormattedJSON()))
+ auditLogger.create(getAuditIdFromRes(res), new VideoImportAuditView(videoImport.toFormattedJSON()))
- return res.json(videoImport.toFormattedJSON()).end()
+ return res.json(videoImport.toFormattedJSON()).end()
+ })
}
function statusFromYtDlImportError (err: YoutubeDlImportError): HttpStatusCodeType {
diff --git a/server/core/controllers/api/videos/index.ts b/server/core/controllers/api/videos/index.ts
index 2f1a563b16..f2b4be4b83 100644
--- a/server/core/controllers/api/videos/index.ts
+++ b/server/core/controllers/api/videos/index.ts
@@ -7,7 +7,7 @@ import { VideoChannelActivityModel } from '@server/models/video/video-channel-ac
import express from 'express'
import { auditLoggerFactory, getAuditIdFromRes, VideoAuditView } from '../../../helpers/audit-logger.js'
import { buildNSFWFilters, getCountVideos } from '../../../helpers/express-utils.js'
-import { logger } from '../../../helpers/logger.js'
+import { createLogger } from '../../../helpers/logger.js'
import { getFormattedObjects } from '../../../helpers/utils.js'
import {
VIDEO_CATEGORIES,
@@ -57,6 +57,8 @@ import { updateRouter } from './update.js'
import { uploadRouter } from './upload.js'
import { viewRouter } from './view.js'
+const logger = createLogger()
+
const auditLogger = auditLoggerFactory('videos')
const videosRouter = express.Router()
diff --git a/server/core/controllers/api/videos/live.ts b/server/core/controllers/api/videos/live.ts
index 557785dc69..4db1c6a44e 100644
--- a/server/core/controllers/api/videos/live.ts
+++ b/server/core/controllers/api/videos/live.ts
@@ -33,7 +33,7 @@ import { VideoLiveSessionModel } from '@server/models/video/video-live-session.j
import { MVideoLive } from '@server/types/models/index.js'
import express from 'express'
import { Transaction } from 'sequelize'
-import { logger, loggerTagsFactory } from '../../../helpers/logger.js'
+import { createLogger } from '../../../helpers/logger.js'
import {
asyncMiddleware,
asyncRetryTransactionMiddleware,
@@ -43,7 +43,7 @@ import {
setLiveSessionsSort
} from '../../../middlewares/index.js'
-const lTags = loggerTagsFactory('api', 'live')
+const logger = createLogger('api', 'live')
const liveRouter = express.Router()
@@ -137,41 +137,43 @@ async function updateLiveVideo (req: express.Request, res: express.Response) {
const video = res.locals.videoFull
const videoLive = res.locals.videoLive
- await retryTransactionWrapper(() => {
- return sequelizeTypescript.transaction(async t => {
- const newReplaySettingModel = await updateReplaySettings(videoLive, body, t)
+ return logger.withContext([ video.uuid ], async () => {
+ await retryTransactionWrapper(() => {
+ return sequelizeTypescript.transaction(async t => {
+ const newReplaySettingModel = await updateReplaySettings(videoLive, body, t)
- if (newReplaySettingModel) videoLive.replaySettingId = newReplaySettingModel.id
- else videoLive.replaySettingId = null
+ if (newReplaySettingModel) videoLive.replaySettingId = newReplaySettingModel.id
+ else videoLive.replaySettingId = null
- if (exists(body.permanentLive)) videoLive.permanentLive = body.permanentLive
- if (exists(body.latencyMode)) videoLive.latencyMode = body.latencyMode
- if (exists(body.dvrWindow)) videoLive.dvrWindow = body.dvrWindow
+ if (exists(body.permanentLive)) videoLive.permanentLive = body.permanentLive
+ if (exists(body.latencyMode)) videoLive.latencyMode = body.latencyMode
+ if (exists(body.dvrWindow)) videoLive.dvrWindow = body.dvrWindow
- if (body.schedules !== undefined) {
- await VideoLiveScheduleModel.deleteAllOfLiveId(videoLive.id, t)
- videoLive.LiveSchedules = []
+ if (body.schedules !== undefined) {
+ await VideoLiveScheduleModel.deleteAllOfLiveId(videoLive.id, t)
+ videoLive.LiveSchedules = []
- if (isArray(body.schedules)) {
- videoLive.LiveSchedules = await VideoLiveScheduleModel.addToLiveId(videoLive.id, body.schedules.map(s => s.startAt), t)
+ if (isArray(body.schedules)) {
+ videoLive.LiveSchedules = await VideoLiveScheduleModel.addToLiveId(videoLive.id, body.schedules.map(s => s.startAt), t)
+ }
}
- }
- video.VideoLive = await videoLive.save({ transaction: t })
+ video.VideoLive = await videoLive.save({ transaction: t })
- await VideoChannelActivityModel.addVideoActivity({
- action: VideoChannelActivityAction.UPDATE,
- user: res.locals.oauth.token.User,
- channel: video.VideoChannel,
- video,
- transaction: t
+ await VideoChannelActivityModel.addVideoActivity({
+ action: VideoChannelActivityAction.UPDATE,
+ user: res.locals.oauth.token.User,
+ channel: video.VideoChannel,
+ video,
+ transaction: t
+ })
})
})
- })
- scheduleVideoFederation({ video })
+ scheduleVideoFederation({ video })
- return res.status(HttpStatusCode.NO_CONTENT_204).end()
+ return res.status(HttpStatusCode.NO_CONTENT_204).end()
+ })
}
async function updateReplaySettings (videoLive: MVideoLive, body: LiveVideoUpdate, t: Transaction) {
@@ -198,60 +200,61 @@ async function updateReplaySettings (videoLive: MVideoLive, body: LiveVideoUpdat
async function addLiveVideo (req: express.Request, res: express.Response) {
const videoInfo: LiveVideoCreate = req.body
- const thumbnailfile = getVideoThumbnailFile(req.files)
-
- const localVideoCreator = new LocalVideoCreator({
- channel: res.locals.videoChannel,
- chapters: undefined,
- fallbackChapters: {
- fromDescription: false,
- finalFallback: undefined
- },
- liveAttributes: pick(videoInfo, [
- 'saveReplay',
- 'permanentLive',
- 'latencyMode',
- 'dvrWindow',
- 'replaySettings',
- 'schedules'
- ]),
- videoAttributeResultHook: 'filter:api.video.live.video-attribute.result',
- lTags,
- videoAttributes: {
- ...videoInfo,
-
- duration: 0,
- state: VideoState.WAITING_FOR_LIVE,
- isLive: true,
- inputFilename: null
- },
- videoFile: undefined,
- user: res.locals.oauth.token.User,
-
- thumbnail: thumbnailfile
- ? {
- path: thumbnailfile.path,
- automaticallyGenerated: false,
- keepOriginal: false
- }
- : {
- path: ASSETS_PATH.DEFAULT_LIVE_BACKGROUND,
- automaticallyGenerated: true,
- keepOriginal: true
- }
- })
+ await logger.inContext(async () => {
+ const thumbnailfile = getVideoThumbnailFile(req.files)
+
+ const localVideoCreator = new LocalVideoCreator({
+ channel: res.locals.videoChannel,
+ chapters: undefined,
+ fallbackChapters: {
+ fromDescription: false,
+ finalFallback: undefined
+ },
+ liveAttributes: pick(videoInfo, [
+ 'saveReplay',
+ 'permanentLive',
+ 'latencyMode',
+ 'dvrWindow',
+ 'replaySettings',
+ 'schedules'
+ ]),
+ videoAttributeResultHook: 'filter:api.video.live.video-attribute.result',
+ videoAttributes: {
+ ...videoInfo,
+
+ duration: 0,
+ state: VideoState.WAITING_FOR_LIVE,
+ isLive: true,
+ inputFilename: null
+ },
+ videoFile: undefined,
+ user: res.locals.oauth.token.User,
+
+ thumbnail: thumbnailfile
+ ? {
+ path: thumbnailfile.path,
+ automaticallyGenerated: false,
+ keepOriginal: false
+ }
+ : {
+ path: ASSETS_PATH.DEFAULT_LIVE_BACKGROUND,
+ automaticallyGenerated: true,
+ keepOriginal: true
+ }
+ })
- const { video } = await localVideoCreator.create()
+ const { video } = await localVideoCreator.create()
- logger.info('Video live %s with uuid %s created.', videoInfo.name, video.uuid, lTags())
+ logger.info('Video live %s with uuid %s created.', videoInfo.name, video.uuid)
- Hooks.runAction('action:api.live-video.created', { video, req, res })
+ Hooks.runAction('action:api.live-video.created', { video, req, res })
- return res.json({
- video: {
- id: video.id,
- shortUUID: uuidToShort(video.uuid),
- uuid: video.uuid
- }
+ return res.json({
+ video: {
+ id: video.id,
+ shortUUID: uuidToShort(video.uuid),
+ uuid: video.uuid
+ }
+ })
})
}
diff --git a/server/core/controllers/api/videos/ownership.ts b/server/core/controllers/api/videos/ownership.ts
index 336e497e43..3d540d97b5 100644
--- a/server/core/controllers/api/videos/ownership.ts
+++ b/server/core/controllers/api/videos/ownership.ts
@@ -3,7 +3,7 @@ import { canVideoBeFederated, scheduleVideoFederation } from '@server/lib/activi
import { VideoChannelActivityModel } from '@server/models/video/video-channel-activity.js'
import { MVideoWithRights } from '@server/types/models/index.js'
import express from 'express'
-import { logger } from '../../../helpers/logger.js'
+import { createLogger } from '../../../helpers/logger.js'
import { getFormattedObjects } from '../../../helpers/utils.js'
import { sequelizeTypescript } from '../../../initializers/database.js'
import { changeVideoChannelShare } from '../../../lib/activitypub/share.js'
@@ -25,6 +25,8 @@ import { ChangeOwnershipModel } from '../../../models/video/change-ownership.js'
import { VideoChannelModel } from '../../../models/video/video-channel.js'
import { VideoModel } from '../../../models/video/video.js'
+const logger = createLogger()
+
const ownershipVideoRouter = express.Router()
ownershipVideoRouter.post(
diff --git a/server/core/controllers/api/videos/passwords.ts b/server/core/controllers/api/videos/passwords.ts
index e4102f5fa8..4c9e4c8bd7 100644
--- a/server/core/controllers/api/videos/passwords.ts
+++ b/server/core/controllers/api/videos/passwords.ts
@@ -1,5 +1,5 @@
import { HttpStatusCode, VideoChannelActivityAction } from '@peertube/peertube-models'
-import { logger, loggerTagsFactory } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { sequelizeTypescript } from '@server/initializers/database.js'
import { VideoChannelActivityModel } from '@server/models/video/video-channel-activity.js'
import { VideoPasswordModel } from '@server/models/video/video-password.js'
@@ -22,7 +22,8 @@ import {
videoPasswordsSortValidator
} from '../../../middlewares/validators/index.js'
-const lTags = loggerTagsFactory('api', 'video')
+const logger = createLogger('api', 'video')
+
const videoPasswordRouter = express.Router()
videoPasswordRouter.get(
@@ -73,66 +74,71 @@ async function listVideoPasswords (req: express.Request, res: express.Response)
return res.json(getFormattedObjects(resultList.data, resultList.total))
}
-async function updateVideoPasswordList (req: express.Request, res: express.Response) {
+function updateVideoPasswordList (req: express.Request, res: express.Response) {
const video = res.locals.videoWithRights
const videoId = video.id
- const passwordArray = req.body.passwords as string[]
+ return logger.withContext([ video.uuid ], async () => {
+ const passwordArray = req.body.passwords as string[]
- await VideoPasswordModel.sequelize.transaction(async (t: Transaction) => {
- await VideoPasswordModel.deleteAllPasswords(videoId, t)
- await VideoPasswordModel.addPasswords(passwordArray, videoId, t)
+ await VideoPasswordModel.sequelize.transaction(async (t: Transaction) => {
+ await VideoPasswordModel.deleteAllPasswords(videoId, t)
+ await VideoPasswordModel.addPasswords(passwordArray, videoId, t)
- await VideoChannelActivityModel.addVideoActivity({
- action: VideoChannelActivityAction.UPDATE_PASSWORDS,
- user: res.locals.oauth.token.User,
- channel: video.VideoChannel,
- video,
- transaction: t
+ await VideoChannelActivityModel.addVideoActivity({
+ action: VideoChannelActivityAction.UPDATE_PASSWORDS,
+ user: res.locals.oauth.token.User,
+ channel: video.VideoChannel,
+ video,
+ transaction: t
+ })
})
- })
- logger.info(`Video passwords for video with name ${video.name} and uuid ${video.uuid} have been updated`, lTags(video.uuid))
+ logger.info(`Video passwords for video with name ${video.name} and uuid ${video.uuid} have been updated`)
- return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
+ return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
+ })
}
-async function addVideoPassword (req: express.Request, res: express.Response) {
+function addVideoPassword (req: express.Request, res: express.Response) {
const video = res.locals.videoWithRights
const videoId = video.id
- const newPassword = req.body.password as string
+ return logger.withContext([ video.uuid ], async () => {
+ const newPassword = req.body.password as string
- await sequelizeTypescript.transaction(t => {
- return VideoPasswordModel.addPassword(newPassword, videoId, t)
- })
+ await sequelizeTypescript.transaction(t => {
+ return VideoPasswordModel.addPassword(newPassword, videoId, t)
+ })
- logger.info(`Video password for video with name ${video.name} and uuid ${video.uuid} have been added`, lTags(video.uuid))
+ logger.info(`Video password for video with name ${video.name} and uuid ${video.uuid} have been added`)
- return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
+ return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
+ })
}
-async function removeVideoPassword (req: express.Request, res: express.Response) {
+function removeVideoPassword (req: express.Request, res: express.Response) {
const videoInstance = res.locals.videoWithRights
const password = res.locals.videoPassword
- await VideoPasswordModel.deletePassword(password.id)
+ return logger.withContext([ videoInstance.uuid ], async () => {
+ await VideoPasswordModel.deletePassword(password.id)
- await VideoChannelActivityModel.addVideoActivity({
- action: VideoChannelActivityAction.UPDATE_PASSWORDS,
- user: res.locals.oauth.token.User,
- channel: videoInstance.VideoChannel,
- video: videoInstance,
- transaction: null
- })
+ await VideoChannelActivityModel.addVideoActivity({
+ action: VideoChannelActivityAction.UPDATE_PASSWORDS,
+ user: res.locals.oauth.token.User,
+ channel: videoInstance.VideoChannel,
+ video: videoInstance,
+ transaction: null
+ })
- logger.info(
- 'Password with id %d of video named %s and uuid %s has been deleted.',
- password.id,
- videoInstance.name,
- videoInstance.uuid,
- lTags(videoInstance.uuid)
- )
+ logger.info(
+ 'Password with id %d of video named %s and uuid %s has been deleted.',
+ password.id,
+ videoInstance.name,
+ videoInstance.uuid
+ )
- return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
+ return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
+ })
}
diff --git a/server/core/controllers/api/videos/rate.ts b/server/core/controllers/api/videos/rate.ts
index 992c7ef496..723d931cac 100644
--- a/server/core/controllers/api/videos/rate.ts
+++ b/server/core/controllers/api/videos/rate.ts
@@ -1,9 +1,11 @@
import express from 'express'
import { HttpStatusCode, UserVideoRateUpdate } from '@peertube/peertube-models'
-import { logger } from '../../../helpers/logger.js'
+import { createLogger } from '../../../helpers/logger.js'
import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate, videoUpdateRateValidator } from '../../../middlewares/index.js'
import { userRateVideo } from '@server/lib/rate.js'
+const logger = createLogger()
+
const rateVideoRouter = express.Router()
rateVideoRouter.put(
diff --git a/server/core/controllers/api/videos/source.ts b/server/core/controllers/api/videos/source.ts
index a2105d54fa..ca21e571bb 100644
--- a/server/core/controllers/api/videos/source.ts
+++ b/server/core/controllers/api/videos/source.ts
@@ -18,7 +18,7 @@ import { VideoModel } from '@server/models/video/video.js'
import { MStreamingPlaylistFiles, MVideo, MVideoFile, MVideoFileInfoHash, MVideoFull } from '@server/types/models/index.js'
import express from 'express'
import { move } from 'fs-extra/esm'
-import { logger, loggerTagsFactory } from '../../../helpers/logger.js'
+import { createLogger } from '../../../helpers/logger.js'
import {
asyncMiddleware,
authenticate,
@@ -27,7 +27,7 @@ import {
videoSourceGetLatestValidator
} from '../../../middlewares/index.js'
-const lTags = loggerTagsFactory('api', 'video')
+const logger = createLogger('api', 'video')
const videoSourceRouter = express.Router()
@@ -90,7 +90,11 @@ function getVideoLatestSource (req: express.Request, res: express.Response) {
return res.json(res.locals.videoSource.toFormattedJSON())
}
-async function replaceVideoSourceResumable (req: express.Request, res: express.Response) {
+function replaceVideoSourceResumable (req: express.Request, res: express.Response) {
+ return logger.withContext([ res.locals.videoFull.uuid ], () => doReplaceVideoSourceResumable(req, res))
+}
+
+async function doReplaceVideoSourceResumable (req: express.Request, res: express.Response) {
const videoPhysicalFile = res.locals.updateVideoFileResumable
const user = res.locals.oauth.token.User
@@ -174,7 +178,7 @@ async function replaceVideoSourceResumable (req: express.Request, res: express.R
await addVideoJobsAfterUpload(video, videoFile.withVideoOrPlaylist(video))
- logger.info('Replaced video file of video %s with uuid %s.', video.name, video.uuid, lTags(video.uuid))
+ logger.info('Replaced video file of video %s with uuid %s.', video.name, video.uuid)
Hooks.runAction('action:api.video.file-updated', { video, req, res })
diff --git a/server/core/controllers/api/videos/transcoding.ts b/server/core/controllers/api/videos/transcoding.ts
index f582f6002a..a1a1f564d4 100644
--- a/server/core/controllers/api/videos/transcoding.ts
+++ b/server/core/controllers/api/videos/transcoding.ts
@@ -1,5 +1,5 @@
import { HttpStatusCode, UserRight, VideoState, VideoTranscodingCreate } from '@peertube/peertube-models'
-import { logger, loggerTagsFactory } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { CONFIG } from '@server/initializers/config.js'
import { Hooks } from '@server/lib/plugins/hooks.js'
import { createTranscodingJobs } from '@server/lib/transcoding/create-transcoding-job.js'
@@ -8,7 +8,8 @@ import { VideoJobInfoModel } from '@server/models/video/video-job-info.js'
import express from 'express'
import { asyncMiddleware, authenticate, createTranscodingValidator, ensureUserHasRight } from '../../../middlewares/index.js'
-const lTags = loggerTagsFactory('api', 'video')
+const logger = createLogger('api', 'video')
+
const transcodingRouter = express.Router()
transcodingRouter.post(
@@ -27,49 +28,50 @@ export {
// ---------------------------------------------------------------------------
-async function createTranscoding (req: express.Request, res: express.Response) {
+function createTranscoding (req: express.Request, res: express.Response) {
const video = res.locals.videoFull
- logger.info('Creating %s transcoding job for %s.', req.body.transcodingType, video.url, lTags())
- const body: VideoTranscodingCreate = req.body
+ return logger.withContext([ video.uuid ], async () => {
+ logger.info('Creating %s transcoding job for %s.', req.body.transcodingType, video.url)
- await VideoJobInfoModel.abortAllTasks(video.uuid, 'pendingTranscode')
+ const body: VideoTranscodingCreate = req.body
- const maxResolution = video.getMaxResolution()
- const hasAudio = video.hasAudio()
+ await VideoJobInfoModel.abortAllTasks(video.uuid, 'pendingTranscode')
- const resolutions = await Hooks.wrapObject(
- computeResolutionsToTranscode({
- input: maxResolution,
- type: 'vod',
- includeInput: true,
- strictLower: false,
- hasAudio,
- forceAudioResolution: body.transcodingType === 'web-video' && CONFIG.TRANSCODING.ALWAYS_TRANSCODE_PODCAST_OPTIMIZED_AUDIO
- }),
- 'filter:transcoding.manual.resolutions-to-transcode.result',
- body
- )
+ const maxResolution = video.getMaxResolution()
+ const hasAudio = video.hasAudio()
- logger.debug(`Resolutions built for manual transcoding ${body.transcodingType} for video ${video.uuid}`, {
- resolutions,
+ const resolutions = await Hooks.wrapObject(
+ computeResolutionsToTranscode({
+ input: maxResolution,
+ type: 'vod',
+ includeInput: true,
+ strictLower: false,
+ hasAudio,
+ forceAudioResolution: body.transcodingType === 'web-video' && CONFIG.TRANSCODING.ALWAYS_TRANSCODE_PODCAST_OPTIMIZED_AUDIO
+ }),
+ 'filter:transcoding.manual.resolutions-to-transcode.result',
+ body
+ )
- ...lTags(video.uuid)
- })
+ logger.debug(`Resolutions built for manual transcoding ${body.transcodingType} for video ${video.uuid}`, {
+ resolutions
+ })
- if (resolutions.length === 0) {
- return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
- }
+ if (resolutions.length === 0) {
+ return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
+ }
- video.state = VideoState.TO_TRANSCODE
- await video.save()
+ video.state = VideoState.TO_TRANSCODE
+ await video.save()
- await createTranscodingJobs({
- video,
- resolutions,
- transcodingType: body.transcodingType,
- user: null // Don't specify priority since these transcoding jobs are fired by the admin
- })
+ await createTranscodingJobs({
+ video,
+ resolutions,
+ transcodingType: body.transcodingType,
+ user: null // Don't specify priority since these transcoding jobs are fired by the admin
+ })
- return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
+ return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
+ })
}
diff --git a/server/core/controllers/api/videos/update.ts b/server/core/controllers/api/videos/update.ts
index 721e98b98b..1452d22553 100644
--- a/server/core/controllers/api/videos/update.ts
+++ b/server/core/controllers/api/videos/update.ts
@@ -6,10 +6,13 @@ import { openapiOperationDoc } from '@server/middlewares/doc.js'
import { MVideoThumbnails } from '@server/types/models/index.js'
import express from 'express'
import { createReqFiles } from '../../../helpers/express-utils.js'
+import { createLogger } from '../../../helpers/logger.js'
import { MIMETYPES } from '../../../initializers/constants.js'
import { Hooks } from '../../../lib/plugins/hooks.js'
import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate, videosUpdateValidator } from '../../../middlewares/index.js'
+const logger = createLogger('api', 'video')
+
const updateRouter = express.Router()
const reqVideoFileUpdate = createReqFiles([ 'thumbnailfile', 'previewfile' ], MIMETYPES.IMAGE.MIMETYPE_EXT)
@@ -36,17 +39,19 @@ async function updateVideo (req: express.Request, res: express.Response) {
const body: VideoUpdate = req.body
const user = res.locals.oauth.token.User
- const thumbnails = await buildVideoThumbnailsFromReq(videoFromReq, req)
+ await logger.inContext(async () => {
+ const thumbnails = await buildVideoThumbnailsFromReq(videoFromReq, req)
- const localVideoUpdater = new LocalVideoUpdater({ user, tags: [ 'api', 'video' ], video: videoFromReq })
+ const localVideoUpdater = new LocalVideoUpdater({ user, video: videoFromReq })
- const video = await localVideoUpdater.update({ ...body, thumbnails, channel: res.locals.videoChannel })
+ const video = await localVideoUpdater.update({ ...body, thumbnails, channel: res.locals.videoChannel })
- Hooks.runAction('action:api.video.updated', { video, body: req.body, req, res })
+ Hooks.runAction('action:api.video.updated', { video, body: req.body, req, res })
- return res.type('json')
- .status(HttpStatusCode.NO_CONTENT_204)
- .end()
+ return res.type('json')
+ .status(HttpStatusCode.NO_CONTENT_204)
+ .end()
+ })
}
async function buildVideoThumbnailsFromReq (video: MVideoThumbnails, req: express.Request) {
diff --git a/server/core/controllers/api/videos/upload.ts b/server/core/controllers/api/videos/upload.ts
index 8e434c1077..0ba21b4ce7 100644
--- a/server/core/controllers/api/videos/upload.ts
+++ b/server/core/controllers/api/videos/upload.ts
@@ -11,7 +11,7 @@ import { openapiOperationDoc } from '@server/middlewares/doc.js'
import express from 'express'
import { auditLoggerFactory, getAuditIdFromRes, VideoAuditView } from '../../../helpers/audit-logger.js'
import { createReqFiles } from '../../../helpers/express-utils.js'
-import { logger, loggerTagsFactory } from '../../../helpers/logger.js'
+import { createLogger } from '../../../helpers/logger.js'
import { CONSTRAINTS_FIELDS, MIMETYPES } from '../../../initializers/constants.js'
import { Hooks } from '../../../lib/plugins/hooks.js'
import {
@@ -23,8 +23,9 @@ import {
videosAddResumableValidator
} from '../../../middlewares/index.js'
-const lTags = loggerTagsFactory('api', 'video')
+const logger = createLogger('api', 'video')
const auditLogger = auditLoggerFactory('videos')
+
const uploadRouter = express.Router()
const reqVideoFileAdd = createReqFiles(
@@ -100,7 +101,7 @@ async function addVideoResumable (req: express.Request, res: express.Response) {
}
}
-async function addVideo (options: {
+function addVideo (options: {
req: express.Request
res: express.Response
videoPhysicalFile: express.VideoLegacyUploadFile
@@ -109,82 +110,84 @@ async function addVideo (options: {
}) {
const { req, res, videoPhysicalFile, videoInfo, files } = options
- const ffprobe = await ffprobePromise(videoPhysicalFile.path)
-
- const containerChapters = await getChaptersFromContainer({
- path: videoPhysicalFile.path,
- maxTitleLength: CONSTRAINTS_FIELDS.VIDEO_CHAPTERS.TITLE.max,
- ffprobe
- })
- logger.debug(`Got ${containerChapters.length} chapters from video "${videoInfo.name}" container`, { containerChapters, ...lTags() })
-
- const thumbnailfile = getVideoThumbnailFile(files)
-
- const localVideoCreator = new LocalVideoCreator({
- lTags,
+ return logger.inContext(async () => {
+ const ffprobe = await ffprobePromise(videoPhysicalFile.path)
- videoFile: {
+ const containerChapters = await getChaptersFromContainer({
path: videoPhysicalFile.path,
- probe: res.locals.ffprobe
- },
-
- user: res.locals.oauth.token.User,
- channel: res.locals.videoChannel,
-
- chapters: undefined,
- fallbackChapters: {
- fromDescription: true,
- finalFallback: containerChapters
- },
-
- videoAttributes: {
- ...videoInfo,
-
- duration: videoPhysicalFile.duration,
- inputFilename: videoPhysicalFile.originalname,
- state: buildNextVideoState(),
- isLive: false
- },
-
- liveAttributes: undefined,
-
- videoAttributeResultHook: 'filter:api.video.upload.video-attribute.result',
-
- thumbnail: thumbnailfile
- ? {
- path: thumbnailfile.path,
- automaticallyGenerated: false,
- keepOriginal: false
- }
- : undefined
- })
-
- try {
- const { video } = await localVideoCreator.create()
-
- auditLogger.create(getAuditIdFromRes(res), new VideoAuditView(video.toFormattedDetailsJSON()))
- logger.info('Video with name %s and uuid %s created.', videoInfo.name, video.uuid, lTags(video.uuid))
-
- Hooks.runAction('action:api.video.uploaded', { video, req, res })
+ maxTitleLength: CONSTRAINTS_FIELDS.VIDEO_CHAPTERS.TITLE.max,
+ ffprobe
+ })
+ logger.debug(`Got ${containerChapters.length} chapters from video "${videoInfo.name}" container`, { containerChapters })
+
+ const thumbnailfile = getVideoThumbnailFile(files)
+
+ const localVideoCreator = new LocalVideoCreator({
+ videoFile: {
+ path: videoPhysicalFile.path,
+ probe: res.locals.ffprobe
+ },
+
+ user: res.locals.oauth.token.User,
+ channel: res.locals.videoChannel,
+
+ chapters: undefined,
+ fallbackChapters: {
+ fromDescription: true,
+ finalFallback: containerChapters
+ },
+
+ videoAttributes: {
+ ...videoInfo,
+
+ duration: videoPhysicalFile.duration,
+ inputFilename: videoPhysicalFile.originalname,
+ state: buildNextVideoState(),
+ isLive: false
+ },
+
+ liveAttributes: undefined,
+
+ videoAttributeResultHook: 'filter:api.video.upload.video-attribute.result',
+
+ thumbnail: thumbnailfile
+ ? {
+ path: thumbnailfile.path,
+ automaticallyGenerated: false,
+ keepOriginal: false
+ }
+ : undefined
+ })
+
+ try {
+ const { video } = await localVideoCreator.create()
+
+ return logger.withContext([ video.uuid ], () => {
+ auditLogger.create(getAuditIdFromRes(res), new VideoAuditView(video.toFormattedDetailsJSON()))
+ logger.info('Video with name %s and uuid %s created.', videoInfo.name, video.uuid)
+
+ Hooks.runAction('action:api.video.uploaded', { video, req, res })
+
+ return {
+ video: {
+ id: video.id,
+ shortUUID: uuidToShort(video.uuid),
+ uuid: video.uuid
+ }
+ }
+ })
+ } catch (err) {
+ if (isPeerTubeError(err) && err.code === 'INVALID_IMAGE_FILE') {
+ logger.warn('Invalid thumbnail file provided for video upload.', { err })
- return {
- video: {
- id: video.id,
- shortUUID: uuidToShort(video.uuid),
- uuid: video.uuid
+ return res.fail({
+ message: req.t('The provided thumbnail file is invalid.')
+ })
}
- }
- } catch (err) {
- if (isPeerTubeError(err) && err.code === 'INVALID_IMAGE_FILE') {
- logger.warn('Invalid thumbnail file provided for video upload.', { err, ...lTags() })
- return res.fail({
- message: req.t('The provided thumbnail file is invalid.')
- })
+ throw err
}
-
- throw err
- }
+ })
}
async function deleteUploadResumableCache (req: express.Request, res: express.Response, next: express.NextFunction) {
diff --git a/server/core/controllers/api/watched-words.ts b/server/core/controllers/api/watched-words.ts
index ff78ee58fb..ab559ea675 100644
--- a/server/core/controllers/api/watched-words.ts
+++ b/server/core/controllers/api/watched-words.ts
@@ -1,7 +1,7 @@
import { HttpStatusCode, UserRight } from '@peertube/peertube-models'
import { Awaitable } from '@peertube/peertube-typescript-utils'
import { deleteInTransactionWithRetries } from '@server/helpers/database-utils.js'
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { sequelizeTypescript } from '@server/initializers/database.js'
import { createRebuildAutomaticTagsJob } from '@server/lib/automatic-tags/automatic-tags.js'
import { fetchAndValidateWatchedWordsSubscriptionActions } from '@server/lib/watched-words-subscriptions.js'
@@ -33,6 +33,8 @@ import {
watchedWordsSubscriptionsSortValidator
} from '../../middlewares/index.js'
+const logger = createLogger()
+
const watchedWordsRouter = express.Router()
watchedWordsRouter.use(apiRateLimiter)
diff --git a/server/core/controllers/client.ts b/server/core/controllers/client.ts
index 3b81fff99a..a7f83f20fd 100644
--- a/server/core/controllers/client.ts
+++ b/server/core/controllers/client.ts
@@ -2,7 +2,7 @@ import { buildFileLocale, getCompleteLocale, is18nLocale, LOCALE_FILES } from '@
import { HttpStatusCode } from '@peertube/peertube-models'
import { currentDir, root } from '@peertube/peertube-node-utils'
import { toCompleteUUID } from '@server/helpers/custom-validators/misc.js'
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { CONFIG } from '@server/initializers/config.js'
import { Hooks } from '@server/lib/plugins/hooks.js'
import { getServerActor } from '@server/models/application/application.js'
@@ -13,6 +13,8 @@ import { STATIC_MAX_AGE } from '../initializers/constants.js'
import { ClientHtml, sendHTML, serveIndexHTML } from '../lib/html/client-html.js'
import { asyncMiddleware, buildRateLimiter, embedCSP } from '../middlewares/index.js'
+const logger = createLogger()
+
const clientsRouter = express.Router()
const clientsRateLimiter = buildRateLimiter({
diff --git a/server/core/controllers/download.ts b/server/core/controllers/download.ts
index c34d137808..2a826ba174 100644
--- a/server/core/controllers/download.ts
+++ b/server/core/controllers/download.ts
@@ -2,7 +2,7 @@ import { forceNumber, maxBy } from '@peertube/peertube-core-utils'
import { FileStorage, HttpStatusCode, UserRight, VideoResolution, VideoStreamingPlaylistType } from '@peertube/peertube-models'
import { exists } from '@server/helpers/custom-validators/misc.js'
import { getAuthUser, parseRangeHeader, pipelineToResponse } from '@server/helpers/express-utils.js'
-import { logger, loggerTagsFactory } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { generateRequestStream } from '@server/helpers/requests.js'
import { ThrottleStream } from '@server/helpers/stream-throttle.js'
import { CONFIG } from '@server/initializers/config.js'
@@ -39,7 +39,7 @@ import {
videosGenerateDownloadValidator
} from '../middlewares/index.js'
-const lTags = loggerTagsFactory('download')
+const logger = createLogger('download')
const downloadRouter = express.Router()
@@ -149,168 +149,181 @@ async function downloadTorrent (req: express.Request, res: express.Response) {
// ---------------------------------------------------------------------------
-async function downloadWebVideoFile (req: express.Request, res: express.Response) {
+function downloadWebVideoFile (req: express.Request, res: express.Response) {
const video = res.locals.videoFull
- const videoFile = getVideoFileFromReq(req, video.VideoFiles)
- if (!videoFile) {
- return res.fail({
- status: HttpStatusCode.NOT_FOUND_404,
- message: 'Video file not found'
- })
- }
+ return logger.withContext([ video.uuid ], async () => {
+ const videoFile = getVideoFileFromReq(req, video.VideoFiles)
+ if (!videoFile) {
+ return res.fail({
+ status: HttpStatusCode.NOT_FOUND_404,
+ message: 'Video file not found'
+ })
+ }
- const allowParameters = {
- req,
- res,
- video,
- videoFile
- }
+ const allowParameters = {
+ req,
+ res,
+ video,
+ videoFile
+ }
- const allowedResult = await Hooks.wrapFun(
- isVideoDownloadAllowed,
- allowParameters,
- 'filter:api.download.video.allowed.result'
- )
+ const allowedResult = await Hooks.wrapFun(
+ isVideoDownloadAllowed,
+ allowParameters,
+ 'filter:api.download.video.allowed.result'
+ )
- if (!checkAllowResult(res, allowParameters, allowedResult)) return
+ if (!checkAllowResult(res, allowParameters, allowedResult)) return
- const downloadFilename = buildDownloadFilename({ video, resolution: videoFile.resolution, extname: videoFile.extname })
+ const downloadFilename = buildDownloadFilename({ video, resolution: videoFile.resolution, extname: videoFile.extname })
- VideoStatsManager.Instance.processLocalDownload({ video })
- .catch(err => logger.error(`Cannot process local download stats for video ${video.uuid}`, { err, ...lTags(video.uuid) }))
+ VideoStatsManager.Instance.processLocalDownload({ video })
+ .catch(err => logger.error(`Cannot process local download stats for video ${video.uuid}`, { err }))
- if (videoFile.storage === FileStorage.OBJECT_STORAGE) {
- return redirectVideoDownloadToObjectStorage({ res, video, file: videoFile, downloadFilename })
- }
+ if (videoFile.storage === FileStorage.OBJECT_STORAGE) {
+ return redirectVideoDownloadToObjectStorage({ res, video, file: videoFile, downloadFilename })
+ }
- await VideoPathManager.Instance.makeAvailableVideoFile(videoFile.withVideoOrPlaylist(video), path => {
- return downloadLocalFileWithOptionalThrottle({ req, res, path, downloadFilename })
+ await VideoPathManager.Instance.makeAvailableVideoFile(videoFile.withVideoOrPlaylist(video), path => {
+ return downloadLocalFileWithOptionalThrottle({ req, res, path, downloadFilename })
+ })
})
}
-async function downloadHLSVideoFile (req: express.Request, res: express.Response) {
+function downloadHLSVideoFile (req: express.Request, res: express.Response) {
const video = res.locals.videoFull
- const streamingPlaylist = getHLSPlaylist(video)
- if (!streamingPlaylist) return res.sendStatus(HttpStatusCode.NOT_FOUND_404)
- const videoFile = getVideoFileFromReq(req, streamingPlaylist.VideoFiles)
- if (!videoFile) {
- return res.fail({
- status: HttpStatusCode.NOT_FOUND_404,
- message: 'Video file not found'
- })
- }
+ return logger.withContext([ video.uuid ], async () => {
+ const streamingPlaylist = getHLSPlaylist(video)
+ if (!streamingPlaylist) return res.sendStatus(HttpStatusCode.NOT_FOUND_404)
- const allowParameters = {
- req,
- res,
- video,
- streamingPlaylist,
- videoFile
- }
-
- const allowedResult = await Hooks.wrapFun(
- isVideoDownloadAllowed,
- allowParameters,
- 'filter:api.download.video.allowed.result'
- )
+ const videoFile = getVideoFileFromReq(req, streamingPlaylist.VideoFiles)
+ if (!videoFile) {
+ return res.fail({
+ status: HttpStatusCode.NOT_FOUND_404,
+ message: 'Video file not found'
+ })
+ }
- if (!checkAllowResult(res, allowParameters, allowedResult)) return
-
- VideoStatsManager.Instance.processLocalDownload({ video })
- .catch(err => logger.error(`Cannot process local download stats for video ${video.uuid}`, { err, ...lTags(video.uuid) }))
-
- const downloadFilename = buildDownloadFilename({ video, streamingPlaylist, resolution: videoFile.resolution, extname: videoFile.extname })
+ const allowParameters = {
+ req,
+ res,
+ video,
+ streamingPlaylist,
+ videoFile
+ }
+
+ const allowedResult = await Hooks.wrapFun(
+ isVideoDownloadAllowed,
+ allowParameters,
+ 'filter:api.download.video.allowed.result'
+ )
+
+ if (!checkAllowResult(res, allowParameters, allowedResult)) return
+
+ VideoStatsManager.Instance.processLocalDownload({ video })
+ .catch(err => logger.error(`Cannot process local download stats for video ${video.uuid}`, { err }))
+
+ const downloadFilename = buildDownloadFilename({
+ video,
+ streamingPlaylist,
+ resolution: videoFile.resolution,
+ extname: videoFile.extname
+ })
- if (videoFile.storage === FileStorage.OBJECT_STORAGE) {
- return redirectVideoDownloadToObjectStorage({ res, video, streamingPlaylist, file: videoFile, downloadFilename })
- }
+ if (videoFile.storage === FileStorage.OBJECT_STORAGE) {
+ return redirectVideoDownloadToObjectStorage({ res, video, streamingPlaylist, file: videoFile, downloadFilename })
+ }
- await VideoPathManager.Instance.makeAvailableVideoFile(videoFile.withVideoOrPlaylist(streamingPlaylist), path => {
- return downloadLocalFileWithOptionalThrottle({ req, res, path, downloadFilename })
+ await VideoPathManager.Instance.makeAvailableVideoFile(videoFile.withVideoOrPlaylist(streamingPlaylist), path => {
+ return downloadLocalFileWithOptionalThrottle({ req, res, path, downloadFilename })
+ })
})
}
// ---------------------------------------------------------------------------
-async function downloadGeneratedVideoFile (req: express.Request, res: express.Response) {
+function downloadGeneratedVideoFile (req: express.Request, res: express.Response) {
const video = res.locals.videoFull
- const filesToSelect = req.query.videoFileIds
-
- const videoFiles = video.getAllFiles()
- .filter(f => filesToSelect.includes(f.id))
- if (videoFiles.length === 0) {
- return res.fail({
- status: HttpStatusCode.NOT_FOUND_404,
- message: `No files found (${filesToSelect.join(', ')}) to download video ${video.url}`
- })
- }
+ return logger.withContext([ video.uuid ], async () => {
+ const filesToSelect = req.query.videoFileIds
- if (videoFiles.filter(f => f.hasVideo()).length > 1 || videoFiles.filter(f => f.hasAudio()).length > 1) {
- return res.fail({
- status: HttpStatusCode.BAD_REQUEST_400,
- // In theory we could, but ffmpeg-fluent doesn't support multiple input streams so prefer to reject this specific use case
- message: `Cannot generate a container with multiple video/audio files. PeerTube supports a maximum of 1 audio and 1 video file`
- })
- }
-
- const allowParameters = {
- req,
- res,
- video,
- videoFiles
- }
+ const videoFiles = video.getAllFiles()
+ .filter(f => filesToSelect.includes(f.id))
- const allowedResult = await Hooks.wrapFun(
- isGeneratedVideoDownloadAllowed,
- allowParameters,
- 'filter:api.download.generated-video.allowed.result'
- )
+ if (videoFiles.length === 0) {
+ return res.fail({
+ status: HttpStatusCode.NOT_FOUND_404,
+ message: `No files found (${filesToSelect.join(', ')}) to download video ${video.url}`
+ })
+ }
- if (!checkAllowResult(res, allowParameters, allowedResult)) return
+ if (videoFiles.filter(f => f.hasVideo()).length > 1 || videoFiles.filter(f => f.hasAudio()).length > 1) {
+ return res.fail({
+ status: HttpStatusCode.BAD_REQUEST_400,
+ // In theory we could, but ffmpeg-fluent doesn't support multiple input streams so prefer to reject this specific use case
+ message: `Cannot generate a container with multiple video/audio files. PeerTube supports a maximum of 1 audio and 1 video file`
+ })
+ }
- if (VideoDownload.totalDownloads >= CONFIG.DOWNLOAD_GENERATE_VIDEO.MAX_PARALLEL_DOWNLOADS) {
- return res.fail({
- status: HttpStatusCode.TOO_MANY_REQUESTS_429,
- message: req.t(`Too many parallel downloads on this server. Please try again later.`)
- })
- }
-
- const maxResolutionFile = maxBy(videoFiles, 'resolution')
-
- // Prefer m4a extension for the user if this is a mp4 audio file only
- const extname = maxResolutionFile.resolution === VideoResolution.H_NOVIDEO && maxResolutionFile.extname === '.mp4'
- ? '.m4a'
- : maxResolutionFile.extname
-
- // If there is the extension, we want to simulate a "raw file" and so not send the content disposition header
- const urlPath = new URL(req.originalUrl, WEBSERVER.URL).pathname
- if (!urlPath.endsWith('.mp4') && !urlPath.endsWith('.m4a')) {
- const downloadFilename = buildDownloadFilename({ video, extname })
- res.setHeader('Content-disposition', createContentDisposition(downloadFilename))
- }
-
- res.type(extname)
-
- VideoStatsManager.Instance.processLocalDownload({ video })
- .catch(err => logger.error(`Cannot process local download stats for video ${video.uuid}`, { err, ...lTags(video.uuid) }))
-
- try {
- await new VideoDownload({ video, videoFiles }).muxToMergeVideoFiles(res, {
- totalBytesPerSecond: CONFIG.DOWNLOAD.MAX_TOTAL_BYTES_PER_SECOND,
- bytesPerIpPerSecond: CONFIG.DOWNLOAD.MAX_BYTES_PER_IP_PER_SECOND,
- ip: req.ip
- })
- } catch (err) {
- // muxToMergeVideoFiles has already logged the error
- res.fail({
- status: HttpStatusCode.SERVICE_UNAVAILABLE_503,
- title: req.t('Cannot process video download at the moment. Please try again later.'),
- message: err.message
- })
- }
+ const allowParameters = {
+ req,
+ res,
+ video,
+ videoFiles
+ }
+
+ const allowedResult = await Hooks.wrapFun(
+ isGeneratedVideoDownloadAllowed,
+ allowParameters,
+ 'filter:api.download.generated-video.allowed.result'
+ )
+
+ if (!checkAllowResult(res, allowParameters, allowedResult)) return
+
+ if (VideoDownload.totalDownloads >= CONFIG.DOWNLOAD_GENERATE_VIDEO.MAX_PARALLEL_DOWNLOADS) {
+ return res.fail({
+ status: HttpStatusCode.TOO_MANY_REQUESTS_429,
+ message: req.t(`Too many parallel downloads on this server. Please try again later.`)
+ })
+ }
+
+ const maxResolutionFile = maxBy(videoFiles, 'resolution')
+
+ // Prefer m4a extension for the user if this is a mp4 audio file only
+ const extname = maxResolutionFile.resolution === VideoResolution.H_NOVIDEO && maxResolutionFile.extname === '.mp4'
+ ? '.m4a'
+ : maxResolutionFile.extname
+
+ // If there is the extension, we want to simulate a "raw file" and so not send the content disposition header
+ const urlPath = new URL(req.originalUrl, WEBSERVER.URL).pathname
+ if (!urlPath.endsWith('.mp4') && !urlPath.endsWith('.m4a')) {
+ const downloadFilename = buildDownloadFilename({ video, extname })
+ res.setHeader('Content-disposition', createContentDisposition(downloadFilename))
+ }
+
+ res.type(extname)
+
+ VideoStatsManager.Instance.processLocalDownload({ video })
+ .catch(err => logger.error(`Cannot process local download stats for video ${video.uuid}`, { err }))
+
+ try {
+ await new VideoDownload({ video, videoFiles }).muxToMergeVideoFiles(res, {
+ totalBytesPerSecond: CONFIG.DOWNLOAD.MAX_TOTAL_BYTES_PER_SECOND,
+ bytesPerIpPerSecond: CONFIG.DOWNLOAD.MAX_BYTES_PER_IP_PER_SECOND,
+ ip: req.ip
+ })
+ } catch (err) {
+ // muxToMergeVideoFiles has already logged the error
+ res.fail({
+ status: HttpStatusCode.SERVICE_UNAVAILABLE_503,
+ title: req.t('Cannot process video download at the moment. Please try again later.'),
+ message: err.message
+ })
+ }
+ })
}
// ---------------------------------------------------------------------------
@@ -430,7 +443,7 @@ async function commonDownloadAllowed (object: {
function checkAllowResult (res: express.Response, allowParameters: any, result?: AllowedResult) {
if (result?.allowed !== true) {
- logger.info('Download is not allowed.', { result, allowParameters, ...lTags() })
+ logger.info('Download is not allowed.', { result, allowParameters })
res.fail({
status: HttpStatusCode.FORBIDDEN_403,
@@ -496,7 +509,7 @@ async function downloadLocalFileWithOptionalThrottle (options: {
if ((err as any).code === 'ENOENT') return res.sendStatus(HttpStatusCode.NOT_FOUND_404)
- logger.error(`Cannot read local file ${path} for download`, { err, ...lTags() })
+ logger.error(`Cannot read local file ${path} for download`, { err })
return res.fail({
status: HttpStatusCode.INTERNAL_SERVER_ERROR_500,
@@ -524,7 +537,7 @@ async function redirectVideoDownloadToObjectStorage (options: {
? await generateHLSFilePresignedUrl({ streamingPlaylist, file, downloadFilename })
: await generateWebVideoPresignedUrl({ file, downloadFilename })
- logger.debug('Generating pre-signed URL %s for video %s', url, video.uuid, lTags())
+ logger.debug('Generating pre-signed URL %s for video %s', url, video.uuid)
return res.redirect(url)
}
@@ -538,7 +551,7 @@ async function redirectUserExportToObjectStorage (options: {
const url = await generateUserExportPresignedUrl({ userExport, downloadFilename })
- logger.debug('Generating pre-signed URL %s for user export %s', url, userExport.filename, lTags())
+ logger.debug('Generating pre-signed URL %s for user export %s', url, userExport.filename)
return res.redirect(url)
}
@@ -552,7 +565,7 @@ async function redirectOriginalFileToObjectStorage (options: {
const url = await generateOriginalFilePresignedUrl({ videoSource, downloadFilename })
- logger.debug('Generating pre-signed URL %s for original video file %s', url, videoSource.keptOriginalFilename, lTags())
+ logger.debug('Generating pre-signed URL %s for original video file %s', url, videoSource.keptOriginalFilename)
return res.redirect(url)
}
diff --git a/server/core/controllers/feeds/video-podcast-feeds.ts b/server/core/controllers/feeds/video-podcast-feeds.ts
index 086362e6ab..5b9d90e368 100644
--- a/server/core/controllers/feeds/video-podcast-feeds.ts
+++ b/server/core/controllers/feeds/video-podcast-feeds.ts
@@ -4,7 +4,7 @@ import { buildDownloadFilesUrl, getResolutionLabel, sortObjectComparator } from
import { ActorImageType, FeedEnclosurePreference, VideoFile, VideoInclude, VideoResolution, VideoState } from '@peertube/peertube-models'
import { buildUUIDv5FromURL } from '@peertube/peertube-node-utils'
import { buildNSFWFilters } from '@server/helpers/express-utils.js'
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { CONFIG } from '@server/initializers/config.js'
import { InternalEventEmitter } from '@server/lib/internal-event-emitter.js'
import { Hooks } from '@server/lib/plugins/hooks.js'
@@ -32,6 +32,8 @@ import {
initFeed
} from './shared/index.js'
+const logger = createLogger()
+
const videoPodcastFeedsRouter = express.Router()
// ---------------------------------------------------------------------------
diff --git a/server/core/controllers/plugins.ts b/server/core/controllers/plugins.ts
index 1bcecce0ef..aef58ca417 100644
--- a/server/core/controllers/plugins.ts
+++ b/server/core/controllers/plugins.ts
@@ -3,7 +3,7 @@ import { join } from 'path'
import { getCompleteLocale, is18nLocale } from '@peertube/peertube-core-utils'
import { HttpStatusCode, PluginType } from '@peertube/peertube-models'
import { isProdInstance } from '@peertube/peertube-node-utils'
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { CONFIG } from '@server/initializers/config.js'
import { optionalAuthenticate } from '@server/middlewares/auth.js'
import { buildRateLimiter } from '@server/middlewares/index.js'
@@ -12,6 +12,8 @@ import { PluginManager, RegisteredPlugin } from '../lib/plugins/plugin-manager.j
import { getExternalAuthValidator, getPluginValidator, pluginStaticDirectoryValidator } from '../middlewares/validators/plugins.js'
import { serveThemeCSSValidator } from '../middlewares/validators/themes.js'
+const logger = createLogger()
+
const sendFileOptions = {
maxAge: '30 days',
immutable: isProdInstance()
diff --git a/server/core/controllers/services.ts b/server/core/controllers/services.ts
index fe8618d906..2494bf78f6 100644
--- a/server/core/controllers/services.ts
+++ b/server/core/controllers/services.ts
@@ -1,6 +1,6 @@
import { escapeHTML, forceNumber } from '@peertube/peertube-core-utils'
import { HttpStatusCode } from '@peertube/peertube-models'
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { getOrCreateAPActor } from '@server/lib/activitypub/actors/get.js'
import { loadActorUrlOrGetFromWebfinger } from '@server/lib/activitypub/actors/webfinger.js'
import { AccountModel } from '@server/models/account/account.js'
@@ -13,6 +13,8 @@ import { EMBED_SIZE, WEBSERVER } from '../initializers/constants.js'
import { apiRateLimiter, asyncMiddleware, oembedValidator } from '../middlewares/index.js'
import { accountHandleGetValidatorFactory } from '../middlewares/validators/index.js'
+const logger = createLogger()
+
const servicesRouter = express.Router()
servicesRouter.use(
diff --git a/server/core/controllers/sitemap.ts b/server/core/controllers/sitemap.ts
index 2161e1fb0a..706433b869 100644
--- a/server/core/controllers/sitemap.ts
+++ b/server/core/controllers/sitemap.ts
@@ -1,5 +1,5 @@
import { VideoFileStream, VideoInclude } from '@peertube/peertube-models'
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { ServerConfigManager } from '@server/lib/server-config-manager.js'
import { getServerActor } from '@server/models/application/application.js'
import express from 'express'
@@ -12,6 +12,8 @@ import { AccountModel } from '../models/account/account.js'
import { VideoChannelModel } from '../models/video/video-channel.js'
import { VideoModel } from '../models/video/video.js'
+const logger = createLogger()
+
const sitemapRouter = express.Router()
sitemapRouter.use('/sitemap.xml', apiRateLimiter, cacheRoute(ROUTE_CACHE_LIFETIME.SITEMAP), asyncMiddleware(getSitemap))
diff --git a/server/core/controllers/tracker.ts b/server/core/controllers/tracker.ts
index 7b7c00bdb2..e528a2fbe1 100644
--- a/server/core/controllers/tracker.ts
+++ b/server/core/controllers/tracker.ts
@@ -4,11 +4,13 @@ import { createServer } from 'http'
import { LRUCache } from 'lru-cache'
import proxyAddr from 'proxy-addr'
import { WebSocketServer } from 'ws'
-import { logger } from '../helpers/logger.js'
+import { createLogger } from '../helpers/logger.js'
import { CONFIG } from '../initializers/config.js'
import { LRU_CACHE, TRACKER_RATE_LIMITS } from '../initializers/constants.js'
import { VideoInfohashModel } from '../models/video/video-infohash.js'
+const logger = createLogger()
+
export const trackerRouter = express.Router()
const blockedIPs = new LRUCache<string, boolean>({
diff --git a/server/core/helpers/activity-pub-utils.ts b/server/core/helpers/activity-pub-utils.ts
index c294ab7543..393213062d 100644
--- a/server/core/helpers/activity-pub-utils.ts
+++ b/server/core/helpers/activity-pub-utils.ts
@@ -2,11 +2,13 @@ import { arrayify } from '@peertube/peertube-core-utils'
import { ContextType } from '@peertube/peertube-models'
import { ACTIVITY_PUB, REMOTE_SCHEME } from '@server/initializers/constants.js'
import { isArray } from './custom-validators/misc.js'
-import { logger } from './logger.js'
+import { createLogger } from './logger.js'
import { buildDigest } from './peertube-crypto.js'
import type { signJsonLDObject } from './peertube-jsonld.js'
import { doJSONRequest } from './requests.js'
+const logger = createLogger()
+
export type ContextFilter = <T>(arg: T) => Promise<T>
export function buildGlobalHTTPHeaders (
diff --git a/server/core/helpers/custom-validators/activitypub/videos.ts b/server/core/helpers/custom-validators/activitypub/videos.ts
index 55b2270979..1d63f094e4 100644
--- a/server/core/helpers/custom-validators/activitypub/videos.ts
+++ b/server/core/helpers/custom-validators/activitypub/videos.ts
@@ -9,7 +9,7 @@ import {
VideoObject,
VideoState
} from '@peertube/peertube-models'
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { spdxToPeertubeLicence } from '@server/helpers/video.js'
import validator from 'validator'
import { CONSTRAINTS_FIELDS, MIMETYPES } from '../../../initializers/constants.js'
@@ -34,6 +34,8 @@ import {
} from './misc.js'
import { getDurationFromActivityStream } from '@server/lib/activitypub/activity.js'
+const logger = createLogger()
+
export function sanitizeAndCheckVideoTorrentUpdateActivity (activity: any) {
return isBaseActivityValid(activity, 'Update') &&
sanitizeAndCheckVideoTorrentObject(activity.object)
diff --git a/server/core/helpers/custom-validators/video-captions.ts b/server/core/helpers/custom-validators/video-captions.ts
index 723ef56e03..5cccf1c7fa 100644
--- a/server/core/helpers/custom-validators/video-captions.ts
+++ b/server/core/helpers/custom-validators/video-captions.ts
@@ -2,9 +2,11 @@ import { UploadFilesForCheck } from 'express'
import { readFile } from 'fs/promises'
import { getFileSize } from '@peertube/peertube-node-utils'
import { CONSTRAINTS_FIELDS, MIMETYPES, VIDEO_TEXT_LANGUAGES } from '../../initializers/constants.js'
-import { logger } from '../logger.js'
+import { createLogger } from '../logger.js'
import { exists, isFileValid } from './misc.js'
+const logger = createLogger()
+
export function isVideoCaptionLanguageValid (value: any) {
return exists(value) && VIDEO_TEXT_LANGUAGES[value] !== undefined
}
diff --git a/server/core/helpers/database-utils.ts b/server/core/helpers/database-utils.ts
index 90357813fe..c1fe44047c 100644
--- a/server/core/helpers/database-utils.ts
+++ b/server/core/helpers/database-utils.ts
@@ -2,7 +2,9 @@ import { wait } from '@peertube/peertube-core-utils'
import { sequelizeTypescript } from '@server/initializers/database.js'
import { Transaction } from 'sequelize'
import { Model } from 'sequelize-typescript'
-import { logger } from './logger.js'
+import { createLogger } from './logger.js'
+
+const logger = createLogger()
export type RetryTransactionWrapperOptions = {
// Also retry when the transaction failed because of a unique constraint violation
diff --git a/server/core/helpers/express-utils.ts b/server/core/helpers/express-utils.ts
index 6c02bf619a..5c96c7deed 100644
--- a/server/core/helpers/express-utils.ts
+++ b/server/core/helpers/express-utils.ts
@@ -9,10 +9,12 @@ import { CONFIG } from '../initializers/config.js'
import { REMOTE_SCHEME } from '../initializers/constants.js'
import { isArray } from './custom-validators/misc.js'
import { deleteFileAndCatch } from './fs.js'
-import { logger } from './logger.js'
+import { createLogger } from './logger.js'
import { generateRandomString } from './utils.js'
import { getExtFromMimetype } from './video.js'
+const logger = createLogger()
+
// ---------------------------------------------------------------------------
// Extract NSFW Filters options to list videos
// ---------------------------------------------------------------------------
diff --git a/server/core/helpers/ffmpeg/codecs.ts b/server/core/helpers/ffmpeg/codecs.ts
index 54f88b3cd8..6a103653be 100644
--- a/server/core/helpers/ffmpeg/codecs.ts
+++ b/server/core/helpers/ffmpeg/codecs.ts
@@ -1,8 +1,10 @@
import { FfprobeData } from 'fluent-ffmpeg'
import { getAudioStream, getVideoStream } from '@peertube/peertube-ffmpeg'
-import { logger } from '../logger.js'
+import { createLogger } from '../logger.js'
import { forceNumber } from '@peertube/peertube-core-utils'
+const logger = createLogger()
+
export async function getVideoStreamCodec (path: string, existingProbe?: FfprobeData) {
const videoStream = await getVideoStream(path, existingProbe)
if (!videoStream) return ''
diff --git a/server/core/helpers/ffmpeg/ffmpeg-options.ts b/server/core/helpers/ffmpeg/ffmpeg-options.ts
index ec1b91f869..9ca31e8894 100644
--- a/server/core/helpers/ffmpeg/ffmpeg-options.ts
+++ b/server/core/helpers/ffmpeg/ffmpeg-options.ts
@@ -1,9 +1,11 @@
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { CONFIG } from '@server/initializers/config.js'
import { FFMPEG_NICE } from '@server/initializers/constants.js'
import { FFmpegCommandWrapperOptions } from '@peertube/peertube-ffmpeg'
import { AvailableEncoders } from '@peertube/peertube-models'
+const logger = createLogger()
+
type CommandType = 'live' | 'vod' | 'thumbnail'
export function getFFmpegCommandWrapperOptions (type: CommandType, availableEncoders?: AvailableEncoders): FFmpegCommandWrapperOptions {
diff --git a/server/core/helpers/ffmpeg/framerate.ts b/server/core/helpers/ffmpeg/framerate.ts
index 9eb98501c6..37bc9eab93 100644
--- a/server/core/helpers/ffmpeg/framerate.ts
+++ b/server/core/helpers/ffmpeg/framerate.ts
@@ -1,6 +1,8 @@
import { VideoResolution } from '@peertube/peertube-models'
import { CONFIG } from '@server/initializers/config.js'
-import { logger } from '../logger.js'
+import { createLogger } from '../logger.js'
+
+const logger = createLogger()
export function computeOutputFPS (options: {
inputFPS: number
diff --git a/server/core/helpers/fs.ts b/server/core/helpers/fs.ts
index 349cfff0d8..9fa8d3f3ab 100644
--- a/server/core/helpers/fs.ts
+++ b/server/core/helpers/fs.ts
@@ -1,6 +1,8 @@
import { move, remove } from 'fs-extra/esm'
import { rename } from 'fs/promises'
-import { logger } from './logger.js'
+import { createLogger } from './logger.js'
+
+const logger = createLogger()
export async function tryAtomicMove (src: string, destination: string) {
try {
diff --git a/server/core/helpers/geo-ip.ts b/server/core/helpers/geo-ip.ts
index 4c7e08c6d2..eb405aa3e0 100644
--- a/server/core/helpers/geo-ip.ts
+++ b/server/core/helpers/geo-ip.ts
@@ -5,10 +5,10 @@ import maxmind, { CityResponse, CountryResponse, Reader } from 'maxmind'
import { join } from 'path'
import { REQUEST_TIMEOUTS } from '../initializers/constants.js'
import { isArray } from './custom-validators/misc.js'
-import { logger, loggerTagsFactory } from './logger.js'
+import { createLogger } from './logger.js'
import { doBufferRequest, isBinaryResponse } from './requests.js'
-const lTags = loggerTagsFactory('geo-ip')
+const logger = createLogger('geo-ip')
export class GeoIP {
private static instance: GeoIP
@@ -100,7 +100,7 @@ export class GeoIP {
}
private async updateDatabaseFile (url: string, destination: string) {
- logger.info('Updating GeoIP databases from %s.', url, lTags())
+ logger.info('Updating GeoIP databases from %s.', url)
try {
const gotResult = await doBufferRequest(url, {
@@ -115,9 +115,9 @@ export class GeoIP {
await writeFile(destination, gotResult.body)
- logger.info('GeoIP database updated %s.', destination, lTags())
+ logger.info('GeoIP database updated %s.', destination)
} catch (err) {
- logger.error('Cannot update GeoIP database from %s.', url, { err, ...lTags() })
+ logger.error('Cannot update GeoIP database from %s.', url, { err })
}
}
diff --git a/server/core/helpers/i18n.ts b/server/core/helpers/i18n.ts
index 33c31699c4..2759fe18c8 100644
--- a/server/core/helpers/i18n.ts
+++ b/server/core/helpers/i18n.ts
@@ -9,7 +9,9 @@ import { readdir } from 'fs/promises'
import i18next from 'i18next'
import ICU from 'i18next-icu'
import { join } from 'path'
-import { logger } from './logger.js'
+import { createLogger } from './logger.js'
+
+const logger = createLogger()
export async function initI18n () {
const locales = await readdir(SERVER_INTERNAL_LOCALES_BASE_PATH)
diff --git a/server/core/helpers/image-utils.ts b/server/core/helpers/image-utils.ts
index 756468c8ed..de257a2a17 100644
--- a/server/core/helpers/image-utils.ts
+++ b/server/core/helpers/image-utils.ts
@@ -4,7 +4,9 @@ import { copy, remove } from 'fs-extra/esm'
import { readFile, writeFile } from 'fs/promises'
import sanitizeHtml from 'sanitize-html'
import sharp, { type Metadata, type Sharp } from 'sharp'
-import { logger } from './logger.js'
+import { createLogger } from './logger.js'
+
+const logger = createLogger()
export function generateImageFilename (extension = '.jpg') {
return buildUUID() + extension
diff --git a/server/core/helpers/logger.ts b/server/core/helpers/logger.ts
index c5874ec887..3dc1fe4873 100644
--- a/server/core/helpers/logger.ts
+++ b/server/core/helpers/logger.ts
@@ -1,11 +1,11 @@
import { context, trace } from '@opentelemetry/api'
-import { omit } from '@peertube/peertube-core-utils'
import { isTestOrDevInstance } from '@peertube/peertube-node-utils'
+import { AsyncLocalStorage } from 'async_hooks'
import { stat } from 'fs/promises'
import { join } from 'path'
import { format as sqlFormat } from 'sql-formatter'
import { isatty } from 'tty'
-import { createLogger, format, transport, transports } from 'winston'
+import { createLogger as createWinstonLogger, format, transport, transports } from 'winston'
import { FileTransportOptions } from 'winston/lib/winston/transports/index.js'
import { isMainThread } from 'worker_threads'
import { CONFIG } from '../initializers/config.js'
@@ -13,11 +13,14 @@ import { LOG_FILENAME } from '../initializers/constants.js'
const label = CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT
-const consoleLoggerFormat = format.printf(info => {
- let additionalInfos = JSON.stringify(getAdditionalInfo(info), removeCyclicValues(), 2)
+const tracingEnabled = CONFIG.OPEN_TELEMETRY.TRACING.ENABLED
+
+// Symbols winston/logform use on the "info" object
+const LEVEL = Symbol.for('level')
+const SPLAT = Symbol.for('splat')
- if (additionalInfos === undefined || additionalInfos === '{}') additionalInfos = ''
- else additionalInfos = ' ' + additionalInfos
+const consoleLoggerFormat = format.printf(info => {
+ let additionalInfos = stringifyAdditionalInfo(info)
if (info.sql) {
if (CONFIG.LOG.PRETTIFY_SQL) {
@@ -43,16 +46,15 @@ export const labelFormatter: (suffix?: string) => ReturnType<typeof format.print
})
}
-export function buildLogger (options: {
+export function buildWinstonLogger (options: {
labelSuffix?: string
- handleExceptions?: boolean // default false
-}) {
- const { labelSuffix, handleExceptions = false } = options
+} = {}) {
+ const { labelSuffix } = options
const loggerTransports: transport[] = []
const formatters = [
format.timestamp({
- format: 'YYYY-MM-DD HH:mm:ss.SSS'
+ format: localTimestamp
})
]
@@ -72,7 +74,7 @@ export function buildLogger (options: {
filename: join(CONFIG.STORAGE.LOG_DIR, LOG_FILENAME),
handleExceptions: false,
format: format.combine(
- format.timestamp(),
+ format.timestamp({ format: isoTimestamp }),
jsonLoggerFormat
)
}
@@ -85,35 +87,26 @@ export function buildLogger (options: {
const fileTransport = new transports.File(fileLoggerOptions)
loggerTransports.push(fileTransport)
-
- if (isMainThread && handleExceptions) {
- process.on('uncaughtException', err => {
- logger.error('Uncaught exception.', { err })
- exitOnCrash()
- })
-
- process.on('unhandledRejection', reason => {
- logger.error('Unhandled rejection.', { reason })
- exitOnCrash()
- })
- }
}
loggerTransports.push(consoleTransport)
- return createLogger({
+ return createWinstonLogger({
level: process.env.LOGGER_LEVEL ?? CONFIG.LOG.LEVEL,
- defaultMeta: {
- get traceId () {
- return trace.getSpanContext(context.active())?.traceId
- },
- get spanId () {
- return trace.getSpanContext(context.active())?.spanId
- },
- get traceFlags () {
- return trace.getSpanContext(context.active())?.traceFlags
+ // Only used by direct winston consumers; the PeerTube logger injects trace context itself
+ defaultMeta: tracingEnabled
+ ? {
+ get traceId () {
+ return trace.getSpanContext(context.active())?.traceId
+ },
+ get spanId () {
+ return trace.getSpanContext(context.active())?.spanId
+ },
+ get traceFlags () {
+ return trace.getSpanContext(context.active())?.traceFlags
+ }
}
- },
+ : undefined,
format: format.combine(
labelFormatter(labelSuffix),
format.splat()
@@ -122,7 +115,150 @@ export function buildLogger (options: {
})
}
-export const logger = buildLogger({ handleExceptions: true })
+const rootWinstonLogger = buildWinstonLogger()
+
+// ---------------------------------------------------------------------------
+// Logger tags
+// ---------------------------------------------------------------------------
+
+export type LoggerTag = string | number
+
+const tagsStore = new AsyncLocalStorage<LoggerTag[]>()
+
+const noTags: LoggerTag[] = []
+
+export function inLoggerContext<T> (tags: LoggerTag[], fn: () => T): T {
+ // Always own the array: addLoggerContextTags() mutates the store in place
+ const merged = appendTags(getLoggerContextTags(), tags)
+
+ return tagsStore.run(merged === tags ? merged.slice() : merged, fn)
+}
+
+export function addLoggerContextTags (...tags: LoggerTag[]) {
+ return tagsStore.getStore().push(...tags)
+}
+
+function getLoggerContextTags (): LoggerTag[] {
+ return tagsStore.getStore() || noTags
+}
+
+function appendTags (existing: LoggerTag[], tags: LoggerTag[]): LoggerTag[] {
+ let merged = existing
+
+ for (const tag of tags) {
+ if (merged.includes(tag)) continue
+
+ // Copy the existing array on first tag
+ if (merged === existing) merged = existing.slice()
+ merged.push(tag)
+ }
+
+ return merged
+}
+
+// ---------------------------------------------------------------------------
+// PeerTube logger: a winston wrapper that automatically injects tags
+// ---------------------------------------------------------------------------
+
+export type LoggerLevel = 'error' | 'warn' | 'info' | 'debug' | 'verbose'
+
+export interface PeerTubeLogger {
+ error(message: string, ...args: any[]): void
+ warn(message: string, ...args: any[]): void
+ info(message: string, ...args: any[]): void
+ debug(message: string, ...args: any[]): void
+ verbose(message: string, ...args: any[]): void
+
+ isLevelEnabled(level: string): boolean
+
+ // `level` is a string and not a LoggerLevel to stay compatible with winston `log()`, that also accepts custom levels
+ log(level: string, ...args: any[]): void
+
+ // Build a new logger that appends these tags to every call
+ child(...tags: StaticLoggerTag[]): PeerTubeLogger
+
+ // Run `fn` with this logger tags added to the async context
+ inContext<T>(fn: () => T): T
+ withContext<T>(tags: LoggerTag[], fn: () => T): T
+}
+
+const rootLogger: PeerTubeLogger = buildPeerTubeLogger(rootWinstonLogger, [])
+
+// Registered here and not in buildWinstonLogger() so the handlers can't run before `rootLogger` is initialized
+if (isMainThread) {
+ process.on('uncaughtException', err => {
+ rootLogger.error('Uncaught exception.', { err })
+ exitOnCrash()
+ })
+
+ process.on('unhandledRejection', reason => {
+ rootLogger.error('Unhandled rejection.', { reason })
+ exitOnCrash()
+ })
+}
+
+// Cache winston level enabled state, because `winstonLogger.isLevelEnabled()` is "expensive" and called on every log line
+// Log level can't change at runtime
+const enabledLevels = new Map<string, boolean>()
+
+const isLevelEnabled = (level: string) => {
+ let enabled = enabledLevels.get(level)
+ if (enabled === undefined) {
+ enabled = rootLogger.isLevelEnabled(level)
+ enabledLevels.set(level, enabled)
+ }
+
+ return enabled
+}
+
+function buildPeerTubeLogger (winstonLogger: ReturnType<typeof buildWinstonLogger>, boundTags: LoggerTag[]): PeerTubeLogger {
+ const write = (level: string, args: any[]) => {
+ if (!isLevelEnabled(level)) return
+
+ const meta = extractMeta(args)
+
+ // Outermost scope first: async context, then tags bound to this logger, then the ones of this specific call.
+ // Both the async context and `boundTags` are already deduplicated, so this is a linear merge over a handful of tags
+ let tags = appendTags(getLoggerContextTags(), boundTags)
+ if (meta.tags) tags = appendTags(tags, meta.tags)
+
+ // Build the winston "info" object ourselves instead of going through `winstonLogger.log(level, message, ...splat)`:
+ // that variadic entry point would re-merge the meta we just built and scan the message for `%s` tokens on every call
+ const message = args[0]
+ const info: any = { ...meta, [LEVEL]: level, level, message }
+
+ if (meta.message) info.message = `${message} ${meta.message}`
+ if (tags.length !== 0) info.tags = tags
+
+ // Only set a splat when there are interpolation arguments, so `format.splat()` can bail out on the common case
+ if (args.length > 1) info[SPLAT] = args.slice(1)
+
+ if (tracingEnabled) addTraceContext(info)
+
+ winstonLogger.write(info)
+ }
+
+ return {
+ error: (...args: any[]) => write('error', args),
+ warn: (...args: any[]) => write('warn', args),
+ info: (...args: any[]) => write('info', args),
+ debug: (...args: any[]) => write('debug', args),
+ verbose: (...args: any[]) => write('verbose', args),
+
+ log: (level: string, ...args: any[]) => write(level, args),
+
+ child: (...tags: StaticLoggerTag[]) => buildPeerTubeLogger(winstonLogger, appendTags(boundTags, tags)),
+
+ isLevelEnabled: (level: string) => winstonLogger.isLevelEnabled(level),
+
+ inContext: <T>(fn: () => T) => inLoggerContext(boundTags, fn),
+ withContext: <T>(tags: LoggerTag[], fn: () => T) => inLoggerContext(appendTags(boundTags, tags), fn)
+ }
+}
+
+export function createLogger (...tags: StaticLoggerTag[]): PeerTubeLogger {
+ return rootLogger.child(...tags)
+}
// ---------------------------------------------------------------------------
// Bunyan logger adapter for Winston
@@ -139,7 +275,7 @@ export const bunyanLogger = {
fatal: bunyanLogFactory('error')
}
-function bunyanLogFactory (level: string) {
+function bunyanLogFactory (level: LoggerLevel) {
return function (...params: any[]) {
let meta = null
let args = [].concat(params)
@@ -154,19 +290,7 @@ function bunyanLogFactory (level: string) {
args.push(meta)
}
- logger[level].apply(logger, args)
- }
-}
-
-// ---------------------------------------------------------------------------
-// Logger tags helpers
-// ---------------------------------------------------------------------------
-
-export type LoggerTags = { tags: (string | number)[] }
-export type LoggerTagsFn = (...tags: (string | number)[]) => LoggerTags
-export function loggerTagsFactory (...defaultTags: (string | number)[]): LoggerTagsFn {
- return (...tags: (string | number)[]) => {
- return { tags: defaultTags.concat(tags) }
+ rootLogger.log(level, ...args)
}
}
@@ -192,6 +316,69 @@ export async function mtimeSortFilesDesc (files: string[], basePath: string) {
return out
}
+// ---------------------------------------------------------------------------
+
+export type StaticLoggerTag =
+ | 'actor'
+ | 'ap-cleaner'
+ | 'ap'
+ | 'api'
+ | 'automatic-tags'
+ | 'avatar-image'
+ | 'blacklist'
+ | 'caption'
+ | 'channel-synchronization'
+ | 'chapter'
+ | 'cleaner'
+ | 'create'
+ | 'debug-controller'
+ | 'download'
+ | 'embed-privacy'
+ | 'ffmpeg'
+ | 'geo-ip'
+ | 'hls'
+ | 'job-queue'
+ | 'job'
+ | 'lazy-load'
+ | 'live'
+ | 'move-file-system'
+ | 'move-object-storage'
+ | 'muxing'
+ | 'notifier'
+ | 'object-storage'
+ | 'playlist'
+ | 'plugin'
+ | 'rate-limit'
+ | 'redis'
+ | 'redundancy'
+ | 'refresh'
+ | 'request'
+ | 'resumable-upload'
+ | 'runner'
+ | 'schedulers'
+ | 'share'
+ | 'stats'
+ | 'storyboard'
+ | 'studio'
+ | 'thumbnail'
+ | 'transcoding'
+ | 'transcription'
+ | 'unzip'
+ | 'update-videos'
+ | 'update'
+ | 'user-export'
+ | 'user-import'
+ | 'users'
+ | 'video-download'
+ | 'video-path-manager'
+ | 'video-privacy'
+ | 'video-state'
+ | 'video'
+ | 'view'
+ | 'views'
+ | 'vod'
+ | 'youtube-dl'
+
// ---------------------------------------------------------------------------
// Private
// ---------------------------------------------------------------------------
@@ -231,12 +418,105 @@ function removeCyclicValues () {
}
}
-function getAdditionalInfo (info: any) {
- const toOmit = [ 'label', 'timestamp', 'level', 'message', 'sql', 'tags' ]
+function addTraceContext (info: any) {
+ const spanContext = trace.getSpanContext(context.active())
+ if (!spanContext) return
- return omit(info, toOmit)
+ info.traceId = spanContext.traceId
+ info.spanId = spanContext.spanId
+ info.traceFlags = spanContext.traceFlags
}
+const notAdditionalInfoKeys = new Set([ 'label', 'timestamp', 'level', 'message', 'sql', 'tags' ])
+
+// Most log lines have no additional info: only build the object (and run JSON.stringify) when there is something to print
+function stringifyAdditionalInfo (info: any) {
+ let additionalInfo: Record<string, any>
+
+ for (const key in info) {
+ if (info[key] === undefined) continue
+ if (notAdditionalInfoKeys.has(key)) continue
+
+ if (!additionalInfo) additionalInfo = {}
+ additionalInfo[key] = info[key]
+ }
+
+ if (!additionalInfo) return ''
+
+ return ' ' + JSON.stringify(additionalInfo, removeCyclicValues(), 2)
+}
+
+// Pop the winston "meta" object from the arguments, so we can inject our tags in it.
+// Anything else (format string, splat arguments) is left untouched
+function extractMeta (args: any[]): { tags?: LoggerTag[] } & Record<string, any> {
+ const last = args[args.length - 1]
+
+ if (
+ typeof last !== 'object' ||
+ last === null ||
+ Array.isArray(last) ||
+ last instanceof Error ||
+ Object.getPrototypeOf(last) !== Object.prototype
+ ) {
+ return {}
+ }
+
+ return args.pop()
+}
+
+// ---------------------------------------------------------------------------
+// `fecha` (used by winston when passing a format string) takes several µs per call, which dominates the cost of a log
+// We only need one format, and under load many lines share the same millisecond, so build it by hand and cache it
+// ---------------------------------------------------------------------------
+
+let lastTimestampMs = -1
+let lastTimestamp = ''
+let lastIsoTimestampMs = -1
+let lastIsoTimestamp = ''
+
+function isoTimestamp () {
+ const now = Date.now()
+ if (now === lastIsoTimestampMs) return lastIsoTimestamp
+
+ lastIsoTimestampMs = now
+ lastIsoTimestamp = new Date(now).toISOString()
+
+ return lastIsoTimestamp
+}
+
+function localTimestamp () {
+ const now = Date.now()
+ if (now === lastTimestampMs) return lastTimestamp
+
+ const date = new Date(now)
+
+ lastTimestampMs = now
+ lastTimestamp = date.getFullYear() +
+ '-' + pad2(date.getMonth() + 1) +
+ '-' + pad2(date.getDate()) +
+ ' ' + pad2(date.getHours()) +
+ ':' + pad2(date.getMinutes()) +
+ ':' + pad2(date.getSeconds()) +
+ '.' + pad3(date.getMilliseconds())
+
+ return lastTimestamp
+}
+
+function pad2 (value: number) {
+ return value < 10
+ ? '0' + value
+ : '' + value
+}
+
+function pad3 (value: number) {
+ if (value < 10) return '00' + value
+ if (value < 100) return '0' + value
+
+ return '' + value
+}
+
+// ---------------------------------------------------------------------------
+
function doesConsoleSupportColor () {
if (isTestOrDevInstance()) return true
@@ -244,9 +524,9 @@ function doesConsoleSupportColor () {
}
function exitOnCrash () {
- logger.on('finish', () => {
+ rootWinstonLogger.on('finish', () => {
process.exit(1)
})
- logger.end()
+ rootWinstonLogger.end()
}
diff --git a/server/core/helpers/otp.ts b/server/core/helpers/otp.ts
index 814c76c108..1df21f32da 100644
--- a/server/core/helpers/otp.ts
+++ b/server/core/helpers/otp.ts
@@ -1,9 +1,11 @@
import { CONFIG } from '@server/initializers/config.js'
import { WEBSERVER } from '@server/initializers/constants.js'
import { Secret, TOTP } from 'otpauth'
-import { logger } from './logger.js'
+import { createLogger } from './logger.js'
import { decrypt } from './peertube-crypto.js'
+const logger = createLogger()
+
async function isOTPValid (options: {
encryptedSecret: string
token: string
diff --git a/server/core/helpers/peertube-crypto.ts b/server/core/helpers/peertube-crypto.ts
index b2ac0f56b8..e47bbfd900 100644
--- a/server/core/helpers/peertube-crypto.ts
+++ b/server/core/helpers/peertube-crypto.ts
@@ -5,7 +5,9 @@ import { Request } from 'express'
import { BCRYPT_SALT_SIZE, ENCRYPTION, PRIVATE_RSA_KEY_SIZE } from '../initializers/constants.js'
import { MActor } from '../types/models/index.js'
import { generateRSAKeyPairPromise, randomBytesPromise, scryptPromise } from './core-utils.js'
-import { logger } from './logger.js'
+import { createLogger } from './logger.js'
+
+const logger = createLogger()
function createPrivateAndPublicKeys () {
logger.info('Generating a RSA key...')
diff --git a/server/core/helpers/peertube-jsonld.ts b/server/core/helpers/peertube-jsonld.ts
index b09a3a9842..97a3c5b733 100644
--- a/server/core/helpers/peertube-jsonld.ts
+++ b/server/core/helpers/peertube-jsonld.ts
@@ -6,9 +6,11 @@ import { MActor } from '../types/models/index.js'
import { getAllContext } from './activity-pub-utils.js'
import { jsonld } from './custom-jsonld-signature.js'
import { isArray } from './custom-validators/misc.js'
-import { logger } from './logger.js'
+import { createLogger } from './logger.js'
import { assertIsInWorkerThread } from './threads.js'
+const logger = createLogger()
+
type ExpressRequest = { body: any }
export function compactJSONLDAndCheckSignature (fromActor: MActor, req: ExpressRequest): Promise<boolean> {
diff --git a/server/core/helpers/requests.ts b/server/core/helpers/requests.ts
index 7886cfb281..d97a2990da 100644
--- a/server/core/helpers/requests.ts
+++ b/server/core/helpers/requests.ts
@@ -18,10 +18,10 @@ import https from 'https'
import { HttpProxyAgent, HttpsProxyAgent } from '../helpers/hpagent.js'
import { ACTIVITY_PUB, BINARY_CONTENT_TYPES, PEERTUBE_VERSION, REQUEST_TIMEOUTS, WEBSERVER } from '../initializers/constants.js'
import { pipelinePromise } from './core-utils.js'
-import { logger, loggerTagsFactory } from './logger.js'
+import { createLogger } from './logger.js'
import { getProxy, isProxyEnabled } from './proxy.js'
-const lTags = loggerTagsFactory('request')
+const logger = createLogger('request')
export interface PeerTubeRequestError extends Error {
statusCode?: number
@@ -81,7 +81,7 @@ const unsafeSSRFGot = got.extend({
if (progress.transferred > bodyLimit && progress.percent !== 1) {
const message = `Exceeded the download limit of ${bodyLimit} B`
const error = new Error(message)
- logger.warn(message, lTags())
+ logger.warn(message)
if (options.isStream) {
;(promiseOrStream as Request).destroy(error)
@@ -133,7 +133,7 @@ const unsafeSSRFGot = got.extend({
beforeRetry: [
(error: RequestError, retryCount: number) => {
- logger.debug('Retrying request to %s.', error.request.requestUrl, { retryCount, error: buildRequestError(error), ...lTags() })
+ logger.debug('Retrying request to %s.', error.request.requestUrl, { retryCount, error: buildRequestError(error) })
}
]
}
@@ -196,7 +196,7 @@ export async function doRequestAndSaveToFile (url: string, destPath: string, opt
)
} catch (err) {
remove(destPath)
- .catch(err => logger.error('Cannot remove %s after request failure.', destPath, { err, ...lTags() }))
+ .catch(err => logger.error('Cannot remove %s after request failure.', destPath, { err }))
throw buildRequestError(err)
}
@@ -220,7 +220,7 @@ export function getProxyAgent () {
const proxy = getProxy()
- logger.info('Using proxy %s.', proxy, lTags())
+ logger.info('Using proxy %s.', proxy)
const proxyAgentOptions = {
keepAlive: true,
diff --git a/server/core/helpers/threads.ts b/server/core/helpers/threads.ts
index ff6b85a26f..1b871f9de9 100644
--- a/server/core/helpers/threads.ts
+++ b/server/core/helpers/threads.ts
@@ -1,6 +1,8 @@
import { isTestOrDevInstance } from '@peertube/peertube-node-utils'
import { isMainThread } from 'node:worker_threads'
-import { logger } from './logger.js'
+import { createLogger } from './logger.js'
+
+const logger = createLogger()
export function assertIsInWorkerThread () {
if (!isMainThread) return
diff --git a/server/core/helpers/unzip.ts b/server/core/helpers/unzip.ts
index 1a37436e50..fc4ac1cf27 100644
--- a/server/core/helpers/unzip.ts
+++ b/server/core/helpers/unzip.ts
@@ -3,9 +3,9 @@ import { ensureDir } from 'fs-extra/esm'
import { dirname, isAbsolute, join, relative } from 'path'
import { pipeline } from 'stream'
import * as yauzl from 'yauzl'
-import { logger, loggerTagsFactory } from './logger.js'
+import { createLogger } from './logger.js'
-const lTags = loggerTagsFactory('unzip')
+const logger = createLogger('unzip')
export async function unzip (options: {
source: string
@@ -17,7 +17,7 @@ export async function unzip (options: {
await ensureDir(destination)
- logger.info(`Unzip ${source} to ${destination}`, lTags())
+ logger.info(`Unzip ${source} to ${destination}`)
return new Promise<void>((res, rej) => {
yauzl.open(source, { lazyEntries: true }, (err, zipFile) => {
@@ -54,7 +54,7 @@ export async function unzip (options: {
try {
if (entry.fileName.endsWith('/')) {
await ensureDir(entryPath)
- logger.debug(`Creating directory from zip ${entryPath}`, lTags())
+ logger.debug(`Creating directory from zip ${entryPath}`)
zipFile.readEntry()
return
@@ -68,7 +68,7 @@ export async function unzip (options: {
zipFile.openReadStream(entry, (readErr, readStream) => {
if (readErr) return rej(readErr)
- logger.debug(`Creating file from zip ${entryPath}`, lTags())
+ logger.debug(`Creating file from zip ${entryPath}`)
const writeStream = createWriteStream(entryPath)
writeStream.on('close', () => zipFile.readEntry())
diff --git a/server/core/helpers/version.ts b/server/core/helpers/version.ts
index adf91b586a..eba411ad22 100644
--- a/server/core/helpers/version.ts
+++ b/server/core/helpers/version.ts
@@ -1,5 +1,7 @@
import { execPromise, execPromise2 } from './core-utils.js'
-import { logger } from './logger.js'
+import { createLogger } from './logger.js'
+
+const logger = createLogger()
export async function getServerCommit () {
try {
diff --git a/server/core/helpers/youtube-dl/youtube-dl-cli.ts b/server/core/helpers/youtube-dl/youtube-dl-cli.ts
index 1b0a54dffa..6980b0a6da 100644
--- a/server/core/helpers/youtube-dl/youtube-dl-cli.ts
+++ b/server/core/helpers/youtube-dl/youtube-dl-cli.ts
@@ -6,13 +6,13 @@ import { ensureDir, pathExists } from 'fs-extra/esm'
import { chmod, writeFile } from 'fs/promises'
import { dirname, join } from 'path'
import { REQUEST_TIMEOUTS } from '../../initializers/constants.js'
-import { logger, loggerTagsFactory } from '../logger.js'
+import { createLogger } from '../logger.js'
import { getProxy, isProxyEnabled } from '../proxy.js'
import { doBufferRequest, isBinaryResponse, PeerTubeRequestOptions } from '../requests.js'
-type ProcessOptions = Pick<ExecaNodeOptions, 'cwd' | 'maxBuffer'>
+const logger = createLogger('youtube-dl')
-const lTags = loggerTagsFactory('youtube-dl')
+type ProcessOptions = Pick<ExecaNodeOptions, 'cwd' | 'maxBuffer'>
const youtubeDLBinaryPath = join(CONFIG.STORAGE.BIN_DIR, CONFIG.IMPORT.VIDEOS.HTTP.YOUTUBE_DL_RELEASE.NAME)
@@ -30,7 +30,7 @@ export class YoutubeDLCLI {
static async updateYoutubeDLBinary () {
const url = CONFIG.IMPORT.VIDEOS.HTTP.YOUTUBE_DL_RELEASE.URL
- logger.info('Updating youtubeDL binary from %s.', url, lTags())
+ logger.info('Updating youtubeDL binary from %s.', url)
const requestOptions: PeerTubeRequestOptions & { preventSSRF?: false } = {
bodyKBLimit: 100_000,
@@ -69,9 +69,9 @@ export class YoutubeDLCLI {
await chmod(youtubeDLBinaryPath, '744')
}
- logger.info('youtube-dl updated %s.', youtubeDLBinaryPath, lTags())
+ logger.info('youtube-dl updated %s.', youtubeDLBinaryPath)
} catch (err) {
- logger.error('Cannot update youtube-dl from %s.', url, { err, ...lTags() })
+ logger.error('Cannot update youtube-dl from %s.', url, { err })
}
}
@@ -232,7 +232,7 @@ export class YoutubeDLCLI {
const output = await subProcess
- logger.debug('Run youtube-dl command.', { command: output.command, ...lTags() })
+ logger.debug('Run youtube-dl command.', { command: output.command })
return output.stdout
? output.stdout.trim().split(/\r?\n/)
@@ -256,7 +256,7 @@ export class YoutubeDLCLI {
? config[randomInt(0, config.length)]
: getProxy()
- logger.debug('Using proxy %s for YoutubeDL', proxy, lTags())
+ logger.debug('Using proxy %s for YoutubeDL', proxy)
return [ '--proxy', proxy ].concat(args)
}
@@ -284,21 +284,20 @@ export class YoutubeDLCLI {
if (!await pathExists(cookiesPath)) {
logger.error(
'yt-dlp cookies are enabled but the cookies file %s does not exist. Continuing without cookies.',
- cookiesPath,
- lTags()
+ cookiesPath
)
return args
}
- logger.debug('Using cookies file %s for YoutubeDL', cookiesPath, lTags())
+ logger.debug('Using cookies file %s for YoutubeDL', cookiesPath)
return [ '--cookies', cookiesPath ].concat(args)
}
private wrapWithFFmpegOptions (args: string[]) {
if (process.env.FFMPEG_PATH) {
- logger.debug('Using ffmpeg location %s for YoutubeDL', process.env.FFMPEG_PATH, lTags())
+ logger.debug('Using ffmpeg location %s for YoutubeDL', process.env.FFMPEG_PATH)
return [ '--ffmpeg-location', process.env.FFMPEG_PATH ].concat(args)
}
diff --git a/server/core/helpers/youtube-dl/youtube-dl-wrapper.ts b/server/core/helpers/youtube-dl/youtube-dl-wrapper.ts
index 766d974ebd..115fa724d8 100644
--- a/server/core/helpers/youtube-dl/youtube-dl-wrapper.ts
+++ b/server/core/helpers/youtube-dl/youtube-dl-wrapper.ts
@@ -8,12 +8,12 @@ import { inspect } from 'util'
import { isVideoFileExtnameValid } from '../custom-validators/videos.js'
import { isResolvingToUnicastOnly } from '../dns.js'
import { t } from '../i18n.js'
-import { logger, loggerTagsFactory } from '../logger.js'
+import { createLogger } from '../logger.js'
import { generateVideoImportTmpPath } from '../utils.js'
import { YoutubeDLCLI } from './youtube-dl-cli.js'
import { YoutubeDLInfo, YoutubeDLInfoBuilder } from './youtube-dl-info-builder.js'
-const lTags = loggerTagsFactory('youtube-dl')
+const logger = createLogger('youtube-dl')
export const YoutubeDlImportErrorCode = {
FETCH_ERROR: 0,
@@ -159,7 +159,7 @@ export class YoutubeDLWrapper {
})
if (!Array.isArray(list)) {
- logger.debug(`List info from youtube-dl is not an array for ${this.url}.`, { info: inspect(list), ...lTags() })
+ logger.debug(`List info from youtube-dl is not an array for ${this.url}.`, { info: inspect(list) })
throw new YoutubeDlImportError({
message: t(`YoutubeDL could not get list info from ${this.url}: ${inspect(list)}`, userLanguage, { targetUrl: this.url }),
@@ -182,7 +182,7 @@ export class YoutubeDLWrapper {
const files = await youtubeDL.getSubs({ url: this.url, format: 'vtt', processOptions: { cwd } })
if (!files) return []
- logger.debug('Get subtitles from youtube dl.', { url: this.url, files, ...lTags() })
+ logger.debug('Get subtitles from youtube dl.', { url: this.url, files })
const subtitles = files.reduce((acc, filename) => {
const matched = filename.match(/\.([a-z]{2})(-[a-z]+)?\.(vtt|ttml)/i)
@@ -213,7 +213,7 @@ export class YoutubeDLWrapper {
// Leave empty the extension, youtube-dl will add it
const pathWithoutExtension = generateVideoImportTmpPath(this.url, '')
- logger.info('Importing youtubeDL video %s to %s', this.url, pathWithoutExtension, lTags())
+ logger.info('Importing youtubeDL video %s to %s', this.url, pathWithoutExtension)
const youtubeDL = await YoutubeDLCLI.safeGet()
@@ -242,11 +242,11 @@ export class YoutubeDLWrapper {
} catch (err) {
this.guessVideoPathWithExtension(pathWithoutExtension, fileExt)
.then(path => {
- logger.debug('Error in youtube-dl import, deleting file if exists.', { err, pathToDelete: path, ...lTags() })
+ logger.debug('Error in youtube-dl import, deleting file if exists.', { err, pathToDelete: path })
if (path) return remove(path)
})
- .catch(innerErr => logger.error('Cannot remove file in youtubeDL error.', { innerErr, ...lTags() }))
+ .catch(innerErr => logger.error('Cannot remove file in youtubeDL error.', { innerErr }))
throw err
}
diff --git a/server/core/initializers/checker-after-init.ts b/server/core/initializers/checker-after-init.ts
index 11e313dfa2..c7556d7ca2 100644
--- a/server/core/initializers/checker-after-init.ts
+++ b/server/core/initializers/checker-after-init.ts
@@ -8,13 +8,15 @@ import { URL } from 'url'
import { parseBytes, parseSemVersion } from '../helpers/core-utils.js'
import { isArray } from '../helpers/custom-validators/misc.js'
import { getBrowseVideosDefaultSortError, getBrowseVideosDefaultScopeError } from '../helpers/custom-validators/browse-videos.js'
-import { logger } from '../helpers/logger.js'
+import { createLogger } from '../helpers/logger.js'
import { ApplicationModel, getServerActor } from '../models/application/application.js'
import { OAuthClientModel } from '../models/oauth/oauth-client.js'
import { UserModel } from '../models/user/user.js'
import { CONFIG, getConfigModule, getLocalConfigFilePath, isEmailEnabled, reloadConfig } from './config.js'
import { WEBSERVER } from './constants.js'
+const logger = createLogger()
+
async function checkActivityPubUrls () {
const actor = await getServerActor()
diff --git a/server/core/initializers/checker-before-init.ts b/server/core/initializers/checker-before-init.ts
index adbcae229c..8cc5dd59fe 100644
--- a/server/core/initializers/checker-before-init.ts
+++ b/server/core/initializers/checker-before-init.ts
@@ -1,8 +1,10 @@
import { promisify0 } from '@peertube/peertube-core-utils'
import { parseSemVersion } from '../helpers/core-utils.js'
-import { logger } from '../helpers/logger.js'
+import { createLogger } from '../helpers/logger.js'
import { getConfigModule } from './config.js'
+const logger = createLogger()
+
// ONLY USE CORE MODULES IN THIS FILE!
// Check the config files
diff --git a/server/core/initializers/database.ts b/server/core/initializers/database.ts
index 7a06f3a0cd..35f04c7456 100644
--- a/server/core/initializers/database.ts
+++ b/server/core/initializers/database.ts
@@ -38,7 +38,7 @@ import { readFileSync } from 'fs'
import pg from 'pg'
import { QueryTypes, Transaction } from 'sequelize'
import { Sequelize as SequelizeTypescript } from 'sequelize-typescript'
-import { logger } from '../helpers/logger.js'
+import { createLogger } from '../helpers/logger.js'
import { AbuseMessageModel } from '../models/abuse/abuse-message.js'
import { AbuseModel } from '../models/abuse/abuse.js'
import { VideoAbuseModel } from '../models/abuse/video-abuse.js'
@@ -83,6 +83,8 @@ import { VideoModel } from '../models/video/video.js'
import { CONFIG } from './config.js'
import { VIDEO_SEARCH_INDEXED_DESCRIPTION_LENGTH } from './constants.js'
+const logger = createLogger()
+
pg.defaults.parseInt8 = true // Avoid BIGINT to be converted to string
const dbname = CONFIG.DATABASE.DBNAME
diff --git a/server/core/initializers/installer.ts b/server/core/initializers/installer.ts
index f74e8e297f..3d3571f833 100644
--- a/server/core/initializers/installer.ts
+++ b/server/core/initializers/installer.ts
@@ -8,7 +8,7 @@ import { ensureDir, remove } from 'fs-extra/esm'
import { readdir } from 'fs/promises'
import { generatePassword } from 'password-generator'
import { join } from 'path'
-import { logger } from '../helpers/logger.js'
+import { createLogger } from '../helpers/logger.js'
import { buildUser, createApplicationActor, createUserAccountAndChannelAndPlaylist } from '../lib/user.js'
import { ApplicationModel } from '../models/application/application.js'
import { OAuthClientModel } from '../models/oauth/oauth-client.js'
@@ -17,6 +17,8 @@ import { CONFIG } from './config.js'
import { ADMIN_MEMORABLE_PASSWORD_GENERATION_LENGTH, DIRECTORIES, FILES_CACHE, LAST_MIGRATION_VERSION } from './constants.js'
import { sequelizeTypescript } from './database.js'
+const logger = createLogger()
+
async function installApplication () {
try {
await Promise.all([
diff --git a/server/core/initializers/migrations/0870-remove-web-video-redundancy.ts b/server/core/initializers/migrations/0870-remove-web-video-redundancy.ts
index 7ee4b3c5fd..5a48db08bc 100644
--- a/server/core/initializers/migrations/0870-remove-web-video-redundancy.ts
+++ b/server/core/initializers/migrations/0870-remove-web-video-redundancy.ts
@@ -1,4 +1,4 @@
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { VideoFileModel } from '@server/models/video/video-file.js'
import { remove } from 'fs-extra'
import { join } from 'path'
@@ -6,6 +6,8 @@ import * as Sequelize from 'sequelize'
import { QueryTypes } from 'sequelize'
import { CONFIG } from '../config.js'
+const logger = createLogger()
+
async function up (utils: {
transaction: Sequelize.Transaction
queryInterface: Sequelize.QueryInterface
diff --git a/server/core/initializers/migrations/0975-pkcs8.ts b/server/core/initializers/migrations/0975-pkcs8.ts
index b994c37fca..6e6a705d72 100644
--- a/server/core/initializers/migrations/0975-pkcs8.ts
+++ b/server/core/initializers/migrations/0975-pkcs8.ts
@@ -1,7 +1,9 @@
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { createPrivateKey } from 'crypto'
import * as Sequelize from 'sequelize'
+const logger = createLogger()
+
async function up (utils: {
transaction: Sequelize.Transaction
queryInterface: Sequelize.QueryInterface
diff --git a/server/core/initializers/migrations/1090-otp-secret-gcm.ts b/server/core/initializers/migrations/1090-otp-secret-gcm.ts
index 489502766d..da9d1b158d 100644
--- a/server/core/initializers/migrations/1090-otp-secret-gcm.ts
+++ b/server/core/initializers/migrations/1090-otp-secret-gcm.ts
@@ -1,8 +1,10 @@
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { createCipheriv, createDecipheriv, randomBytes, scryptSync } from 'crypto'
import * as Sequelize from 'sequelize'
import { CONFIG } from '../config.js'
+const logger = createLogger()
+
// Crypto is inlined (rather than imported from peertube-crypto.ts) so this migration stays a frozen,
// self-contained artifact: removing the legacy CBC fallback from the helper later cannot break it
const ENCODING = 'hex'
diff --git a/server/core/initializers/migrator.ts b/server/core/initializers/migrator.ts
index a4b9ad81ee..20f9e66af4 100644
--- a/server/core/initializers/migrator.ts
+++ b/server/core/initializers/migrator.ts
@@ -3,10 +3,12 @@ import { currentDir } from '@peertube/peertube-node-utils'
import { readdir } from 'fs/promises'
import { join } from 'path'
import { QueryTypes } from 'sequelize'
-import { logger } from '../helpers/logger.js'
+import { createLogger } from '../helpers/logger.js'
import { LAST_MIGRATION_VERSION } from './constants.js'
import { sequelizeTypescript } from './database.js'
+const logger = createLogger()
+
async function migrate () {
const tables = await sequelizeTypescript.getQueryInterface().showAllTables()
diff --git a/server/core/lib/activitypub/actors/get.ts b/server/core/lib/activitypub/actors/get.ts
index 80bb7c03ac..8a15c710b5 100644
--- a/server/core/lib/activitypub/actors/get.ts
+++ b/server/core/lib/activitypub/actors/get.ts
@@ -1,7 +1,7 @@
import { arrayify } from '@peertube/peertube-core-utils'
import { ActivityPubActor, APObjectId } from '@peertube/peertube-models'
import { retryTransactionWrapper } from '@server/helpers/database-utils.js'
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { JobQueue } from '@server/lib/job-queue/index.js'
import { ActorLoadByUrlType, loadActorByUrl } from '@server/lib/model-loaders/index.js'
import {
@@ -16,6 +16,8 @@ import { checkUrlsSameHost } from '../url.js'
import { refreshActorIfNeeded } from './refresh.js'
import { APActorCreator, fetchRemoteActor } from './shared/index.js'
+const logger = createLogger()
+
// FIXME: use an object for params
function getOrCreateAPActor (
activityActor: string | ActivityPubActor,
diff --git a/server/core/lib/activitypub/actors/image.ts b/server/core/lib/activitypub/actors/image.ts
index a4e6c22552..5b180ed70e 100644
--- a/server/core/lib/activitypub/actors/image.ts
+++ b/server/core/lib/activitypub/actors/image.ts
@@ -1,9 +1,11 @@
import { ActorImageType, ActorImageType_Type } from '@peertube/peertube-models'
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { ActorImageModel } from '@server/models/actor/actor-image.js'
import { MActorImage, MActorImages } from '@server/types/models/index.js'
import { Transaction } from 'sequelize'
+const logger = createLogger()
+
type ImageInfo = {
name: string
fileUrl: string
diff --git a/server/core/lib/activitypub/actors/refresh.ts b/server/core/lib/activitypub/actors/refresh.ts
index 1e13bef165..160d3d065d 100644
--- a/server/core/lib/activitypub/actors/refresh.ts
+++ b/server/core/lib/activitypub/actors/refresh.ts
@@ -1,5 +1,5 @@
import { HttpStatusCode } from '@peertube/peertube-models'
-import { logger, loggerTagsFactory } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { CachePromiseFactory } from '@server/helpers/promise-cache.js'
import { PeerTubeRequestError } from '@server/helpers/requests.js'
import { JobQueue } from '@server/lib/job-queue/job-queue.js'
@@ -10,6 +10,8 @@ import { fetchRemoteActor } from './shared/index.js'
import { APActorUpdater } from './updater.js'
import { getUrlFromWebfinger } from './webfinger.js'
+const logger = createLogger('ap', 'actor', 'refresh')
+
type RefreshResult<T> = Promise<{ actor: T | MActorFull, refreshed: boolean }>
type RefreshOptions<T> = {
@@ -51,39 +53,39 @@ async function doRefresh<T extends MActorFull | MActorOutdated> (options: Refres
? actorArg as MActorFull
: await ActorModel.loadAndPopulateAccountAndChannel(actorArg.id)
- const lTags = loggerTagsFactory('ap', 'actor', 'refresh', actor.url)
+ return logger.withContext([ actor.url ], async () => {
+ logger.info('Refreshing actor %s.', actor.url)
- logger.info('Refreshing actor %s.', actor.url, lTags())
+ try {
+ const actorUrl = await getActorUrl(actor)
+ const { actorObject } = await fetchRemoteActor(actorUrl)
- try {
- const actorUrl = await getActorUrl(actor)
- const { actorObject } = await fetchRemoteActor(actorUrl)
+ if (actorObject === undefined) {
+ logger.info('Cannot fetch remote actor %s in refresh actor.', actorUrl)
+ return { actor, refreshed: false }
+ }
- if (actorObject === undefined) {
- logger.info('Cannot fetch remote actor %s in refresh actor.', actorUrl)
- return { actor, refreshed: false }
- }
+ const updater = new APActorUpdater(actorObject, actor)
+ await updater.update()
- const updater = new APActorUpdater(actorObject, actor)
- await updater.update()
+ return { refreshed: true, actor }
+ } catch (err) {
+ const statusCode = (err as PeerTubeRequestError).statusCode
- return { refreshed: true, actor }
- } catch (err) {
- const statusCode = (err as PeerTubeRequestError).statusCode
+ if (statusCode === HttpStatusCode.NOT_FOUND_404 || statusCode === HttpStatusCode.GONE_410) {
+ logger.info('Deleting actor %s because there is a 404/410 in refresh actor.', actor.url)
- if (statusCode === HttpStatusCode.NOT_FOUND_404 || statusCode === HttpStatusCode.GONE_410) {
- logger.info('Deleting actor %s because there is a 404/410 in refresh actor.', actor.url, lTags())
+ actor.Account
+ ? await actor.Account.destroy()
+ : await actor.VideoChannel.destroy()
- actor.Account
- ? await actor.Account.destroy()
- : await actor.VideoChannel.destroy()
+ return { actor: undefined, refreshed: false }
+ }
- return { actor: undefined, refreshed: false }
+ logger.info('Cannot refresh actor %s.', actor.url, { err })
+ return { actor, refreshed: false }
}
-
- logger.info('Cannot refresh actor %s.', actor.url, { err, ...lTags() })
- return { actor, refreshed: false }
- }
+ })
}
function getActorUrl (actor: MActorFull) {
diff --git a/server/core/lib/activitypub/actors/shared/creator.ts b/server/core/lib/activitypub/actors/shared/creator.ts
index ebe07e7407..4f151079ef 100644
--- a/server/core/lib/activitypub/actors/shared/creator.ts
+++ b/server/core/lib/activitypub/actors/shared/creator.ts
@@ -1,6 +1,6 @@
import { ActivityPubActor, ActorImageType, ActorImageType_Type } from '@peertube/peertube-models'
import { isAccountActor, isChannelActor } from '@server/helpers/actors.js'
-import { logger, loggerTagsFactory, LoggerTagsFn } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { sequelizeTypescript } from '@server/initializers/database.js'
import { AccountModel } from '@server/models/account/account.js'
import { ActorModel } from '@server/models/actor/actor.js'
@@ -14,18 +14,21 @@ import { updateActorImages } from '../image.js'
import { getActorAttributesFromObject, getActorDisplayNameFromObject, getImagesInfoFromObject } from './object-to-model-attributes.js'
import { fetchActorFollowsCount } from './url-to-object.js'
-export class APActorCreator {
- private readonly lTags: LoggerTagsFn
+const logger = createLogger('ap', 'actor', 'create')
+export class APActorCreator {
constructor (
private readonly actorObject: ActivityPubActor,
private readonly ownerActor?: MActorFullActor
- ) {
- this.lTags = loggerTagsFactory('ap', 'actor', 'create', this.actorObject.id)
- }
+ ) {}
+ // Wraps `runCreate` so every logger call it makes (including in inner/async functions) is tagged with this actor
async create (): Promise<MActorFull> {
- logger.debug('Creating remote actor from object', { actorObject: this.actorObject, ...this.lTags() })
+ return logger.withContext([ this.actorObject.id ], () => this.runCreate())
+ }
+
+ private async runCreate (): Promise<MActorFull> {
+ logger.debug('Creating remote actor from object', { actorObject: this.actorObject })
// A remote actor must never be registered with our own host
if (isLocalUrl(this.actorObject.id)) {
@@ -47,7 +50,7 @@ export class APActorCreator {
})
if (existingActor) {
- logger.debug(`Actor ${existingActor.id} already exists, updating existing one`, this.lTags())
+ logger.debug(`Actor ${existingActor.id} already exists, updating existing one`)
// Re-init unique keys
existingActor.preferredUsername = actorInstance.preferredUsername
diff --git a/server/core/lib/activitypub/actors/shared/url-to-object.ts b/server/core/lib/activitypub/actors/shared/url-to-object.ts
index 39382aed95..c26e6ef378 100644
--- a/server/core/lib/activitypub/actors/shared/url-to-object.ts
+++ b/server/core/lib/activitypub/actors/shared/url-to-object.ts
@@ -1,10 +1,12 @@
import { ActivityPubActor, ActivityPubOrderedCollection } from '@peertube/peertube-models'
import { sanitizeAndCheckActorObject } from '@server/helpers/custom-validators/activitypub/actor.js'
import { isUrlValid } from '@server/helpers/custom-validators/activitypub/misc.js'
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { fetchAP } from '../../activity.js'
import { checkUrlsSameHost } from '../../url.js'
+const logger = createLogger()
+
export async function fetchRemoteActor (
actorUrl: string,
canRefetchPublicKeyOwner = true
diff --git a/server/core/lib/activitypub/actors/updater.ts b/server/core/lib/activitypub/actors/updater.ts
index 923575be30..8fd88a9a2e 100644
--- a/server/core/lib/activitypub/actors/updater.ts
+++ b/server/core/lib/activitypub/actors/updater.ts
@@ -1,6 +1,6 @@
import { ActivityPubActor, ActorImageType } from '@peertube/peertube-models'
import { resetSequelizeInstance, runInReadCommittedTransaction } from '@server/helpers/database-utils.js'
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { AccountModel } from '@server/models/account/account.js'
import { VideoChannelModel } from '@server/models/video/video-channel.js'
import { VideoPlaylistModel } from '@server/models/video/video-playlist.js'
@@ -12,6 +12,8 @@ import { updateActorImages } from './image.js'
import { fetchActorFollowsCount } from './shared/index.js'
import { getImagesInfoFromObject } from './shared/object-to-model-attributes.js'
+const logger = createLogger()
+
export class APActorUpdater {
private readonly accountOrChannel: MAccount | MChannel
diff --git a/server/core/lib/activitypub/cache-file.ts b/server/core/lib/activitypub/cache-file.ts
index 8a21a6e915..dcdae3fa3e 100644
--- a/server/core/lib/activitypub/cache-file.ts
+++ b/server/core/lib/activitypub/cache-file.ts
@@ -1,9 +1,11 @@
import { CacheFileObject, VideoStreamingPlaylistType } from '@peertube/peertube-models'
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { MActorId, MVideoRedundancy, MVideoWithAllFiles } from '@server/types/models/index.js'
import { Transaction } from 'sequelize'
import { VideoRedundancyModel } from '../../models/redundancy/video-redundancy.js'
+const logger = createLogger()
+
export async function createOrUpdateCacheFile (
cacheFileObject: CacheFileObject,
video: MVideoWithAllFiles,
diff --git a/server/core/lib/activitypub/crawl.ts b/server/core/lib/activitypub/crawl.ts
index 929548ee5c..6de8f7df70 100644
--- a/server/core/lib/activitypub/crawl.ts
+++ b/server/core/lib/activitypub/crawl.ts
@@ -2,10 +2,12 @@ import { ActivityPubOrderedCollection } from '@peertube/peertube-models'
import { retryTransactionWrapper } from '@server/helpers/database-utils.js'
import Bluebird from 'bluebird'
import { URL } from 'url'
-import { logger } from '../../helpers/logger.js'
+import { createLogger } from '../../helpers/logger.js'
import { ACTIVITY_PUB, WEBSERVER } from '../../initializers/constants.js'
import { fetchAP } from './activity.js'
+const logger = createLogger()
+
type HandlerFunction<T> = (items: T[]) => Promise<any> | Bluebird<any>
type CleanerFunction = (startedDate: Date) => Promise<any>
diff --git a/server/core/lib/activitypub/follow.ts b/server/core/lib/activitypub/follow.ts
index d6c60602bf..e82c833701 100644
--- a/server/core/lib/activitypub/follow.ts
+++ b/server/core/lib/activitypub/follow.ts
@@ -1,12 +1,14 @@
import { Transaction } from 'sequelize'
import { getServerActor } from '@server/models/application/application.js'
-import { logger } from '../../helpers/logger.js'
+import { createLogger } from '../../helpers/logger.js'
import { CONFIG } from '../../initializers/config.js'
import { SERVER_ACTOR_NAME } from '../../initializers/constants.js'
import { ServerModel } from '../../models/server/server.js'
import { MActorFollowActors } from '../../types/models/index.js'
import { JobQueue } from '../job-queue/index.js'
+const logger = createLogger()
+
async function autoFollowBackIfNeeded (actorFollow: MActorFollowActors, transaction?: Transaction) {
if (!CONFIG.FOLLOWINGS.INSTANCE.AUTO_FOLLOW_BACK.ENABLED) return
diff --git a/server/core/lib/activitypub/inbox-manager.ts b/server/core/lib/activitypub/inbox-manager.ts
index eaaa1cad7e..9806a846a9 100644
--- a/server/core/lib/activitypub/inbox-manager.ts
+++ b/server/core/lib/activitypub/inbox-manager.ts
@@ -1,11 +1,13 @@
import PQueue from 'p-queue'
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { SCHEDULER_INTERVALS_MS } from '@server/initializers/constants.js'
import { MActorDefault, MActorSignature } from '@server/types/models/index.js'
import { Activity, ActivityType } from '@peertube/peertube-models'
import { StatsManager } from '../stat-manager.js'
import { processActivities } from './process/index.js'
+const logger = createLogger()
+
export class InboxManager {
private static instance: InboxManager
private readonly seqInboxQueue: PQueue
diff --git a/server/core/lib/activitypub/outbox.ts b/server/core/lib/activitypub/outbox.ts
index 8e3cf68159..7793f6a431 100644
--- a/server/core/lib/activitypub/outbox.ts
+++ b/server/core/lib/activitypub/outbox.ts
@@ -1,8 +1,10 @@
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { ActorModel } from '@server/models/actor/actor.js'
import { getServerActor } from '@server/models/application/application.js'
import { JobQueue } from '../job-queue/index.js'
+const logger = createLogger()
+
async function addFetchOutboxJob (actor: Pick<ActorModel, 'id' | 'outboxUrl'>) {
// Don't fetch ourselves
const serverActor = await getServerActor()
diff --git a/server/core/lib/activitypub/playlists/create-update.ts b/server/core/lib/activitypub/playlists/create-update.ts
index e1cf8c416c..cb50651780 100644
--- a/server/core/lib/activitypub/playlists/create-update.ts
+++ b/server/core/lib/activitypub/playlists/create-update.ts
@@ -2,7 +2,7 @@ import { guessAspectRatio } from '@peertube/peertube-core-utils'
import { ActivityIconObject, HttpStatusCode, PlaylistObject } from '@peertube/peertube-models'
import { isActivityPubUrlValid } from '@server/helpers/custom-validators/activitypub/misc.js'
import { retryTransactionWrapper } from '@server/helpers/database-utils.js'
-import { logger, loggerTagsFactory } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { PeerTubeRequestError } from '@server/helpers/requests.js'
import { CRAWL_REQUEST_CONCURRENCY } from '@server/initializers/constants.js'
import { sequelizeTypescript } from '@server/initializers/database.js'
@@ -24,34 +24,35 @@ import {
playlistObjectToDBAttributes
} from './shared/index.js'
-const lTags = loggerTagsFactory('ap', 'video-playlist')
+const logger = createLogger('ap', 'playlist')
export async function createAccountPlaylists (playlistUrls: string[], account: MAccountHost) {
logger.info(
- `Creating or updating ${playlistUrls.length} playlists for account ${account.Actor.preferredUsername}`,
- lTags()
+ `Creating or updating ${playlistUrls.length} playlists for account ${account.Actor.preferredUsername}`
)
await Bluebird.map(playlistUrls, async playlistUrl => {
- if (!checkUrlsSameHost(playlistUrl, account.Actor.url)) {
- logger.warn(`Playlist ${playlistUrl} is not on the same host as owner account ${account.Actor.url}`, lTags(playlistUrl))
- return
- }
+ await logger.withContext([ playlistUrl ], async () => {
+ if (!checkUrlsSameHost(playlistUrl, account.Actor.url)) {
+ logger.warn(`Playlist ${playlistUrl} is not on the same host as owner account ${account.Actor.url}`)
+ return
+ }
- try {
- const exists = await VideoPlaylistModel.doesPlaylistExist(playlistUrl)
- if (exists === true) return
+ try {
+ const exists = await VideoPlaylistModel.doesPlaylistExist(playlistUrl)
+ if (exists === true) return
- const { playlistObject } = await fetchRemoteVideoPlaylist(playlistUrl)
+ const { playlistObject } = await fetchRemoteVideoPlaylist(playlistUrl)
- if (playlistObject === undefined) {
- throw new Error(`Cannot refresh remote playlist ${playlistUrl}: invalid body.`)
- }
+ if (playlistObject === undefined) {
+ throw new Error(`Cannot refresh remote playlist ${playlistUrl}: invalid body.`)
+ }
- return createOrUpdateVideoPlaylist({ playlistObject, contextUrl: playlistUrl })
- } catch (err) {
- logger.warn(`Cannot create or update playlist ${playlistUrl}`, { err, ...lTags(playlistUrl) })
- }
+ return createOrUpdateVideoPlaylist({ playlistObject, contextUrl: playlistUrl })
+ } catch (err) {
+ logger.warn(`Cannot create or update playlist ${playlistUrl}`, { err })
+ }
+ })
}, { concurrency: CRAWL_REQUEST_CONCURRENCY })
}
@@ -73,7 +74,7 @@ export async function createOrUpdateVideoPlaylist (options: {
throw new Error(`Playlist ${playlistObject.id} is not on the same host as context URL ${contextUrl}`)
}
- logger.debug(`Creating or updating playlist ${playlistObject.id}`, lTags(playlistObject.id))
+ logger.debug(`Creating or updating playlist ${playlistObject.id}`)
const playlistAttributes = playlistObjectToDBAttributes(playlistObject, to || playlistObject.to)
@@ -159,10 +160,10 @@ async function updatePlaylistThumbnail (playlistObject: PlaylistObject, playlist
await playlist.replaceAndSaveThumbnails(thumbnails, t)
})
} catch (err) {
- logger.debug(`Failed to update thumbnail for playlist ${playlist.url} with icon ${icons[0].url}, maybe because of concurrent request`, {
- err,
- ...lTags(playlist.uuid, playlist.url)
- })
+ logger.debug(
+ `Failed to update thumbnail for playlist ${playlist.url} with icon ${icons[0].url}, maybe because of concurrent request`,
+ { err }
+ )
}
}
@@ -179,7 +180,7 @@ async function rebuildVideoPlaylistElements (elementUrls: string[], playlist: MV
})
)
- logger.info('Rebuilt playlist %s with %s elements.', playlist.url, elementsToCreate.length, lTags(playlist.uuid, playlist.url))
+ logger.info('Rebuilt playlist %s with %s elements.', playlist.url, elementsToCreate.length)
return elementsToCreate.length
}
@@ -199,7 +200,7 @@ async function buildElementsDBAttributes (elementUrls: string[], playlist: MVide
? 'debug'
: 'warn'
- logger.log(logLevel, `Cannot add playlist element ${elementUrl}`, { err, ...lTags(playlist.uuid, playlist.url) })
+ logger.log(logLevel, `Cannot add playlist element ${elementUrl}`, { err })
}
}, { concurrency: CRAWL_REQUEST_CONCURRENCY })
diff --git a/server/core/lib/activitypub/playlists/get.ts b/server/core/lib/activitypub/playlists/get.ts
index eb7567c297..6f8105278b 100644
--- a/server/core/lib/activitypub/playlists/get.ts
+++ b/server/core/lib/activitypub/playlists/get.ts
@@ -1,3 +1,4 @@
+import { createLogger } from '@server/helpers/logger.js'
import { VideoPlaylistModel } from '@server/models/video/video-playlist.js'
import { MVideoPlaylistFullSummary } from '@server/types/models/index.js'
import { getAPId } from '../activity.js'
@@ -5,22 +6,26 @@ import { createOrUpdateVideoPlaylist } from './create-update.js'
import { schedulePlaylistRefreshIfNeeded } from './refresh.js'
import { fetchRemoteVideoPlaylist } from './shared/index.js'
-export async function getOrCreateAPVideoPlaylist (playlistUrl: string): Promise<MVideoPlaylistFullSummary> {
- const playlistFromDatabase = await VideoPlaylistModel.loadByUrlWithAccountAndChannelSummary(playlistUrl)
+const logger = createLogger('ap', 'playlist')
- if (playlistFromDatabase) {
- schedulePlaylistRefreshIfNeeded(playlistFromDatabase)
+export function getOrCreateAPVideoPlaylist (playlistUrl: string): Promise<MVideoPlaylistFullSummary> {
+ return logger.withContext([ playlistUrl ], async () => {
+ const playlistFromDatabase = await VideoPlaylistModel.loadByUrlWithAccountAndChannelSummary(playlistUrl)
- return playlistFromDatabase
- }
+ if (playlistFromDatabase) {
+ schedulePlaylistRefreshIfNeeded(playlistFromDatabase)
- const { playlistObject } = await fetchRemoteVideoPlaylist(playlistUrl)
- if (!playlistObject) throw new Error('Cannot fetch remote playlist with url: ' + playlistUrl)
+ return playlistFromDatabase
+ }
- // playlistUrl is just an alias/redirection, so process object id instead
- if (playlistObject.id !== playlistUrl) return getOrCreateAPVideoPlaylist(getAPId(playlistObject))
+ const { playlistObject } = await fetchRemoteVideoPlaylist(playlistUrl)
+ if (!playlistObject) throw new Error('Cannot fetch remote playlist with url: ' + playlistUrl)
- const playlistCreated = await createOrUpdateVideoPlaylist({ playlistObject, contextUrl: playlistUrl })
+ // playlistUrl is just an alias/redirection, so process object id instead
+ if (playlistObject.id !== playlistUrl) return getOrCreateAPVideoPlaylist(getAPId(playlistObject))
- return playlistCreated
+ const playlistCreated = await createOrUpdateVideoPlaylist({ playlistObject, contextUrl: playlistUrl })
+
+ return playlistCreated
+ })
}
diff --git a/server/core/lib/activitypub/playlists/refresh.ts b/server/core/lib/activitypub/playlists/refresh.ts
index 0ca9515ecd..b1ffe2289c 100644
--- a/server/core/lib/activitypub/playlists/refresh.ts
+++ b/server/core/lib/activitypub/playlists/refresh.ts
@@ -1,12 +1,14 @@
import { HttpStatusCode } from '@peertube/peertube-models'
-import { logger, loggerTagsFactory } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { PeerTubeRequestError } from '@server/helpers/requests.js'
import { JobQueue } from '@server/lib/job-queue/index.js'
import { MVideoPlaylist, MVideoPlaylistOwnerDefault } from '@server/types/models/index.js'
import { createOrUpdateVideoPlaylist } from './create-update.js'
import { fetchRemoteVideoPlaylist } from './shared/index.js'
-function schedulePlaylistRefreshIfNeeded (playlist: MVideoPlaylist) {
+const logger = createLogger('ap', 'playlist', 'refresh')
+
+export function schedulePlaylistRefreshIfNeeded (playlist: MVideoPlaylist) {
if (!playlist.isOutdated()) return
JobQueue.Instance.createJobAsync({
@@ -16,48 +18,44 @@ function schedulePlaylistRefreshIfNeeded (playlist: MVideoPlaylist) {
})
}
-async function refreshVideoPlaylistIfNeeded (videoPlaylist: MVideoPlaylistOwnerDefault): Promise<MVideoPlaylistOwnerDefault> {
- const lTags = loggerTagsFactory('ap', 'video-playlist', 'refresh', videoPlaylist.uuid, videoPlaylist.url)
+export async function refreshVideoPlaylistIfNeeded (videoPlaylist: MVideoPlaylistOwnerDefault): Promise<MVideoPlaylistOwnerDefault> {
+ return logger.withContext([ videoPlaylist.uuid, videoPlaylist.url ], async () => {
+ if (!videoPlaylist.isOutdated()) {
+ logger.debug('Playlist ' + videoPlaylist.url + ' is not outdated, no need to refresh it.')
- if (!videoPlaylist.isOutdated()) {
- logger.debug('Playlist ' + videoPlaylist.url + ' is not outdated, no need to refresh it.', lTags())
+ return videoPlaylist
+ }
- return videoPlaylist
- }
+ // Inner functions (fetchRemoteVideoPlaylist...) inherit these tags without having to inject them
+ logger.info('Refreshing playlist %s.', videoPlaylist.url)
- logger.info('Refreshing playlist %s.', videoPlaylist.url, lTags())
+ try {
+ const { playlistObject } = await fetchRemoteVideoPlaylist(videoPlaylist.url)
- try {
- const { playlistObject } = await fetchRemoteVideoPlaylist(videoPlaylist.url)
+ if (playlistObject === undefined) {
+ logger.warn('Cannot refresh remote playlist %s: invalid body.', videoPlaylist.url)
- if (playlistObject === undefined) {
- logger.warn('Cannot refresh remote playlist %s: invalid body.', videoPlaylist.url, lTags())
+ await videoPlaylist.setAsRefreshed()
+ return videoPlaylist
+ }
+
+ await createOrUpdateVideoPlaylist({ playlistObject, contextUrl: videoPlaylist.url })
- await videoPlaylist.setAsRefreshed()
return videoPlaylist
- }
+ } catch (err) {
+ const statusCode = (err as PeerTubeRequestError).statusCode
- await createOrUpdateVideoPlaylist({ playlistObject, contextUrl: videoPlaylist.url })
+ if (statusCode === HttpStatusCode.NOT_FOUND_404 || statusCode === HttpStatusCode.GONE_410) {
+ logger.info('Cannot refresh not existing playlist (404/410 error code) %s. Deleting it.', videoPlaylist.url)
- return videoPlaylist
- } catch (err) {
- const statusCode = (err as PeerTubeRequestError).statusCode
+ await videoPlaylist.destroy()
+ return undefined
+ }
- if (statusCode === HttpStatusCode.NOT_FOUND_404 || statusCode === HttpStatusCode.GONE_410) {
- logger.info('Cannot refresh not existing playlist (404/410 error code) %s. Deleting it.', videoPlaylist.url, lTags())
+ logger.warn('Cannot refresh video playlist %s.', videoPlaylist.url, { err })
- await videoPlaylist.destroy()
- return undefined
+ await videoPlaylist.setAsRefreshed()
+ return videoPlaylist
}
-
- logger.warn('Cannot refresh video playlist %s.', videoPlaylist.url, { err, ...lTags() })
-
- await videoPlaylist.setAsRefreshed()
- return videoPlaylist
- }
-}
-
-export {
- refreshVideoPlaylistIfNeeded,
- schedulePlaylistRefreshIfNeeded
+ })
}
diff --git a/server/core/lib/activitypub/playlists/shared/url-to-object.ts b/server/core/lib/activitypub/playlists/shared/url-to-object.ts
index 3e6adbcb0e..bae67b49db 100644
--- a/server/core/lib/activitypub/playlists/shared/url-to-object.ts
+++ b/server/core/lib/activitypub/playlists/shared/url-to-object.ts
@@ -1,34 +1,34 @@
+import { PlaylistElementObject, PlaylistObject } from '@peertube/peertube-models'
import { isPlaylistElementObjectValid, isPlaylistObjectValid } from '@server/helpers/custom-validators/activitypub/playlist.js'
import { isArray } from '@server/helpers/custom-validators/misc.js'
-import { logger, loggerTagsFactory } from '@server/helpers/logger.js'
-import { PlaylistElementObject, PlaylistObject } from '@peertube/peertube-models'
+import { createLogger } from '@server/helpers/logger.js'
import { fetchAP } from '../../activity.js'
import { checkUrlsSameHost } from '../../url.js'
-async function fetchRemoteVideoPlaylist (playlistUrl: string): Promise<{ statusCode: number, playlistObject: PlaylistObject }> {
- const lTags = loggerTagsFactory('ap', 'video-playlist', playlistUrl)
+const logger = createLogger('ap', 'playlist')
- logger.info('Fetching remote playlist %s.', playlistUrl, lTags())
+export async function fetchRemoteVideoPlaylist (playlistUrl: string): Promise<{ statusCode: number, playlistObject: PlaylistObject }> {
+ logger.info('Fetching remote playlist %s.', playlistUrl)
const { body, statusCode } = await fetchAP<any>(playlistUrl)
if (isPlaylistObjectValid(body) === false || checkUrlsSameHost(body.id, playlistUrl) !== true) {
- logger.debug('Remote video playlist JSON is not valid.', { body, ...lTags() })
+ logger.debug('Remote video playlist JSON is not valid.', { body })
return { statusCode, playlistObject: undefined }
}
if (!isArray(body.to)) {
- logger.debug('Remote video playlist JSON does not have a valid audience.', { body, ...lTags() })
+ logger.debug('Remote video playlist JSON does not have a valid audience.', { body })
return { statusCode, playlistObject: undefined }
}
return { statusCode, playlistObject: body }
}
-async function fetchRemotePlaylistElement (elementUrl: string): Promise<{ statusCode: number, elementObject: PlaylistElementObject }> {
- const lTags = loggerTagsFactory('ap', 'video-playlist', 'element', elementUrl)
-
- logger.debug('Fetching remote playlist element %s.', elementUrl, lTags())
+export async function fetchRemotePlaylistElement (
+ elementUrl: string
+): Promise<{ statusCode: number, elementObject: PlaylistElementObject }> {
+ logger.debug('Fetching remote playlist element %s.', elementUrl)
const { body, statusCode } = await fetchAP<PlaylistElementObject>(elementUrl)
@@ -40,8 +40,3 @@ async function fetchRemotePlaylistElement (elementUrl: string): Promise<{ status
return { statusCode, elementObject: body }
}
-
-export {
- fetchRemoteVideoPlaylist,
- fetchRemotePlaylistElement
-}
diff --git a/server/core/lib/activitypub/process/process-announce.ts b/server/core/lib/activitypub/process/process-announce.ts
index e777d05388..231b3ca07a 100644
--- a/server/core/lib/activitypub/process/process-announce.ts
+++ b/server/core/lib/activitypub/process/process-announce.ts
@@ -1,7 +1,7 @@
import { ActivityAnnounce } from '@peertube/peertube-models'
import { getAPId } from '@server/lib/activitypub/activity.js'
import { retryTransactionWrapper } from '../../../helpers/database-utils.js'
-import { logger } from '../../../helpers/logger.js'
+import { createLogger } from '../../../helpers/logger.js'
import { sequelizeTypescript } from '../../../initializers/database.js'
import { VideoShareModel } from '../../../models/video/video-share.js'
import { APProcessorOptions } from '../../../types/activitypub-processor.model.js'
@@ -11,6 +11,8 @@ import { forwardVideoRelatedActivity } from '../send/shared/send-utils.js'
import { checkUrlsSameHost } from '../url.js'
import { maybeGetOrCreateAPVideo } from '../videos/index.js'
+const logger = createLogger()
+
async function processAnnounceActivity (options: APProcessorOptions<ActivityAnnounce>) {
const { activity, byActor: actorAnnouncer } = options
// Only notify if it is not from a fetcher job
diff --git a/server/core/lib/activitypub/process/process-create.ts b/server/core/lib/activitypub/process/process-create.ts
index 079ef97213..39a90ecff0 100644
--- a/server/core/lib/activitypub/process/process-create.ts
+++ b/server/core/lib/activitypub/process/process-create.ts
@@ -16,7 +16,7 @@ import { isRedundancyAccepted } from '@server/lib/redundancy.js'
import { VideoCommentModel } from '@server/models/video/video-comment.js'
import { VideoModel } from '@server/models/video/video.js'
import { retryTransactionWrapper } from '../../../helpers/database-utils.js'
-import { logger } from '../../../helpers/logger.js'
+import { createLogger } from '../../../helpers/logger.js'
import { sequelizeTypescript } from '../../../initializers/database.js'
import { APProcessorOptions } from '../../../types/activitypub-processor.model.js'
import { MActorSignature, MCommentOwnerVideo, MVideoAccountLightBlacklistAllFiles } from '../../../types/models/index.js'
@@ -31,6 +31,8 @@ import { checkUrlsSameHost, getLocalApproveReplyActivityPubUrl } from '../url.js
import { resolveThread } from '../video-comments.js'
import { canVideoBeFederated, getOrCreateAPVideo } from '../videos/index.js'
+const logger = createLogger()
+
async function processCreateActivity (options: APProcessorOptions<ActivityCreate<ActivityCreateObject>>) {
const { activity, byActor } = options
diff --git a/server/core/lib/activitypub/process/process-delete.ts b/server/core/lib/activitypub/process/process-delete.ts
index 945554670f..e913b7ed78 100644
--- a/server/core/lib/activitypub/process/process-delete.ts
+++ b/server/core/lib/activitypub/process/process-delete.ts
@@ -1,7 +1,7 @@
import { ActivityDelete } from '@peertube/peertube-models'
import { isAccountActor, isChannelActor } from '@server/helpers/actors.js'
import { retryTransactionWrapper } from '../../../helpers/database-utils.js'
-import { logger } from '../../../helpers/logger.js'
+import { createLogger } from '../../../helpers/logger.js'
import { sequelizeTypescript } from '../../../initializers/database.js'
import { ActorModel } from '../../../models/actor/actor.js'
import { VideoCommentModel } from '../../../models/video/video-comment.js'
@@ -21,6 +21,8 @@ import {
} from '../../../types/models/index.js'
import { forwardVideoRelatedActivity } from '../send/shared/send-utils.js'
+const logger = createLogger()
+
async function processDeleteActivity (options: APProcessorOptions<ActivityDelete>) {
const { activity, byActor } = options
diff --git a/server/core/lib/activitypub/process/process-dislike.ts b/server/core/lib/activitypub/process/process-dislike.ts
index e356c7431e..7835dae86e 100644
--- a/server/core/lib/activitypub/process/process-dislike.ts
+++ b/server/core/lib/activitypub/process/process-dislike.ts
@@ -1,5 +1,5 @@
import { ActivityDislike } from '@peertube/peertube-models'
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { VideoModel } from '@server/models/video/video.js'
import { retryTransactionWrapper } from '../../../helpers/database-utils.js'
import { sequelizeTypescript } from '../../../initializers/database.js'
@@ -8,6 +8,8 @@ import { APProcessorOptions } from '../../../types/activitypub-processor.model.j
import { MActorSignature } from '../../../types/models/index.js'
import { canVideoBeFederated, maybeGetOrCreateAPVideo, scheduleVideoFederation } from '../videos/index.js'
+const logger = createLogger()
+
async function processDislikeActivity (options: APProcessorOptions<ActivityDislike>) {
const { activity, byActor } = options
diff --git a/server/core/lib/activitypub/process/process-download.ts b/server/core/lib/activitypub/process/process-download.ts
index efb587a19c..b0de614139 100644
--- a/server/core/lib/activitypub/process/process-download.ts
+++ b/server/core/lib/activitypub/process/process-download.ts
@@ -1,12 +1,12 @@
import { ActivityDownload } from '@peertube/peertube-models'
-import { logger, loggerTagsFactory } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { VideoStatsManager } from '@server/lib/stats/video-stats-manager.js'
import { APProcessorOptions } from '../../../types/activitypub-processor.model.js'
import { MActorSignature } from '../../../types/models/index.js'
import { checkUrlsSameHost } from '../url.js'
import { getOrCreateAPVideo } from '../videos/index.js'
-const lTags = loggerTagsFactory('ap', 'download')
+const logger = createLogger('ap', 'download')
async function processDownloadActivity (options: APProcessorOptions<ActivityDownload>) {
const { activity, byActor } = options
@@ -34,7 +34,7 @@ async function processCreateDownload (activity: ActivityDownload, byActor: MActo
// An instance can tell us one of its users downloaded one of our videos
// But for a remote video, only its origin instance broadcasts download activities
if (!video.isLocal() && !checkUrlsSameHost(byActor.url, video.url)) {
- logger.warn('Ignoring download activity %s of %s that does not come from the origin instance.', activity.id, video.url, lTags())
+ logger.warn('Ignoring download activity %s of %s that does not come from the origin instance.', activity.id, video.url)
return
}
diff --git a/server/core/lib/activitypub/process/process-flag.ts b/server/core/lib/activitypub/process/process-flag.ts
index c5ecef059f..ef0cffcf79 100644
--- a/server/core/lib/activitypub/process/process-flag.ts
+++ b/server/core/lib/activitypub/process/process-flag.ts
@@ -5,12 +5,14 @@ import { AccountModel } from '@server/models/account/account.js'
import { VideoCommentModel } from '@server/models/video/video-comment.js'
import { VideoModel } from '@server/models/video/video.js'
import { retryTransactionWrapper } from '../../../helpers/database-utils.js'
-import { logger } from '../../../helpers/logger.js'
+import { createLogger } from '../../../helpers/logger.js'
import { sequelizeTypescript } from '../../../initializers/database.js'
import { getAPId } from '../../../lib/activitypub/activity.js'
import { APProcessorOptions } from '../../../types/activitypub-processor.model.js'
import { MAccountDefault, MActorSignature, MCommentOwnerVideo } from '../../../types/models/index.js'
+const logger = createLogger()
+
async function processFlagActivity (options: APProcessorOptions<ActivityFlag>) {
const { activity, byActor } = options
diff --git a/server/core/lib/activitypub/process/process-follow.ts b/server/core/lib/activitypub/process/process-follow.ts
index a9f7081e22..cf83058098 100644
--- a/server/core/lib/activitypub/process/process-follow.ts
+++ b/server/core/lib/activitypub/process/process-follow.ts
@@ -4,7 +4,7 @@ import { AccountModel } from '@server/models/account/account.js'
import { getServerActor } from '@server/models/application/application.js'
import { Transaction } from 'sequelize'
import { retryTransactionWrapper } from '../../../helpers/database-utils.js'
-import { logger } from '../../../helpers/logger.js'
+import { createLogger } from '../../../helpers/logger.js'
import { CONFIG } from '../../../initializers/config.js'
import { sequelizeTypescript } from '../../../initializers/database.js'
import { getAPId } from '../../../lib/activitypub/activity.js'
@@ -16,6 +16,8 @@ import { Notifier } from '../../notifier/index.js'
import { autoFollowBackIfNeeded } from '../follow.js'
import { sendAccept, sendReject } from '../send/index.js'
+const logger = createLogger()
+
async function processFollowActivity (options: APProcessorOptions<ActivityFollow>) {
const { activity, byActor } = options
diff --git a/server/core/lib/activitypub/process/process-like.ts b/server/core/lib/activitypub/process/process-like.ts
index 400119bcb0..59e83b8e03 100644
--- a/server/core/lib/activitypub/process/process-like.ts
+++ b/server/core/lib/activitypub/process/process-like.ts
@@ -1,5 +1,5 @@
import { ActivityLike } from '@peertube/peertube-models'
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { VideoModel } from '@server/models/video/video.js'
import { retryTransactionWrapper } from '../../../helpers/database-utils.js'
import { sequelizeTypescript } from '../../../initializers/database.js'
@@ -9,6 +9,8 @@ import { APProcessorOptions } from '../../../types/activitypub-processor.model.j
import { MActorSignature } from '../../../types/models/index.js'
import { canVideoBeFederated, maybeGetOrCreateAPVideo, scheduleVideoFederation } from '../videos/index.js'
+const logger = createLogger()
+
async function processLikeActivity (options: APProcessorOptions<ActivityLike>) {
const { activity, byActor } = options
diff --git a/server/core/lib/activitypub/process/process-undo.ts b/server/core/lib/activitypub/process/process-undo.ts
index 836250028e..0a862d587a 100644
--- a/server/core/lib/activitypub/process/process-undo.ts
+++ b/server/core/lib/activitypub/process/process-undo.ts
@@ -10,7 +10,7 @@ import {
} from '@peertube/peertube-models'
import { VideoModel } from '@server/models/video/video.js'
import { retryTransactionWrapper } from '../../../helpers/database-utils.js'
-import { logger } from '../../../helpers/logger.js'
+import { createLogger } from '../../../helpers/logger.js'
import { sequelizeTypescript } from '../../../initializers/database.js'
import { AccountVideoRateModel } from '../../../models/account/account-video-rate.js'
import { ActorFollowModel } from '../../../models/actor/actor-follow.js'
@@ -23,6 +23,8 @@ import { fetchAPObjectIfNeeded } from '../activity.js'
import { forwardVideoRelatedActivity } from '../send/shared/send-utils.js'
import { getOrCreateAPVideo, maybeGetOrCreateAPVideo, scheduleVideoFederation } from '../videos/index.js'
+const logger = createLogger()
+
async function processUndoActivity (options: APProcessorOptions<ActivityUndo<ActivityUndoObject>>) {
const { activity, byActor } = options
const activityToUndo = activity.object
diff --git a/server/core/lib/activitypub/process/process-update.ts b/server/core/lib/activitypub/process/process-update.ts
index 88c7992e2a..5a6422af5d 100644
--- a/server/core/lib/activitypub/process/process-update.ts
+++ b/server/core/lib/activitypub/process/process-update.ts
@@ -13,7 +13,7 @@ import { isRedundancyAccepted } from '@server/lib/redundancy.js'
import { isCacheFileObjectValid } from '../../../helpers/custom-validators/activitypub/cache-file.js'
import { sanitizeAndCheckVideoTorrentObject } from '../../../helpers/custom-validators/activitypub/videos.js'
import { retryTransactionWrapper } from '../../../helpers/database-utils.js'
-import { logger } from '../../../helpers/logger.js'
+import { createLogger } from '../../../helpers/logger.js'
import { sequelizeTypescript } from '../../../initializers/database.js'
import { ActorModel } from '../../../models/actor/actor.js'
import { APProcessorOptions } from '../../../types/activitypub-processor.model.js'
@@ -28,6 +28,8 @@ import { forwardVideoRelatedActivity } from '../send/shared/send-utils.js'
import { checkUrlsSameHost, isLocalUrl } from '../url.js'
import { APVideoUpdater, canVideoBeFederated, getOrCreateAPVideo, maybeGetOrCreateAPVideo } from '../videos/index.js'
+const logger = createLogger()
+
async function processUpdateActivity (options: APProcessorOptions<ActivityUpdate<ActivityUpdateObject>>) {
const { activity, byActor } = options
diff --git a/server/core/lib/activitypub/process/process-view.ts b/server/core/lib/activitypub/process/process-view.ts
index 3553603aec..b5f8946c95 100644
--- a/server/core/lib/activitypub/process/process-view.ts
+++ b/server/core/lib/activitypub/process/process-view.ts
@@ -1,5 +1,5 @@
import { ActivityView } from '@peertube/peertube-models'
-import { logger, loggerTagsFactory } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { MAX_REMOTE_VIEWERS_COUNTER } from '@server/initializers/constants.js'
import { VideoStatsManager } from '@server/lib/stats/video-stats-manager.js'
import { APProcessorOptions } from '../../../types/activitypub-processor.model.js'
@@ -8,7 +8,7 @@ import { forwardVideoRelatedActivity } from '../send/shared/send-utils.js'
import { checkUrlsSameHost } from '../url.js'
import { getOrCreateAPVideo } from '../videos/index.js'
-const lTags = loggerTagsFactory('ap', 'view')
+const logger = createLogger('ap', 'view')
async function processViewActivity (options: APProcessorOptions<ActivityView>) {
const { activity, byActor } = options
@@ -29,7 +29,7 @@ async function processCreateView (activity: ActivityView, byActor: MActorSignatu
// The view URL is built from the actor URL, so don't accept a view of another host
if (checkUrlsSameHost(activity.id, byActor.url) !== true) {
- logger.warn('Ignoring view %s that has not the same host than actor %s.', activity.id, byActor.url, lTags())
+ logger.warn('Ignoring view %s that has not the same host than actor %s.', activity.id, byActor.url)
return
}
diff --git a/server/core/lib/activitypub/process/process.ts b/server/core/lib/activitypub/process/process.ts
index 115345116a..2ecc747e16 100644
--- a/server/core/lib/activitypub/process/process.ts
+++ b/server/core/lib/activitypub/process/process.ts
@@ -1,6 +1,6 @@
import { Activity, ActivityType } from '@peertube/peertube-models'
import { StatsManager } from '@server/lib/stat-manager.js'
-import { logger } from '../../../helpers/logger.js'
+import { createLogger } from '../../../helpers/logger.js'
import { APProcessorOptions } from '../../../types/activitypub-processor.model.js'
import { MActorDefault, MActorSignature } from '../../../types/models/index.js'
import { getAPId } from '../activity.js'
@@ -21,6 +21,8 @@ import { processUpdateActivity } from './process-update.js'
import { processViewActivity } from './process-view.js'
import { processDownloadActivity } from './process-download.js'
+const logger = createLogger()
+
const processActivity: { [ P in ActivityType ]: (options: APProcessorOptions<Activity>) => Promise<any> } = {
Create: processCreateActivity,
Update: processUpdateActivity,
diff --git a/server/core/lib/activitypub/send/http.ts b/server/core/lib/activitypub/send/http.ts
index 492ffa6208..f9b8ee8907 100644
--- a/server/core/lib/activitypub/send/http.ts
+++ b/server/core/lib/activitypub/send/http.ts
@@ -1,6 +1,6 @@
import { ContextType } from '@peertube/peertube-models'
import { signAndContextify } from '@server/helpers/activity-pub-utils.js'
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { ACTIVITY_PUB, HTTP_SIGNATURE } from '@server/initializers/constants.js'
import { buildDigestFromWorker, signJsonLDObjectFromWorker } from '@server/lib/worker/parent-process.js'
import { ActorReservedModel } from '@server/models/actor/actor-reserved.js'
@@ -8,6 +8,8 @@ import { ActorModel } from '@server/models/actor/actor.js'
import { getServerActor } from '@server/models/application/application.js'
import { getContextFilter } from '../context.js'
+const logger = createLogger()
+
type Payload<T> = { body: T, contextType: ContextType, signatureActorId?: number }
export async function computeBody<T> (
diff --git a/server/core/lib/activitypub/send/send-accept.ts b/server/core/lib/activitypub/send/send-accept.ts
index 8486564b8e..d6f8738d63 100644
--- a/server/core/lib/activitypub/send/send-accept.ts
+++ b/server/core/lib/activitypub/send/send-accept.ts
@@ -1,10 +1,12 @@
import { ActivityAccept, ActivityFollow } from '@peertube/peertube-models'
-import { logger } from '../../../helpers/logger.js'
+import { createLogger } from '../../../helpers/logger.js'
import { MActor, MActorFollowActors } from '../../../types/models/index.js'
import { getLocalActorFollowAcceptActivityPubUrl } from '../url.js'
import { buildFollowActivity } from './send-follow.js'
import { unicastTo } from './shared/send-utils.js'
+const logger = createLogger()
+
function sendAccept (actorFollow: MActorFollowActors) {
const follower = actorFollow.ActorFollower
const me = actorFollow.ActorFollowing
diff --git a/server/core/lib/activitypub/send/send-announce.ts b/server/core/lib/activitypub/send/send-announce.ts
index 44ddd6fead..5dfef46afa 100644
--- a/server/core/lib/activitypub/send/send-announce.ts
+++ b/server/core/lib/activitypub/send/send-announce.ts
@@ -1,11 +1,13 @@
import { ActivityAnnounce, ActivityAudience } from '@peertube/peertube-models'
import { Transaction } from 'sequelize'
-import { logger } from '../../../helpers/logger.js'
+import { createLogger } from '../../../helpers/logger.js'
import { MActorLight, MVideo } from '../../../types/models/index.js'
import { MVideoShare } from '../../../types/models/video/index.js'
import { audiencify, getPublicAudience } from '../audience.js'
import { broadcastToFollowers, getActorsInvolvedInVideo } from './shared/send-utils.js'
+const logger = createLogger()
+
export async function sendVideoAnnounce (options: {
byActor: MActorLight
videoShare: MVideoShare
diff --git a/server/core/lib/activitypub/send/send-create.ts b/server/core/lib/activitypub/send/send-create.ts
index a3400b0082..3d02ca7c2b 100644
--- a/server/core/lib/activitypub/send/send-create.ts
+++ b/server/core/lib/activitypub/send/send-create.ts
@@ -10,7 +10,7 @@ import { AccountModel } from '@server/models/account/account.js'
import { getServerActor } from '@server/models/application/application.js'
import { VideoModel } from '@server/models/video/video.js'
import { Transaction } from 'sequelize'
-import { logger, loggerTagsFactory } from '../../../helpers/logger.js'
+import { createLogger } from '../../../helpers/logger.js'
import { VideoCommentModel } from '../../../models/video/video-comment.js'
import {
MActorLight,
@@ -32,157 +32,167 @@ import {
unicastTo
} from './shared/send-utils.js'
-const lTags = loggerTagsFactory('ap', 'create')
+const logger = createLogger('ap', 'create')
-export async function sendCreateVideo (video: MVideoAP, transaction: Transaction) {
+export function sendCreateVideo (video: MVideoAP, transaction: Transaction) {
if (!canVideoBeFederated(video)) return undefined
- logger.info('Creating job to send video creation of %s.', video.url, lTags(video.uuid))
+ return logger.withContext([ video.uuid ], async () => {
+ logger.info('Creating job to send video creation of %s.', video.url)
- const byActor = video.VideoChannel.Account.Actor
- const videoObject = await video.toActivityPubObject()
+ const byActor = video.VideoChannel.Account.Actor
+ const videoObject = await video.toActivityPubObject()
- const audience = getVideoAudience({ account: video.VideoChannel.Account, channel: video.VideoChannel, privacy: video.privacy })
- const createActivity = buildCreateActivity(video.url, byActor, videoObject, audience)
+ const audience = getVideoAudience({ account: video.VideoChannel.Account, channel: video.VideoChannel, privacy: video.privacy })
+ const createActivity = buildCreateActivity(video.url, byActor, videoObject, audience)
- return broadcastToFollowers({
- data: createActivity,
- byActor,
- toFollowersOf: [ byActor ],
- transaction,
- contextType: 'Video'
+ return broadcastToFollowers({
+ data: createActivity,
+ byActor,
+ toFollowersOf: [ byActor ],
+ transaction,
+ contextType: 'Video'
+ })
})
}
-export async function sendCreateCacheFile (
+export function sendCreateCacheFile (
byActor: MActorLight,
video: MVideoAccountLight,
fileRedundancy: MVideoRedundancyStreamingPlaylistVideo
) {
- logger.info('Creating job to send file cache of %s.', fileRedundancy.url, lTags(video.uuid))
-
- return sendVideoRelatedCreateActivity({
- byActor,
- video,
- url: fileRedundancy.url,
- object: fileRedundancy.toActivityPubObject(),
- contextType: 'CacheFile'
+ return logger.withContext([ video.uuid ], async () => {
+ logger.info('Creating job to send file cache of %s.', fileRedundancy.url)
+
+ return sendVideoRelatedCreateActivity({
+ byActor,
+ video,
+ url: fileRedundancy.url,
+ object: fileRedundancy.toActivityPubObject(),
+ contextType: 'CacheFile'
+ })
})
}
-export async function sendCreateWatchAction (stats: MLocalVideoViewerWithWatchSections, transaction: Transaction) {
- logger.info('Creating job to send create watch action %s.', stats.url, lTags(stats.uuid))
+export function sendCreateWatchAction (stats: MLocalVideoViewerWithWatchSections, transaction: Transaction) {
+ return logger.withContext([ stats.uuid ], async () => {
+ logger.info('Creating job to send create watch action %s.', stats.url)
- const byActor = await getServerActor()
+ const byActor = await getServerActor()
- const activityBuilder = (audience: ActivityAudience) => {
- return buildCreateActivity(stats.url, byActor, stats.toActivityPubObject(), audience)
- }
+ const activityBuilder = (audience: ActivityAudience) => {
+ return buildCreateActivity(stats.url, byActor, stats.toActivityPubObject(), audience)
+ }
- return sendVideoRelatedActivityToOrigin(activityBuilder, { byActor, video: stats.Video, transaction, contextType: 'WatchAction' })
+ return sendVideoRelatedActivityToOrigin(activityBuilder, { byActor, video: stats.Video, transaction, contextType: 'WatchAction' })
+ })
}
-export async function sendCreateVideoPlaylist (playlist: MVideoPlaylistFull, transaction: Transaction) {
+export function sendCreateVideoPlaylist (playlist: MVideoPlaylistFull, transaction: Transaction) {
if (playlist.privacy === VideoPlaylistPrivacy.PRIVATE) return undefined
- logger.info('Creating job to send create video playlist of %s.', playlist.url, lTags(playlist.uuid))
+ return logger.withContext([ playlist.uuid ], async () => {
+ logger.info('Creating job to send create video playlist of %s.', playlist.url)
- const audience = getPlaylistAudience({ account: playlist.OwnerAccount, channel: playlist.VideoChannel, privacy: playlist.privacy })
+ const audience = getPlaylistAudience({ account: playlist.OwnerAccount, channel: playlist.VideoChannel, privacy: playlist.privacy })
- const object = await playlist.toActivityPubObject(null, transaction)
+ const object = await playlist.toActivityPubObject(null, transaction)
- const byActor = playlist.OwnerAccount.Actor
- const createActivity = buildCreateActivity(playlist.url, byActor, object, audience)
+ const byActor = playlist.OwnerAccount.Actor
+ const createActivity = buildCreateActivity(playlist.url, byActor, object, audience)
- const serverActor = await getServerActor()
- const toFollowersOf = [ byActor, serverActor ]
+ const serverActor = await getServerActor()
+ const toFollowersOf = [ byActor, serverActor ]
- if (playlist.VideoChannel) toFollowersOf.push(playlist.VideoChannel.Actor)
+ if (playlist.VideoChannel) toFollowersOf.push(playlist.VideoChannel.Actor)
- return broadcastToFollowers({
- data: createActivity,
- byActor,
- toFollowersOf,
- transaction,
- contextType: 'Playlist'
+ return broadcastToFollowers({
+ data: createActivity,
+ byActor,
+ toFollowersOf,
+ transaction,
+ contextType: 'Playlist'
+ })
})
}
export async function sendCreateVideoCommentIfNeeded (comment: MCommentOwnerVideoReply, transaction: Transaction) {
- if (comment.Video.isLocal()) {
- const videoWithBlacklist = await VideoModel.loadWithBlacklist(comment.Video.id)
-
- if (!canVideoBeFederated(videoWithBlacklist)) {
- logger.debug(`Do not send comment ${comment.url} on a video that cannot be federated`)
- return undefined
- }
-
- if (comment.heldForReview) {
- logger.debug(`Do not send comment ${comment.url} that requires approval`)
- return undefined
+ return logger.withContext([ comment.url ], async () => {
+ if (comment.Video.isLocal()) {
+ const videoWithBlacklist = await VideoModel.loadWithBlacklist(comment.Video.id)
+
+ if (!canVideoBeFederated(videoWithBlacklist)) {
+ logger.debug(`Do not send comment ${comment.url} on a video that cannot be federated`)
+ return undefined
+ }
+
+ if (comment.heldForReview) {
+ logger.debug(`Do not send comment ${comment.url} that requires approval`)
+ return undefined
+ }
}
- }
- logger.info('Creating job to send comment %s.', comment.url)
+ logger.info('Creating job to send comment %s.', comment.url)
- const byActor = comment.Account.Actor
- const videoAccount = await AccountModel.load(comment.Video.VideoChannel.Account.id, transaction)
+ const byActor = comment.Account.Actor
+ const videoAccount = await AccountModel.load(comment.Video.VideoChannel.Account.id, transaction)
- const threadParentComments = await VideoCommentModel.listThreadParentComments({ comment, transaction })
- const commentObject = comment.toActivityPubObject(threadParentComments) as VideoCommentObject
+ const threadParentComments = await VideoCommentModel.listThreadParentComments({ comment, transaction })
+ const commentObject = comment.toActivityPubObject(threadParentComments) as VideoCommentObject
- const parentsCommentActors = threadParentComments.filter(c => !c.isDeleted() && !c.heldForReview)
- .map(c => c.Account.Actor)
-
- const video = await VideoModel.loadByUrlAndPopulateAccount(comment.Video.url, transaction)
- const audience = getCommentAudience({ comment, video, threadParentComments })
-
- const createActivity = buildCreateActivity(comment.url, byActor, commentObject, audience)
-
- // This was a reply, send it to the parent actors
- const actorsException = [ byActor ]
- await broadcastToActors({
- data: createActivity,
- byActor,
- toActors: parentsCommentActors,
- transaction,
- actorsException,
- contextType: 'Comment'
- })
+ const parentsCommentActors = threadParentComments.filter(c => !c.isDeleted() && !c.heldForReview)
+ .map(c => c.Account.Actor)
- // Broadcast to our followers
- await broadcastToFollowers({
- data: createActivity,
- byActor,
- toFollowersOf: [ byActor ],
- transaction,
- contextType: 'Comment'
- })
+ const video = await VideoModel.loadByUrlAndPopulateAccount(comment.Video.url, transaction)
+ const audience = getCommentAudience({ comment, video, threadParentComments })
- // Send to actors involved in the comment
- if (comment.Video.isLocal()) {
- const actorsInvolvedInComment = await getActorsInvolvedInVideo(comment.Video, transaction)
- // Add the actor that commented too
- actorsInvolvedInComment.push(byActor)
+ const createActivity = buildCreateActivity(comment.url, byActor, commentObject, audience)
- return broadcastToFollowers({
+ // This was a reply, send it to the parent actors
+ const actorsException = [ byActor ]
+ await broadcastToActors({
data: createActivity,
byActor,
- toFollowersOf: actorsInvolvedInComment,
+ toActors: parentsCommentActors,
transaction,
actorsException,
contextType: 'Comment'
})
- }
- // Send to origin
- return transaction.afterCommit(() => {
- return unicastTo({
+ // Broadcast to our followers
+ await broadcastToFollowers({
data: createActivity,
byActor,
- toActorUrl: videoAccount.Actor.getSharedInbox(),
+ toFollowersOf: [ byActor ],
+ transaction,
contextType: 'Comment'
})
+
+ // Send to actors involved in the comment
+ if (comment.Video.isLocal()) {
+ const actorsInvolvedInComment = await getActorsInvolvedInVideo(comment.Video, transaction)
+ // Add the actor that commented too
+ actorsInvolvedInComment.push(byActor)
+
+ return broadcastToFollowers({
+ data: createActivity,
+ byActor,
+ toFollowersOf: actorsInvolvedInComment,
+ transaction,
+ actorsException,
+ contextType: 'Comment'
+ })
+ }
+
+ // Send to origin
+ return transaction.afterCommit(() => {
+ return unicastTo({
+ data: createActivity,
+ byActor,
+ toActorUrl: videoAccount.Actor.getSharedInbox(),
+ contextType: 'Comment'
+ })
+ })
})
}
diff --git a/server/core/lib/activitypub/send/send-delete.ts b/server/core/lib/activitypub/send/send-delete.ts
index 043dd71b5b..981d50cbd8 100644
--- a/server/core/lib/activitypub/send/send-delete.ts
+++ b/server/core/lib/activitypub/send/send-delete.ts
@@ -3,7 +3,7 @@ import { AccountModel } from '@server/models/account/account.js'
import { getServerActor } from '@server/models/application/application.js'
import { VideoModel } from '@server/models/video/video.js'
import { Transaction } from 'sequelize'
-import { logger } from '../../../helpers/logger.js'
+import { createLogger } from '../../../helpers/logger.js'
import { ActorModel } from '../../../models/actor/actor.js'
import { VideoCommentModel } from '../../../models/video/video-comment.js'
import { VideoShareModel } from '../../../models/video/video-share.js'
@@ -19,6 +19,8 @@ import {
unicastTo
} from './shared/send-utils.js'
+const logger = createLogger()
+
async function sendDeleteVideo (options: {
video: MVideoAccountLight
transaction: Transaction
diff --git a/server/core/lib/activitypub/send/send-dislike.ts b/server/core/lib/activitypub/send/send-dislike.ts
index 081ab17cbf..dd2840e7be 100644
--- a/server/core/lib/activitypub/send/send-dislike.ts
+++ b/server/core/lib/activitypub/send/send-dislike.ts
@@ -1,11 +1,13 @@
import { Transaction } from 'sequelize'
import { ActivityAudience, ActivityDislike } from '@peertube/peertube-models'
-import { logger } from '../../../helpers/logger.js'
+import { createLogger } from '../../../helpers/logger.js'
import { MActor, MActorAudience, MVideoAccountLight, MVideoUrl } from '../../../types/models/index.js'
import { audiencify, getPublicAudience } from '../audience.js'
import { getVideoDislikeActivityPubUrlByLocalActor } from '../url.js'
import { sendVideoRelatedActivityToOrigin } from './shared/send-utils.js'
+const logger = createLogger()
+
function sendDislike (byActor: MActor, video: MVideoAccountLight, transaction: Transaction) {
logger.info('Creating job to dislike %s.', video.url)
diff --git a/server/core/lib/activitypub/send/send-download.ts b/server/core/lib/activitypub/send/send-download.ts
index 12e488fcae..7890e47610 100644
--- a/server/core/lib/activitypub/send/send-download.ts
+++ b/server/core/lib/activitypub/send/send-download.ts
@@ -2,12 +2,14 @@ import { ActivityAudience, ActivityDownload } from '@peertube/peertube-models'
import { VideoModel } from '@server/models/video/video.js'
import { MActorAudience, MActorLight, MVideoImmutable, MVideoUrl } from '@server/types/models/index.js'
import { Transaction } from 'sequelize'
-import { logger } from '../../../helpers/logger.js'
+import { createLogger } from '../../../helpers/logger.js'
import { audiencify, getPublicAudience } from '../audience.js'
import { getDownloadsActivityPubUrl } from '../url.js'
import { canVideoBeFederated } from '../videos/index.js'
import { sendVideoRelatedActivity } from './shared/send-utils.js'
+const logger = createLogger()
+
async function sendDownload (options: {
byActor: MActorLight
video: MVideoImmutable
diff --git a/server/core/lib/activitypub/send/send-flag.ts b/server/core/lib/activitypub/send/send-flag.ts
index 2776e56f5d..37c2e696f1 100644
--- a/server/core/lib/activitypub/send/send-flag.ts
+++ b/server/core/lib/activitypub/send/send-flag.ts
@@ -1,11 +1,13 @@
import { Transaction } from 'sequelize'
import { ActivityAudience, ActivityFlag } from '@peertube/peertube-models'
-import { logger } from '../../../helpers/logger.js'
+import { createLogger } from '../../../helpers/logger.js'
import { MAbuseAP, MAccountLight, MActor } from '../../../types/models/index.js'
import { audiencify, getPublicAudience } from '../audience.js'
import { getLocalAbuseActivityPubUrl } from '../url.js'
import { unicastTo } from './shared/send-utils.js'
+const logger = createLogger()
+
function sendAbuse (byActor: MActor, abuse: MAbuseAP, flaggedAccount: MAccountLight, t: Transaction) {
if (!flaggedAccount.Actor.serverId) return // Local user
diff --git a/server/core/lib/activitypub/send/send-follow.ts b/server/core/lib/activitypub/send/send-follow.ts
index 9e34ad94a3..926f7b5cd9 100644
--- a/server/core/lib/activitypub/send/send-follow.ts
+++ b/server/core/lib/activitypub/send/send-follow.ts
@@ -1,10 +1,12 @@
import { Transaction } from 'sequelize'
import { ActivityFollow } from '@peertube/peertube-models'
-import { logger } from '../../../helpers/logger.js'
+import { createLogger } from '../../../helpers/logger.js'
import { MActor, MActorFollowActors } from '../../../types/models/index.js'
import { unicastTo } from './shared/send-utils.js'
import { afterCommitIfTransaction } from '@server/helpers/database-utils.js'
+const logger = createLogger()
+
export function sendFollow (actorFollow: MActorFollowActors, t: Transaction | undefined) {
const me = actorFollow.ActorFollower
const following = actorFollow.ActorFollowing
diff --git a/server/core/lib/activitypub/send/send-like.ts b/server/core/lib/activitypub/send/send-like.ts
index 7aea76985b..fef9c0e39d 100644
--- a/server/core/lib/activitypub/send/send-like.ts
+++ b/server/core/lib/activitypub/send/send-like.ts
@@ -1,11 +1,13 @@
import { Transaction } from 'sequelize'
import { ActivityAudience, ActivityLike } from '@peertube/peertube-models'
-import { logger } from '../../../helpers/logger.js'
+import { createLogger } from '../../../helpers/logger.js'
import { MActor, MActorAudience, MVideoAccountLight, MVideoUrl } from '../../../types/models/index.js'
import { audiencify, getPublicAudience } from '../audience.js'
import { getVideoLikeActivityPubUrlByLocalActor } from '../url.js'
import { sendVideoRelatedActivityToOrigin } from './shared/send-utils.js'
+const logger = createLogger()
+
function sendLike (byActor: MActor, video: MVideoAccountLight, transaction: Transaction) {
logger.info('Creating job to like %s.', video.url)
diff --git a/server/core/lib/activitypub/send/send-reject.ts b/server/core/lib/activitypub/send/send-reject.ts
index 4076d4d738..3af906c321 100644
--- a/server/core/lib/activitypub/send/send-reject.ts
+++ b/server/core/lib/activitypub/send/send-reject.ts
@@ -1,10 +1,12 @@
import { ActivityFollow, ActivityReject } from '@peertube/peertube-models'
-import { logger } from '../../../helpers/logger.js'
+import { createLogger } from '../../../helpers/logger.js'
import { MActor } from '../../../types/models/index.js'
import { getLocalActorFollowRejectActivityPubUrl } from '../url.js'
import { buildFollowActivity } from './send-follow.js'
import { unicastTo } from './shared/send-utils.js'
+const logger = createLogger()
+
function sendReject (followUrl: string, follower: MActor, following: MActor) {
if (!follower.serverId) { // This should never happen
logger.warn('Do not sending reject to local follower.')
diff --git a/server/core/lib/activitypub/send/send-reply-approval.ts b/server/core/lib/activitypub/send/send-reply-approval.ts
index a2e7b067ee..faa1c75fdd 100644
--- a/server/core/lib/activitypub/send/send-reply-approval.ts
+++ b/server/core/lib/activitypub/send/send-reply-approval.ts
@@ -1,9 +1,11 @@
import { ActivityApproveReply, ActivityRejectReply } from '@peertube/peertube-models'
-import { logger } from '../../../helpers/logger.js'
+import { createLogger } from '../../../helpers/logger.js'
import { MCommentOwnerVideoReply } from '../../../types/models/index.js'
import { getLocalApproveReplyActivityPubUrl } from '../url.js'
import { unicastTo } from './shared/send-utils.js'
+const logger = createLogger()
+
// We can support type: 'RejectReply' in the future
export function sendReplyApproval (comment: MCommentOwnerVideoReply, type: 'ApproveReply') {
logger.info('Creating job to approve reply %s.', comment.url)
diff --git a/server/core/lib/activitypub/send/send-undo.ts b/server/core/lib/activitypub/send/send-undo.ts
index d7fba91dc5..33e6fd3eb6 100644
--- a/server/core/lib/activitypub/send/send-undo.ts
+++ b/server/core/lib/activitypub/send/send-undo.ts
@@ -1,6 +1,6 @@
import { ActivityAudience, ActivityDislike, ActivityLike, ActivityUndo, ActivityUndoObject, ContextType } from '@peertube/peertube-models'
import { Transaction } from 'sequelize'
-import { logger } from '../../../helpers/logger.js'
+import { createLogger } from '../../../helpers/logger.js'
import { VideoModel } from '../../../models/video/video.js'
import {
MActor,
@@ -27,6 +27,8 @@ import {
unicastTo
} from './shared/send-utils.js'
+const logger = createLogger()
+
function sendUndoFollow (actorFollow: MActorFollowActors, t: Transaction) {
const me = actorFollow.ActorFollower
const following = actorFollow.ActorFollowing
diff --git a/server/core/lib/activitypub/send/send-update.ts b/server/core/lib/activitypub/send/send-update.ts
index 3ae5558115..3ea5dcd7b3 100644
--- a/server/core/lib/activitypub/send/send-update.ts
+++ b/server/core/lib/activitypub/send/send-update.ts
@@ -3,7 +3,7 @@ import { getServerActor } from '@server/models/application/application.js'
import { PlayerSettingModel } from '@server/models/video/player-setting.js'
import { MPlayerSetting } from '@server/types/models/video/player-setting.js'
import { Transaction } from 'sequelize'
-import { logger } from '../../../helpers/logger.js'
+import { createLogger } from '../../../helpers/logger.js'
import { AccountModel } from '../../../models/account/account.js'
import { VideoShareModel } from '../../../models/video/video-share.js'
import { VideoModel } from '../../../models/video/video.js'
@@ -22,6 +22,8 @@ import { getLocalChannelPlayerSettingsActivityPubUrl, getLocalVideoPlayerSetting
import { canVideoBeFederated } from '../videos/federate.js'
import { broadcastToFollowers, getActorsInvolvedInVideo, sendVideoRelatedActivity } from './shared/send-utils.js'
+const logger = createLogger()
+
export async function sendUpdateVideo (video: MVideoAP, transaction: Transaction, overriddenByActor?: MActor) {
if (!canVideoBeFederated(video)) return undefined
diff --git a/server/core/lib/activitypub/send/send-view.ts b/server/core/lib/activitypub/send/send-view.ts
index 1257820141..3de4306ccc 100644
--- a/server/core/lib/activitypub/send/send-view.ts
+++ b/server/core/lib/activitypub/send/send-view.ts
@@ -3,12 +3,14 @@ import { VideoStatsManager } from '@server/lib/stats/video-stats-manager.js'
import { VideoModel } from '@server/models/video/video.js'
import { MActorAudience, MActorLight, MVideoImmutable, MVideoUrl } from '@server/types/models/index.js'
import { Transaction } from 'sequelize'
-import { logger } from '../../../helpers/logger.js'
+import { createLogger } from '../../../helpers/logger.js'
import { audiencify, getPublicAudience } from '../audience.js'
import { getLocalVideoViewActivityPubUrl } from '../url.js'
import { sendVideoRelatedActivity } from './shared/send-utils.js'
import { canVideoBeFederated } from '../videos/index.js'
+const logger = createLogger()
+
async function sendView (options: {
byActor: MActorLight
video: MVideoImmutable
diff --git a/server/core/lib/activitypub/send/shared/send-utils.ts b/server/core/lib/activitypub/send/shared/send-utils.ts
index 9a287da5b1..5c33aba46a 100644
--- a/server/core/lib/activitypub/send/shared/send-utils.ts
+++ b/server/core/lib/activitypub/send/shared/send-utils.ts
@@ -5,7 +5,7 @@ import { VideoShareModel } from '@server/models/video/video-share.js'
import { VideoModel } from '@server/models/video/video.js'
import { Transaction } from 'sequelize'
import { afterCommitIfTransaction } from '../../../../helpers/database-utils.js'
-import { logger } from '../../../../helpers/logger.js'
+import { createLogger } from '../../../../helpers/logger.js'
import { ActorFollowModel } from '../../../../models/actor/actor-follow.js'
import { ActorModel } from '../../../../models/actor/actor.js'
import {
@@ -20,6 +20,8 @@ import {
import { JobQueue } from '../../../job-queue/index.js'
import { getDirectAudience, getVideoAudience } from '../../audience.js'
+const logger = createLogger()
+
async function sendVideoRelatedActivity (activityBuilder: (audience: ActivityAudience) => Activity, options: {
byActor: MActorLight
video: MVideoAccountLight
diff --git a/server/core/lib/activitypub/share.ts b/server/core/lib/activitypub/share.ts
index 2c4e8c3e83..fbbe4dfe5b 100644
--- a/server/core/lib/activitypub/share.ts
+++ b/server/core/lib/activitypub/share.ts
@@ -2,7 +2,7 @@ import { HttpStatusCode } from '@peertube/peertube-models'
import { getServerActor } from '@server/models/application/application.js'
import Bluebird from 'bluebird'
import { Transaction } from 'sequelize'
-import { logger, loggerTagsFactory } from '../../helpers/logger.js'
+import { createLogger } from '../../helpers/logger.js'
import { CRAWL_REQUEST_CONCURRENCY } from '../../initializers/constants.js'
import { VideoShareModel } from '../../models/video/video-share.js'
import { MChannelActorLight, MVideo, MVideoAccountLight, MVideoId } from '../../types/models/video/index.js'
@@ -11,20 +11,14 @@ import { getOrCreateAPActor } from './actors/index.js'
import { sendUndoAnnounce, sendVideoAnnounce } from './send/index.js'
import { checkUrlsSameHost, getLocalVideoAnnounceActivityPubUrl } from './url.js'
-const lTags = loggerTagsFactory('share')
+const logger = createLogger('share')
export async function changeVideoChannelShare (
video: MVideoAccountLight,
oldVideoChannel: MChannelActorLight,
t: Transaction
) {
- logger.info(
- 'Updating video channel of video %s: %s -> %s.',
- video.uuid,
- oldVideoChannel.name,
- video.VideoChannel.name,
- lTags(video.uuid)
- )
+ logger.info('Updating video channel of video %s: %s -> %s.', video.uuid, oldVideoChannel.name, video.VideoChannel.name)
await undoShareByVideoChannel(video, oldVideoChannel, t)
diff --git a/server/core/lib/activitypub/video-comments.ts b/server/core/lib/activitypub/video-comments.ts
index d14a9784b4..46f7d998cf 100644
--- a/server/core/lib/activitypub/video-comments.ts
+++ b/server/core/lib/activitypub/video-comments.ts
@@ -3,7 +3,7 @@ import { CONFIG } from '@server/initializers/config.js'
import { getServerAccount } from '@server/models/application/application.js'
import Bluebird from 'bluebird'
import { sanitizeAndCheckVideoCommentObject } from '../../helpers/custom-validators/activitypub/video-comments.js'
-import { logger } from '../../helpers/logger.js'
+import { createLogger } from '../../helpers/logger.js'
import { ACTIVITY_PUB, CRAWL_REQUEST_CONCURRENCY } from '../../initializers/constants.js'
import { VideoCommentModel } from '../../models/video/video-comment.js'
import {
@@ -23,6 +23,8 @@ import { getOrCreateAPActor } from './actors/index.js'
import { checkUrlsSameHost } from './url.js'
import { canVideoBeFederated, getOrCreateAPVideo } from './videos/index.js'
+const logger = createLogger()
+
type ResolveThreadParams = {
url: string
comments?: MCommentOwner[]
@@ -35,16 +37,18 @@ export async function addVideoComments (commentUrls: string[]) {
if (CONFIG.VIDEO_COMMENTS.ACCEPT_REMOTE_COMMENTS !== true) return
return Bluebird.map(commentUrls, async commentUrl => {
- try {
- await resolveThread({ url: commentUrl, isVideo: false })
- } catch (err) {
- if (err.statusCode === HttpStatusCode.NOT_FOUND_404 || err.statusCode === HttpStatusCode.GONE_410) {
- logger.debug(`Cannot resolve thread ${commentUrl} that does not exist anymore`, { err })
- return
+ await logger.withContext([ commentUrl ], async () => {
+ try {
+ await resolveThread({ url: commentUrl, isVideo: false })
+ } catch (err) {
+ if (err.statusCode === HttpStatusCode.NOT_FOUND_404 || err.statusCode === HttpStatusCode.GONE_410) {
+ logger.debug(`Cannot resolve thread ${commentUrl} that does not exist anymore`, { err })
+ return
+ }
+
+ logger.info(`Cannot resolve thread ${commentUrl}`, { err })
}
-
- logger.info(`Cannot resolve thread ${commentUrl}`, { err })
- }
+ })
}, { concurrency: CRAWL_REQUEST_CONCURRENCY })
}
diff --git a/server/core/lib/activitypub/videos/get.ts b/server/core/lib/activitypub/videos/get.ts
index 1332d46bdc..f1eacffa1f 100644
--- a/server/core/lib/activitypub/videos/get.ts
+++ b/server/core/lib/activitypub/videos/get.ts
@@ -1,12 +1,14 @@
import { APObjectId } from '@peertube/peertube-models'
import { retryTransactionWrapper } from '@server/helpers/database-utils.js'
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { loadVideoByUrl } from '@server/lib/model-loaders/index.js'
import { MVideoAccountLightBlacklistAllFiles, MVideoImmutable, MVideoThumbnails, MVideoWithBlacklist } from '@server/types/models/index.js'
import { getAPId } from '../activity.js'
import { refreshVideoIfNeeded, scheduleVideoRefreshIfNeeded } from './refresh.js'
import { APVideoCreator, fetchRemoteVideo, SyncParam, syncVideoExternalAttributes } from './shared/index.js'
+const logger = createLogger()
+
type GetVideoResult<T> = Promise<{
video: T
created: boolean
@@ -49,51 +51,54 @@ export async function getOrCreateAPVideo (
// Get video url
const videoUrl = getAPId(options.videoObject)
- const videoFromDatabase = await loadVideoByUrl(videoUrl, fetchType)
-
- if (videoFromDatabase) {
- // We know that allowRefresh === false on `unsafe-only-immutable-attributes` fetch type because of type definitions
- let video = videoFromDatabase as MVideoThumbnails
-
- if (allowRefresh === true && video.isOutdated()) {
- if (syncParam.refreshVideo === true) {
- video = await refreshVideoIfNeeded({
- video,
- fetchedType: fetchType,
- syncParam
- })
- } else {
- scheduleVideoRefreshIfNeeded(video)
+
+ return logger.withContext([ videoUrl ], async () => {
+ const videoFromDatabase = await loadVideoByUrl(videoUrl, fetchType)
+
+ if (videoFromDatabase) {
+ // We know that allowRefresh === false on `unsafe-only-immutable-attributes` fetch type because of type definitions
+ let video = videoFromDatabase as MVideoThumbnails
+
+ if (allowRefresh === true && video.isOutdated()) {
+ if (syncParam.refreshVideo === true) {
+ video = await refreshVideoIfNeeded({
+ video,
+ fetchedType: fetchType,
+ syncParam
+ })
+ } else {
+ scheduleVideoRefreshIfNeeded(video)
+ }
}
+
+ return { video: videoFromDatabase, created: false }
}
- return { video: videoFromDatabase, created: false }
- }
+ const { videoObject } = await fetchRemoteVideo(videoUrl)
+ if (!videoObject) throw new Error('Cannot fetch remote video with url: ' + videoUrl)
- const { videoObject } = await fetchRemoteVideo(videoUrl)
- if (!videoObject) throw new Error('Cannot fetch remote video with url: ' + videoUrl)
+ // videoUrl is just an alias/redirection, so process object id instead
+ if (videoObject.id !== videoUrl) return getOrCreateAPVideo({ ...options, fetchType: 'full', videoObject })
- // videoUrl is just an alias/redirection, so process object id instead
- if (videoObject.id !== videoUrl) return getOrCreateAPVideo({ ...options, fetchType: 'full', videoObject })
+ try {
+ const creator = new APVideoCreator(videoObject)
+ const { autoBlacklisted, videoCreated } = await retryTransactionWrapper(() => creator.create())
- try {
- const creator = new APVideoCreator(videoObject)
- const { autoBlacklisted, videoCreated } = await retryTransactionWrapper(() => creator.create())
+ await syncVideoExternalAttributes(videoCreated, videoObject, syncParam)
- await syncVideoExternalAttributes(videoCreated, videoObject, syncParam)
+ return { video: videoCreated, created: true, autoBlacklisted }
+ } catch (err) {
+ // Maybe a concurrent getOrCreateAPVideo call created this video
+ if (err.name === 'SequelizeUniqueConstraintError') {
+ const alreadyCreatedVideo = await loadVideoByUrl(videoUrl, fetchType)
+ if (alreadyCreatedVideo) return { video: alreadyCreatedVideo, created: false }
- return { video: videoCreated, created: true, autoBlacklisted }
- } catch (err) {
- // Maybe a concurrent getOrCreateAPVideo call created this video
- if (err.name === 'SequelizeUniqueConstraintError') {
- const alreadyCreatedVideo = await loadVideoByUrl(videoUrl, fetchType)
- if (alreadyCreatedVideo) return { video: alreadyCreatedVideo, created: false }
+ logger.error('Cannot create video %s because of SequelizeUniqueConstraintError error, but cannot find it in database.', videoUrl)
+ }
- logger.error('Cannot create video %s because of SequelizeUniqueConstraintError error, but cannot find it in database.', videoUrl)
+ throw err
}
-
- throw err
- }
+ })
}
export function maybeGetOrCreateAPVideo (options: GetVideoParamAll): GetVideoResult<MVideoAccountLightBlacklistAllFiles>
diff --git a/server/core/lib/activitypub/videos/refresh.ts b/server/core/lib/activitypub/videos/refresh.ts
index 67d485b5c1..502cf14f41 100644
--- a/server/core/lib/activitypub/videos/refresh.ts
+++ b/server/core/lib/activitypub/videos/refresh.ts
@@ -1,5 +1,5 @@
import { HttpStatusCode } from '@peertube/peertube-models'
-import { logger, loggerTagsFactory } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { PeerTubeRequestError } from '@server/helpers/requests.js'
import { JobQueue } from '@server/lib/job-queue/job-queue.js'
import { VideoLoadByUrlType } from '@server/lib/model-loaders/index.js'
@@ -9,6 +9,8 @@ import { ActorFollowHealthCache } from '../../actor-follow-health-cache.js'
import { fetchRemoteVideo, SyncParam, syncVideoExternalAttributes } from './shared/index.js'
import { APVideoUpdater } from './updater.js'
+const logger = createLogger('ap', 'video', 'refresh')
+
export function scheduleVideoRefreshIfNeeded (video: MVideo) {
if (!video.isOutdated()) return
@@ -31,45 +33,46 @@ export async function refreshVideoIfNeeded (options: {
? options.video as MVideoAccountLightBlacklistAllFiles
: await VideoModel.loadByUrlAndPopulateAccountAndFiles(options.video.url)
- const lTags = loggerTagsFactory('ap', 'video', 'refresh', video.uuid, video.url)
+ // Inner functions (fetchRemoteVideo, APVideoUpdater...) inherit these tags without having to inject them
+ return logger.withContext([ video.uuid, video.url ], async () => {
+ logger.info('Refreshing video %s.', video.url)
- logger.info('Refreshing video %s.', video.url, lTags())
+ try {
+ const { videoObject } = await fetchRemoteVideo(video.url)
- try {
- const { videoObject } = await fetchRemoteVideo(video.url)
+ if (videoObject === undefined) {
+ logger.warn('Cannot refresh remote video %s: invalid body.', video.url)
- if (videoObject === undefined) {
- logger.warn('Cannot refresh remote video %s: invalid body.', video.url, lTags())
+ await video.setAsRefreshed()
+ return video
+ }
- await video.setAsRefreshed()
- return video
- }
+ const videoUpdater = new APVideoUpdater(videoObject, video, video.url)
+ await videoUpdater.update()
- const videoUpdater = new APVideoUpdater(videoObject, video, video.url)
- await videoUpdater.update()
+ await syncVideoExternalAttributes(video, videoObject, options.syncParam)
- await syncVideoExternalAttributes(video, videoObject, options.syncParam)
+ ActorFollowHealthCache.Instance.addGoodServerId(video.VideoChannel.Actor.serverId)
- ActorFollowHealthCache.Instance.addGoodServerId(video.VideoChannel.Actor.serverId)
+ return video
+ } catch (err) {
+ const statusCode = (err as PeerTubeRequestError).statusCode
- return video
- } catch (err) {
- const statusCode = (err as PeerTubeRequestError).statusCode
+ if (statusCode === HttpStatusCode.NOT_FOUND_404 || statusCode === HttpStatusCode.GONE_410) {
+ logger.info('Cannot refresh remote video %s: video does not exist anymore (404/410 error code). Deleting it.', video.url)
- if (statusCode === HttpStatusCode.NOT_FOUND_404 || statusCode === HttpStatusCode.GONE_410) {
- logger.info('Cannot refresh remote video %s: video does not exist anymore (404/410 error code). Deleting it.', video.url, lTags())
+ // Video does not exist anymore
+ await video.destroy()
+ return undefined
+ }
- // Video does not exist anymore
- await video.destroy()
- return undefined
- }
+ logger.warn('Cannot refresh video %s.', options.video.url, { err })
- logger.warn('Cannot refresh video %s.', options.video.url, { err, ...lTags() })
+ ActorFollowHealthCache.Instance.addBadServerId(video.VideoChannel.Actor.serverId)
- ActorFollowHealthCache.Instance.addBadServerId(video.VideoChannel.Actor.serverId)
-
- // Don't refresh in loop
- await video.setAsRefreshed()
- return video
- }
+ // Don't refresh in loop
+ await video.setAsRefreshed()
+ return video
+ }
+ })
}
diff --git a/server/core/lib/activitypub/videos/shared/abstract-builder.ts b/server/core/lib/activitypub/videos/shared/abstract-builder.ts
index aebcac6f32..3208ebd668 100644
--- a/server/core/lib/activitypub/videos/shared/abstract-builder.ts
+++ b/server/core/lib/activitypub/videos/shared/abstract-builder.ts
@@ -2,7 +2,7 @@ import { guessAspectRatio } from '@peertube/peertube-core-utils'
import { ActivityTagObject, VideoChaptersObject, VideoObject, VideoStreamingPlaylistType_Type } from '@peertube/peertube-models'
import { isVideoChaptersObjectValid } from '@server/helpers/custom-validators/activitypub/video-chapters.js'
import { deleteAllModels, filterNonExistingModels, retryTransactionWrapper } from '@server/helpers/database-utils.js'
-import { LoggerTagsFn, logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { sequelizeTypescript } from '@server/initializers/database.js'
import { AutomaticTagger } from '@server/lib/automatic-tags/automatic-tagger.js'
import { setAndSaveVideoAutomaticTags } from '@server/lib/automatic-tags/automatic-tags.js'
@@ -42,9 +42,10 @@ import {
} from './object-to-model-attributes.js'
import { getTrackerUrls, setVideoTrackers } from './trackers.js'
+const logger = createLogger()
+
export abstract class APVideoAbstractBuilder {
protected abstract videoObject: VideoObject
- protected abstract lTags: LoggerTagsFn
protected async getOrCreateVideoChannelFromVideoObject () {
const channel = await findOwner({
@@ -62,7 +63,7 @@ export abstract class APVideoAbstractBuilder {
protected async setThumbnails (video: MVideoThumbnails, t?: Transaction) {
const icons = this.videoObject.icon
if (icons.length === 0) {
- logger.warn('Cannot find thumbnails in video object', { object: this.videoObject, ...this.lTags() })
+ logger.warn('Cannot find thumbnails in video object', { object: this.videoObject })
return undefined
}
@@ -153,11 +154,11 @@ export abstract class APVideoAbstractBuilder {
const { body } = await fetchAP<VideoChaptersObject>(this.videoObject.hasParts)
if (!isVideoChaptersObjectValid(body)) {
- logger.warn('Chapters AP object is not valid, skipping', { body, ...this.lTags() })
+ logger.warn('Chapters AP object is not valid, skipping', { body })
return
}
- logger.debug('Fetched chapters AP object', { body, ...this.lTags() })
+ logger.debug('Fetched chapters AP object', { body })
return retryTransactionWrapper(() => {
return sequelizeTypescript.transaction(async t => {
diff --git a/server/core/lib/activitypub/videos/shared/creator.ts b/server/core/lib/activitypub/videos/shared/creator.ts
index 076f254ac1..3ddd54fe28 100644
--- a/server/core/lib/activitypub/videos/shared/creator.ts
+++ b/server/core/lib/activitypub/videos/shared/creator.ts
@@ -1,5 +1,5 @@
import { VideoObject } from '@peertube/peertube-models'
-import { logger, loggerTagsFactory, LoggerTagsFn } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { sequelizeTypescript } from '@server/initializers/database.js'
import { Hooks } from '@server/lib/plugins/hooks.js'
import { autoBlacklistVideoIfNeeded } from '@server/lib/video-blacklist.js'
@@ -8,17 +8,19 @@ import { MVideoFull, MVideoThumbnails } from '@server/types/models/index.js'
import { APVideoAbstractBuilder } from './abstract-builder.js'
import { getVideoAttributesFromObject } from './object-to-model-attributes.js'
-export class APVideoCreator extends APVideoAbstractBuilder {
- protected lTags: LoggerTagsFn
+const logger = createLogger('ap', 'video', 'create')
+export class APVideoCreator extends APVideoAbstractBuilder {
constructor (protected readonly videoObject: VideoObject) {
super()
+ }
- this.lTags = loggerTagsFactory('ap', 'video', 'create', this.videoObject.uuid, this.videoObject.id)
+ create () {
+ return logger.withContext([ this.videoObject.uuid, this.videoObject.id ], () => this.runCreate())
}
- async create () {
- logger.debug('Adding remote video %s.', this.videoObject.id, { ...this.videoObject, ...this.lTags() })
+ private async runCreate () {
+ logger.debug('Adding remote video %s.', this.videoObject.id, { ...this.videoObject })
const channelActor = await this.getOrCreateVideoChannelFromVideoObject()
const channel = channelActor.VideoChannel
@@ -55,7 +57,7 @@ export class APVideoCreator extends APVideoAbstractBuilder {
transaction: t
})
- logger.info('Remote video with uuid %s inserted.', this.videoObject.uuid, this.lTags())
+ logger.info('Remote video with uuid %s inserted.', this.videoObject.uuid)
Hooks.runAction('action:activity-pub.remote-video.created', { video: videoCreated, videoAPObject: this.videoObject })
diff --git a/server/core/lib/activitypub/videos/shared/url-to-object.ts b/server/core/lib/activitypub/videos/shared/url-to-object.ts
index f27f24971a..2771a4a64c 100644
--- a/server/core/lib/activitypub/videos/shared/url-to-object.ts
+++ b/server/core/lib/activitypub/videos/shared/url-to-object.ts
@@ -1,25 +1,21 @@
-import { sanitizeAndCheckVideoTorrentObject } from '@server/helpers/custom-validators/activitypub/videos.js'
-import { logger, loggerTagsFactory } from '@server/helpers/logger.js'
import { VideoObject } from '@peertube/peertube-models'
+import { sanitizeAndCheckVideoTorrentObject } from '@server/helpers/custom-validators/activitypub/videos.js'
+import { createLogger } from '@server/helpers/logger.js'
import { fetchAP } from '../../activity.js'
import { checkUrlsSameHost } from '../../url.js'
-const lTags = loggerTagsFactory('ap', 'video')
+const logger = createLogger('ap', 'video')
-async function fetchRemoteVideo (videoUrl: string): Promise<{ statusCode: number, videoObject: VideoObject }> {
- logger.info('Fetching remote video %s.', videoUrl, lTags(videoUrl))
+export async function fetchRemoteVideo (videoUrl: string): Promise<{ statusCode: number, videoObject: VideoObject }> {
+ logger.info('Fetching remote video %s.', videoUrl)
const { statusCode, body } = await fetchAP<any>(videoUrl)
if (sanitizeAndCheckVideoTorrentObject(body) === false || checkUrlsSameHost(body.id, videoUrl) !== true) {
- logger.debug('Remote video JSON is not valid.', { body, ...lTags(videoUrl) })
+ logger.debug('Remote video JSON is not valid.', { body })
return { statusCode, videoObject: undefined }
}
return { statusCode, videoObject: body }
}
-
-export {
- fetchRemoteVideo
-}
diff --git a/server/core/lib/activitypub/videos/shared/video-sync-attributes.ts b/server/core/lib/activitypub/videos/shared/video-sync-attributes.ts
index 2663b36659..6e71c87975 100644
--- a/server/core/lib/activitypub/videos/shared/video-sync-attributes.ts
+++ b/server/core/lib/activitypub/videos/shared/video-sync-attributes.ts
@@ -1,6 +1,6 @@
import { ActivityPubOrderedCollection, ActivitypubHttpFetcherPayload, VideoObject } from '@peertube/peertube-models'
import { runInReadCommittedTransaction } from '@server/helpers/database-utils.js'
-import { logger, loggerTagsFactory } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { JobQueue } from '@server/lib/job-queue/index.js'
import { VideoCommentModel } from '@server/models/video/video-comment.js'
import { VideoShareModel } from '@server/models/video/video-share.js'
@@ -11,7 +11,7 @@ import { crawlCollectionPage } from '../../crawl.js'
import { addVideoShares } from '../../share.js'
import { addVideoComments } from '../../video-comments.js'
-const lTags = loggerTagsFactory('ap', 'video')
+const logger = createLogger('ap', 'video')
export type SyncParam = {
rates: boolean
@@ -82,7 +82,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, video.url) }))
+ .catch(err => logger.error('Cannot add shares of video %s.', video.uuid, { err, rootUrl: uri }))
}
function syncComments (video: MVideo, fetchedVideo: VideoObject, isSync: boolean) {
@@ -97,7 +97,7 @@ 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, video.url) }))
+ .catch(err => logger.error('Cannot add comments of video %s.', video.uuid, { err, rootUrl: uri }))
}
function createJob (payload: ActivitypubHttpFetcherPayload) {
diff --git a/server/core/lib/activitypub/videos/updater.ts b/server/core/lib/activitypub/videos/updater.ts
index 0825cba15c..209b968406 100644
--- a/server/core/lib/activitypub/videos/updater.ts
+++ b/server/core/lib/activitypub/videos/updater.ts
@@ -1,6 +1,6 @@
import { VideoObject, VideoPrivacy } from '@peertube/peertube-models'
import { resetSequelizeInstance, runInReadCommittedTransaction } from '@server/helpers/database-utils.js'
-import { logger, loggerTagsFactory, LoggerTagsFn } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { Notifier } from '@server/lib/notifier/index.js'
import { PeerTubeSocket } from '@server/lib/peertube-socket.js'
import { Hooks } from '@server/lib/plugins/hooks.js'
@@ -15,8 +15,10 @@ import {
} from '@server/types/models/index.js'
import { Transaction } from 'sequelize'
import { haveActorsSameRemoteHost } from '../actors/check-actor.js'
-import { APVideoAbstractBuilder, getVideoAttributesFromObject, updateVideoRates } from './shared/index.js'
import { checkUrlsSameHost } from '../url.js'
+import { APVideoAbstractBuilder, getVideoAttributesFromObject, updateVideoRates } from './shared/index.js'
+
+const logger = createLogger('ap', 'video', 'update')
export class APVideoUpdater extends APVideoAbstractBuilder {
private readonly wasPrivateVideo: boolean
@@ -24,8 +26,6 @@ export class APVideoUpdater extends APVideoAbstractBuilder {
private readonly oldVideoChannel: MChannelAccountLight
- protected lTags: LoggerTagsFn
-
constructor (
protected readonly videoObject: VideoObject,
private readonly video: MVideoAccountLightBlacklistAllFiles,
@@ -37,15 +37,17 @@ export class APVideoUpdater extends APVideoAbstractBuilder {
this.wasUnlistedVideo = this.video.privacy === VideoPrivacy.UNLISTED
this.oldVideoChannel = this.video.VideoChannel
-
- this.lTags = loggerTagsFactory('ap', 'video', 'update', video.uuid, video.url)
}
async update (overrideTo?: string[]) {
+ return logger.withContext([ this.video.uuid, this.video.url ], () => this.runUpdate(overrideTo))
+ }
+
+ private async runUpdate (overrideTo?: string[]) {
logger.debug(
'Updating remote video "%s".',
this.videoObject.uuid,
- { videoObject: this.videoObject, ...this.lTags() }
+ { videoObject: this.videoObject }
)
if (!checkUrlsSameHost(this.contextUrl, this.videoObject.id)) {
@@ -112,7 +114,7 @@ export class APVideoUpdater extends APVideoAbstractBuilder {
Hooks.runAction('action:activity-pub.remote-video.updated', { video: videoUpdated, videoAPObject: this.videoObject })
- logger.info('Remote video with uuid %s updated', this.videoObject.uuid, this.lTags())
+ logger.info('Remote video with uuid %s updated', this.videoObject.uuid)
return videoUpdated
} catch (err) {
@@ -195,7 +197,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() })
+ logger.debug('Cannot update the remote video.', { err })
throw err
}
}
diff --git a/server/core/lib/actor-follow-health-cache.ts b/server/core/lib/actor-follow-health-cache.ts
index 5adf809336..04a30835b0 100644
--- a/server/core/lib/actor-follow-health-cache.ts
+++ b/server/core/lib/actor-follow-health-cache.ts
@@ -1,4 +1,6 @@
-import { logger } from '../helpers/logger.js'
+import { createLogger } from '../helpers/logger.js'
+
+const logger = createLogger()
// Cache follows scores, instead of writing them too often in database
// Keep data in memory, we don't really need Redis here as we don't really care to loose some scores
diff --git a/server/core/lib/auth/external-auth.ts b/server/core/lib/auth/external-auth.ts
index 4af7cb431a..e12cb26e4a 100644
--- a/server/core/lib/auth/external-auth.ts
+++ b/server/core/lib/auth/external-auth.ts
@@ -9,7 +9,7 @@ import {
isUserVideoQuotaDailyValid,
isUserVideoQuotaValid
} from '@server/helpers/custom-validators/users.js'
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { generateRandomString } from '@server/helpers/utils.js'
import { PLUGIN_EXTERNAL_AUTH_TOKEN_LIFETIME } from '@server/initializers/constants.js'
import { PluginManager } from '@server/lib/plugins/plugin-manager.js'
@@ -22,6 +22,8 @@ import {
import { BypassLogin } from './bypass-login.model.js'
import { ExternalUser } from './external-user.model.js'
+const logger = createLogger()
+
// Token is the key, expiration date is the value
const authBypassTokens = new Map<string, {
expires: Date
diff --git a/server/core/lib/auth/oauth-handlers.ts b/server/core/lib/auth/oauth-handlers.ts
index 3641ff1a5e..fd58a70cba 100644
--- a/server/core/lib/auth/oauth-handlers.ts
+++ b/server/core/lib/auth/oauth-handlers.ts
@@ -11,7 +11,7 @@ import { maskSecret } from '@peertube/peertube-core-utils'
import { isUserPasswordTooLong } from '@server/helpers/custom-validators/users.js'
import { MOAuthClient } from '@server/types/models/index.js'
import express from 'express'
-import { logger } from '../../helpers/logger.js'
+import { createLogger } from '../../helpers/logger.js'
import { CONFIG } from '../../initializers/config.js'
import { OAuthClientModel } from '../../models/oauth/oauth-client.js'
import { Hooks } from '../plugins/hooks.js'
@@ -21,6 +21,8 @@ import { TooLongPasswordError } from './oauth-errors.js'
import { buildToken, getAccessToken, getRefreshToken, revokeToken, saveToken } from './oauth-token.js'
import { checkUserNotBlockedOrThrow, getUserOrThrow } from './oauth-user.js'
+const logger = createLogger()
+
/**
* Reimplement some functions of OAuth2Server to inject external auth methods
*/
diff --git a/server/core/lib/auth/oauth-token.ts b/server/core/lib/auth/oauth-token.ts
index 2b5d135029..0bd50471dc 100644
--- a/server/core/lib/auth/oauth-token.ts
+++ b/server/core/lib/auth/oauth-token.ts
@@ -5,13 +5,15 @@ import { PluginManager } from '@server/lib/plugins/plugin-manager.js'
import { MOAuthClient } from '@server/types/models/index.js'
import { MUser } from '@server/types/models/user/user.js'
import express from 'express'
-import { logger } from '../../helpers/logger.js'
+import { createLogger } from '../../helpers/logger.js'
import { CONFIG } from '../../initializers/config.js'
import { OAuthTokenModel } from '../../models/oauth/oauth-token.js'
import { isRootAuthDisabled } from './auth-utils.js'
import { BypassLogin } from './bypass-login.model.js'
import { TokensCache } from './tokens-cache.js'
+const logger = createLogger()
+
export async function getAccessToken (bearerToken: string) {
logger.debug('Getting access token.')
diff --git a/server/core/lib/auth/oauth-user.ts b/server/core/lib/auth/oauth-user.ts
index 62f6a84dcd..127cfa210e 100644
--- a/server/core/lib/auth/oauth-user.ts
+++ b/server/core/lib/auth/oauth-user.ts
@@ -8,7 +8,7 @@ import { UserRegistrationModel } from '@server/models/user/user-registration.js'
import { AuthenticatedResultUpdaterFieldName, RegisterServerAuthenticatedResult } from '@server/types/index.js'
import { MUser, MUserDefault } from '@server/types/models/user/user.js'
import express from 'express'
-import { logger } from '../../helpers/logger.js'
+import { createLogger } from '../../helpers/logger.js'
import { CONFIG } from '../../initializers/config.js'
import { OTP } from '../../initializers/constants.js'
import { sequelizeTypescript } from '../../initializers/database.js'
@@ -30,6 +30,8 @@ import {
RegistrationWaitingForApproval
} from './oauth-errors.js'
+const logger = createLogger()
+
export async function getUserOrThrow (options: {
usernameOrEmail?: string
password?: string
diff --git a/server/core/lib/automatic-tags/automatic-tagger.ts b/server/core/lib/automatic-tags/automatic-tagger.ts
index 0bbcc0fa8b..77a5958d5a 100644
--- a/server/core/lib/automatic-tags/automatic-tagger.ts
+++ b/server/core/lib/automatic-tags/automatic-tagger.ts
@@ -1,6 +1,6 @@
import { uniqify } from '@peertube/peertube-core-utils'
import { AutomaticTagAvailable, AutomaticTagPolicy, CommentAutomaticTagPolicies, VideoAutoTagPolicies } from '@peertube/peertube-models'
-import { logger, loggerTagsFactory } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { WEBSERVER } from '@server/initializers/constants.js'
import { getServerAccount } from '@server/models/application/application.js'
import { AccountAutomaticTagPolicyModel } from '@server/models/automatic-tag/account-automatic-tag-policy.js'
@@ -10,7 +10,7 @@ import { LinkifyIt } from 'linkify-it'
import { Transaction } from 'sequelize'
import { PluginManager } from '../plugins/plugin-manager.js'
-const lTags = loggerTagsFactory('automatic-tags')
+const logger = createLogger('automatic-tags')
const linkifyIt = new LinkifyIt({ fuzzyLink: true })
@@ -51,11 +51,11 @@ export class AutomaticTagger {
result[ownerAccount.id] = uniqify(tags)
}
- logger.debug('Built automatic tags for comment', { text, result, ...lTags() })
+ logger.debug('Built automatic tags for comment', { text, result })
return result
} catch (err) {
- logger.error('Cannot build comment automatic tags', { text, err, ...lTags() })
+ logger.error('Cannot build comment automatic tags', { text, err })
return {}
}
@@ -80,13 +80,12 @@ export class AutomaticTagger {
videoDescription: video.description,
videoNameTags,
videoDescriptionTags,
- pluginTags,
- ...lTags()
+ pluginTags
})
return { [serverAccount.id]: uniqify([ ...videoNameTags, ...videoDescriptionTags, ...pluginTags ]) }
} catch (err) {
- logger.error('Cannot build video automatic tags', { video, err, ...lTags() })
+ logger.error('Cannot build video automatic tags', { video, err })
return {}
}
@@ -106,8 +105,7 @@ export class AutomaticTagger {
const watchedWords = await WatchedWordsListModel.buildWatchedWordsRegexp({ accountId: account.id, transaction })
logger.debug(`Got watched words regex for account ${account.id}`, {
- listNames: watchedWords.map(r => r.listName),
- ...lTags()
+ listNames: watchedWords.map(r => r.listName)
})
for (const { listName, regex } of watchedWords) {
@@ -117,7 +115,7 @@ export class AutomaticTagger {
automaticTags.push(listName)
}
} catch (err) {
- logger.error('Cannot test regex against text', { listName, regex: regex.toString(), err, ...lTags() })
+ logger.error('Cannot test regex against text', { listName, regex: regex.toString(), err })
}
}
@@ -128,7 +126,7 @@ export class AutomaticTagger {
tagsDone.add(AutomaticTagger.SPECIAL_TAGS.EXTERNAL_LINK)
}
- logger.debug('Built automatic tags for text', { text, automaticTags, ...lTags() })
+ logger.debug('Built automatic tags for text', { text, automaticTags })
return automaticTags
}
@@ -153,7 +151,7 @@ export class AutomaticTagger {
if (result) pluginTags.push(autoTagName)
} catch (err) {
- logger.error('Cannot execute auto tagger of plugin ' + npmName, { err, ...lTags() })
+ logger.error('Cannot execute auto tagger of plugin ' + npmName, { err })
}
}
}
@@ -168,7 +166,7 @@ export class AutomaticTagger {
const matches = linkifyIt.match(text)
if (!matches) return false
- logger.debug('Found external links in text', { matches, text, ...lTags() })
+ logger.debug('Found external links in text', { matches, text })
return matches.some(({ url }) => new URL(url).host !== WEBSERVER.HOST)
}
diff --git a/server/core/lib/blocklist.ts b/server/core/lib/blocklist.ts
index 7ec177607c..ef70fb2452 100644
--- a/server/core/lib/blocklist.ts
+++ b/server/core/lib/blocklist.ts
@@ -1,4 +1,4 @@
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { sequelizeTypescript } from '@server/initializers/database.js'
import { AccountModel } from '@server/models/account/account.js'
import { getServerAccount } from '@server/models/application/application.js'
@@ -17,6 +17,8 @@ import { AccountBlocklistModel } from '../models/blocklist/account-blocklist.js'
import { BlocklistLogModel } from '../models/blocklist/blocklist-log.js'
import { ServerBlocklistModel } from '../models/blocklist/server-blocklist.js'
+const logger = createLogger()
+
export async function addAccountInBlocklist (options: {
byAccountId: number
targetAccount: MAccountDefault
diff --git a/server/core/lib/emailer.ts b/server/core/lib/emailer.ts
index eb478b7037..d957e949bb 100644
--- a/server/core/lib/emailer.ts
+++ b/server/core/lib/emailer.ts
@@ -18,7 +18,7 @@ import { readdir, readFile } from 'fs/promises'
import handlebars, { HelperOptions } from 'handlebars'
import { createTransport, Transporter } from 'nodemailer'
import { join } from 'path'
-import { bunyanLogger, logger } from '../helpers/logger.js'
+import { bunyanLogger, createLogger } from '../helpers/logger.js'
import { CONFIG, isEmailEnabled } from '../initializers/config.js'
import { WEBSERVER } from '../initializers/constants.js'
import { MRegistration, MUserExport, MUserImport } from '../types/models/index.js'
@@ -27,6 +27,8 @@ import { JobQueue } from './job-queue/index.js'
import { Hooks } from './plugins/hooks.js'
import { ServerConfigManager } from './server-config-manager.js'
+const logger = createLogger()
+
interface MailMessage {
to: string[] | string
from: MailFrom
diff --git a/server/core/lib/files-cache/avatar-image-file-cache.ts b/server/core/lib/files-cache/avatar-image-file-cache.ts
index 1d34d87a82..cd9aaea2d5 100644
--- a/server/core/lib/files-cache/avatar-image-file-cache.ts
+++ b/server/core/lib/files-cache/avatar-image-file-cache.ts
@@ -1,11 +1,11 @@
-import { logger, loggerTagsFactory } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { ActorImageModel } from '@server/models/actor/actor-image.js'
import { ActorModel } from '@server/models/actor/actor.js'
import { MActorImage } from '@server/types/models/index.js'
import { refreshActorIfNeeded } from '../activitypub/actors/refresh.js'
import { AbstractImageFileCache } from './shared/abstract-image-file-cache.js'
-const lTags = loggerTagsFactory('lazy-load', 'avatar-image')
+const logger = createLogger('lazy-load', 'avatar-image')
export class AvatarImageFileCache extends AbstractImageFileCache<MActorImage> {
protected loadModel (filename: string) {
@@ -26,7 +26,7 @@ export class AvatarImageFileCache extends AbstractImageFileCache<MActorImage> {
await refreshActorIfNeeded({ actor, fetchedType: 'partial' })
} catch (err) {
- logger.error('Error while refreshing actor for avatar image lazy fetch', { ...lTags(), err })
+ logger.error('Error while refreshing actor for avatar image lazy fetch', { err })
}
}
}
diff --git a/server/core/lib/files-cache/shared/abstract-file-cache.ts b/server/core/lib/files-cache/shared/abstract-file-cache.ts
index d978fdc17c..c1c8ba1f0b 100644
--- a/server/core/lib/files-cache/shared/abstract-file-cache.ts
+++ b/server/core/lib/files-cache/shared/abstract-file-cache.ts
@@ -1,5 +1,5 @@
import { HttpStatusCode } from '@peertube/peertube-models'
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { CachePromise } from '@server/helpers/promise-cache.js'
import { doRequestAndSaveToFile, PeerTubeRequestError } from '@server/helpers/requests.js'
import { LRU_CACHE, STATIC_MAX_AGE } from '@server/initializers/constants.js'
@@ -7,6 +7,8 @@ import express from 'express'
import { LRUCache } from 'lru-cache'
import { Model } from 'sequelize'
+const logger = createLogger()
+
export type FileModel = {
fileUrl: string
filename: string
diff --git a/server/core/lib/files-cache/video-captions-file-cache.ts b/server/core/lib/files-cache/video-captions-file-cache.ts
index 76ce2491b3..89ed482f7f 100644
--- a/server/core/lib/files-cache/video-captions-file-cache.ts
+++ b/server/core/lib/files-cache/video-captions-file-cache.ts
@@ -1,11 +1,11 @@
-import { logger, loggerTagsFactory } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { VideoCaptionModel } from '@server/models/video/video-caption.js'
import { VideoModel } from '@server/models/video/video.js'
import { MVideoCaption } from '@server/types/models/index.js'
import { scheduleVideoRefreshIfNeeded } from '../activitypub/videos/refresh.js'
import { AbstractFileCache } from './shared/abstract-file-cache.js'
-const lTags = loggerTagsFactory('lazy-load', 'video-captions')
+const logger = createLogger('lazy-load', 'caption')
export class VideoCaptionsFileCache extends AbstractFileCache<MVideoCaption> {
protected loadModel (filename: string) {
@@ -26,7 +26,7 @@ export class VideoCaptionsFileCache extends AbstractFileCache<MVideoCaption> {
scheduleVideoRefreshIfNeeded(video)
} catch (err) {
- logger.error('Error while refreshing video for lazy fetch', { ...lTags(), err })
+ logger.error('Error while refreshing video for lazy fetch', { err })
}
}
}
diff --git a/server/core/lib/files-cache/video-storyboards-image-file-cache.ts b/server/core/lib/files-cache/video-storyboards-image-file-cache.ts
index ca38041a8f..ead75095ec 100644
--- a/server/core/lib/files-cache/video-storyboards-image-file-cache.ts
+++ b/server/core/lib/files-cache/video-storyboards-image-file-cache.ts
@@ -1,11 +1,11 @@
-import { logger, loggerTagsFactory } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { StoryboardModel } from '@server/models/video/storyboard.js'
import { VideoModel } from '@server/models/video/video.js'
import { MStoryboard } from '@server/types/models/index.js'
import { scheduleVideoRefreshIfNeeded } from '../activitypub/videos/index.js'
import { AbstractImageFileCache } from './shared/abstract-image-file-cache.js'
-const lTags = loggerTagsFactory('lazy-load', 'video-storyboards')
+const logger = createLogger('lazy-load', 'storyboard')
export class VideoStoryboardsImageFileCache extends AbstractImageFileCache<MStoryboard> {
protected loadModel (filename: string) {
@@ -26,7 +26,7 @@ export class VideoStoryboardsImageFileCache extends AbstractImageFileCache<MStor
scheduleVideoRefreshIfNeeded(video)
} catch (err) {
- logger.error('Error while refreshing video for lazy fetch', { ...lTags(), err })
+ logger.error('Error while refreshing video for lazy fetch', { err })
}
}
}
diff --git a/server/core/lib/files-cache/video-thumbnails-image-file-cache.ts b/server/core/lib/files-cache/video-thumbnails-image-file-cache.ts
index 9985bbcfc0..214369e3c5 100644
--- a/server/core/lib/files-cache/video-thumbnails-image-file-cache.ts
+++ b/server/core/lib/files-cache/video-thumbnails-image-file-cache.ts
@@ -1,11 +1,11 @@
-import { logger, loggerTagsFactory } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { ThumbnailModel } from '@server/models/video/thumbnail.js'
import { VideoModel } from '@server/models/video/video.js'
import { MThumbnail } from '@server/types/models/index.js'
import { scheduleVideoRefreshIfNeeded } from '../activitypub/videos/refresh.js'
import { AbstractImageFileCache } from './shared/abstract-image-file-cache.js'
-const lTags = loggerTagsFactory('lazy-load', 'video-thumbnails')
+const logger = createLogger('lazy-load', 'thumbnail')
export class VideoThumbnailsImageFileCache extends AbstractImageFileCache<MThumbnail> {
protected loadModel (filename: string) {
@@ -26,7 +26,7 @@ export class VideoThumbnailsImageFileCache extends AbstractImageFileCache<MThumb
scheduleVideoRefreshIfNeeded(video)
} catch (err) {
- logger.error('Error while refreshing video for lazy fetch', { ...lTags(), err })
+ logger.error('Error while refreshing video for lazy fetch', { err })
}
}
}
diff --git a/server/core/lib/hls.ts b/server/core/lib/hls.ts
index 14e38755c8..3283f854a6 100644
--- a/server/core/lib/hls.ts
+++ b/server/core/lib/hls.ts
@@ -11,7 +11,7 @@ import flatten from 'lodash-es/flatten.js'
import PQueue from 'p-queue'
import { basename, dirname, join } from 'path'
import { getAudioStreamCodec, getVideoStreamCodec } from '../helpers/ffmpeg/index.js'
-import { logger, loggerTagsFactory } from '../helpers/logger.js'
+import { createLogger } from '../helpers/logger.js'
import { doRequest, doRequestAndSaveToFile } from '../helpers/requests.js'
import { generateRandomString } from '../helpers/utils.js'
import { CONFIG } from '../initializers/config.js'
@@ -23,20 +23,20 @@ import { storeHLSFileFromContent } from './object-storage/index.js'
import { generateHLSMasterPlaylistFilename, generateHlsSha256SegmentsFilename, getHLSResolutionPlaylistFilename } from './paths.js'
import { VideoPathManager } from './video-path-manager.js'
-const lTags = loggerTagsFactory('hls')
+const logger = createLogger('hls')
export async function updateStreamingPlaylistsInfohashesIfNeeded () {
let playlistsToUpdateIds = new Set(await VideoStreamingPlaylistModel.listIdsByIncorrectPeerVersion())
if (playlistsToUpdateIds.size !== 0) {
- logger.info(`Will update ${playlistsToUpdateIds.size} streaming playlists infohash because of protocol version change.`, lTags())
+ logger.info(`Will update ${playlistsToUpdateIds.size} streaming playlists infohash because of protocol version change.`)
}
if (await ApplicationModel.streamingPlaylistBaseUrlChanged()) {
const localIds = await VideoStreamingPlaylistModel.listIdsLocals()
if (localIds.length !== 0) {
- logger.info(`Will update ${localIds.length} local streaming playlists infohash because of object storage base URL change.`, lTags())
+ logger.info(`Will update ${localIds.length} local streaming playlists infohash because of object storage base URL change.`)
playlistsToUpdateIds = new Set([ ...playlistsToUpdateIds, ...localIds ])
}
@@ -164,12 +164,12 @@ function updateMasterHLSPlaylist (video: MVideo, playlistArg: MStreamingPlaylist
content: masterPlaylistContent
})
- logger.info(`Updated master playlist file of video ${video.uuid} to object storage`, lTags(video.uuid))
+ logger.info(`Updated master playlist file of video ${video.uuid} to object storage`)
} else {
const masterPlaylistPath = VideoPathManager.Instance.getFSHLSOutputPath(video, playlist.playlistFilename)
await writeFile(masterPlaylistPath, masterPlaylistContent)
- logger.info(`Updated master playlist file ${masterPlaylistPath} of video ${video.uuid}`, lTags(video.uuid))
+ logger.info(`Updated master playlist file ${masterPlaylistPath} of video ${video.uuid}`)
}
return playlist.save()
diff --git a/server/core/lib/html/client-html.ts b/server/core/lib/html/client-html.ts
index 42d98026b1..97665e5d12 100644
--- a/server/core/lib/html/client-html.ts
+++ b/server/core/lib/html/client-html.ts
@@ -1,12 +1,14 @@
import { HttpStatusCode } from '@peertube/peertube-models'
import express from 'express'
-import { logger } from '../../helpers/logger.js'
+import { createLogger } from '../../helpers/logger.js'
import { ACCEPT_HEADERS } from '../../initializers/constants.js'
import { ActorHtml } from './shared/actor-html.js'
import { PageHtml } from './shared/page-html.js'
import { PlaylistHtml } from './shared/playlist-html.js'
import { VideoHtml } from './shared/video-html.js'
+const logger = createLogger()
+
class ClientHtml {
static invalidateCache () {
PageHtml.invalidateCache()
diff --git a/server/core/lib/html/shared/page-html.ts b/server/core/lib/html/shared/page-html.ts
index 6f8a155f61..c8ecb90a76 100644
--- a/server/core/lib/html/shared/page-html.ts
+++ b/server/core/lib/html/shared/page-html.ts
@@ -16,11 +16,13 @@ import express from 'express'
import { pathExists } from 'fs-extra/esm'
import { readFile } from 'fs/promises'
import { join } from 'path'
-import { logger } from '../../../helpers/logger.js'
+import { createLogger } from '../../../helpers/logger.js'
import { CUSTOM_HTML_TAG_COMMENTS, FILES_CONTENT_HASH, PLUGIN_GLOBAL_CSS_PATH, WEBSERVER } from '../../../initializers/constants.js'
import { ServerConfigManager } from '../../server-config-manager.js'
import { TagsHtml } from './tags-html.js'
+const logger = createLogger()
+
export class PageHtml {
private static htmlCache: { [path: string]: string } = {}
diff --git a/server/core/lib/job-queue/handlers/activitypub-cleaner.ts b/server/core/lib/job-queue/handlers/activitypub-cleaner.ts
index 643a641f37..a4d9be4617 100644
--- a/server/core/lib/job-queue/handlers/activitypub-cleaner.ts
+++ b/server/core/lib/job-queue/handlers/activitypub-cleaner.ts
@@ -1,5 +1,4 @@
-import Bluebird from 'bluebird'
-import { Job } from 'bullmq'
+import { HttpStatusCode } from '@peertube/peertube-models'
import {
isAnnounceActivityValid,
isDislikeActivityValid,
@@ -14,16 +13,17 @@ import { Redis } from '@server/lib/redis.js'
import { VideoCommentModel } from '@server/models/video/video-comment.js'
import { VideoShareModel } from '@server/models/video/video-share.js'
import { VideoModel } from '@server/models/video/video.js'
-import { HttpStatusCode } from '@peertube/peertube-models'
-import { logger, loggerTagsFactory } from '../../../helpers/logger.js'
+import Bluebird from 'bluebird'
+import { Job } from 'bullmq'
+import { createLogger } from '../../../helpers/logger.js'
import { AccountVideoRateModel } from '../../../models/account/account-video-rate.js'
-const lTags = loggerTagsFactory('ap-cleaner')
+const logger = createLogger('ap-cleaner')
// Job to clean remote interactions off local videos
async function processActivityPubCleaner (_job: Job) {
- logger.info('Processing ActivityPub cleaner.', lTags())
+ logger.info('Processing ActivityPub cleaner.')
{
const rateUrls = await AccountVideoRateModel.listRemoteRateUrlsOfLocalVideos()
@@ -70,60 +70,62 @@ export {
// ---------------------------------------------------------------------------
-async function updateObjectIfNeeded <T> (options: {
+async function updateObjectIfNeeded<T> (options: {
url: string
bodyValidator: (body: any) => boolean
updater: (url: string, newUrl: string) => Promise<T>
- deleter: (url: string) => Promise<T> }
-): Promise<{ data: T, status: 'deleted' | 'updated' } | null> {
+ deleter: (url: string) => Promise<T>
+}): Promise<{ data: T, status: 'deleted' | 'updated' } | null> {
const { url, bodyValidator, updater, deleter } = options
- const on404OrTombstone = async () => {
- logger.info('Removing remote AP object %s.', url, lTags(url))
- const data = await deleter(url)
-
- return { status: 'deleted' as 'deleted', data }
- }
+ return logger.withContext([ url ], async () => {
+ const on404OrTombstone = async () => {
+ logger.info('Removing remote AP object %s.', url)
+ const data = await deleter(url)
- try {
- const { body } = await fetchAP<any>(url)
+ return { status: 'deleted' as 'deleted', data }
+ }
- // If not same id, check same host and update
- if (!body?.id || !bodyValidator(body)) throw new Error(`Body or body id of ${url} is invalid`)
+ try {
+ const { body } = await fetchAP<any>(url)
- if (body.type === 'Tombstone') {
- return on404OrTombstone()
- }
+ // If not same id, check same host and update
+ if (!body?.id || !bodyValidator(body)) throw new Error(`Body or body id of ${url} is invalid`)
- const newUrl = body.id
- if (newUrl !== url) {
- if (checkUrlsSameHost(newUrl, url) !== true) {
- throw new Error(`New url ${newUrl} has not the same host than old url ${url}`)
+ if (body.type === 'Tombstone') {
+ return on404OrTombstone()
}
- logger.info('Updating remote AP object %s.', url, lTags(url))
- const data = await updater(url, newUrl)
+ const newUrl = body.id
+ if (newUrl !== url) {
+ if (checkUrlsSameHost(newUrl, url) !== true) {
+ throw new Error(`New url ${newUrl} has not the same host than old url ${url}`)
+ }
- return { status: 'updated', data }
- }
+ logger.info('Updating remote AP object %s.', url)
+ const data = await updater(url, newUrl)
- return null
- } catch (err) {
- // Does not exist anymore, remove entry
- if ((err as PeerTubeRequestError).statusCode === HttpStatusCode.NOT_FOUND_404) {
- return on404OrTombstone()
- }
+ return { status: 'updated', data }
+ }
- logger.debug('Remote AP object %s is unavailable.', url, lTags(url))
+ return null
+ } catch (err) {
+ // Does not exist anymore, remove entry
+ if ((err as PeerTubeRequestError).statusCode === HttpStatusCode.NOT_FOUND_404) {
+ return on404OrTombstone()
+ }
- const unavailability = await Redis.Instance.addAPUnavailability(url)
- if (unavailability >= AP_CLEANER.UNAVAILABLE_TRESHOLD) {
- logger.info('Removing unavailable AP resource %s.', url, lTags(url))
- return on404OrTombstone()
- }
+ logger.debug('Remote AP object %s is unavailable.', url)
- return null
- }
+ const unavailability = await Redis.Instance.addAPUnavailability(url)
+ if (unavailability >= AP_CLEANER.UNAVAILABLE_TRESHOLD) {
+ logger.info('Removing unavailable AP resource %s.', url)
+ return on404OrTombstone()
+ }
+
+ return null
+ }
+ })
}
function rateOptionsFactory () {
@@ -142,7 +144,7 @@ function rateOptionsFactory () {
return { videoId, type }
},
- deleter: async (url) => {
+ deleter: async url => {
const rate = await AccountVideoRateModel.loadByUrl(url, undefined)
const videoId = rate.videoId
@@ -168,7 +170,7 @@ function shareOptionsFactory () {
return undefined
},
- deleter: async (url) => {
+ deleter: async url => {
const share = await VideoShareModel.loadByUrl(url, undefined)
await share.destroy()
@@ -191,7 +193,7 @@ function commentOptionsFactory () {
return undefined
},
- deleter: async (url) => {
+ deleter: async url => {
const comment = await VideoCommentModel.loadByUrlAndPopulateAccountAndVideoAndReply(url)
await comment.destroy()
diff --git a/server/core/lib/job-queue/handlers/activitypub-follow.ts b/server/core/lib/job-queue/handlers/activitypub-follow.ts
index d0f1a01eaa..c5a9765f64 100644
--- a/server/core/lib/job-queue/handlers/activitypub-follow.ts
+++ b/server/core/lib/job-queue/handlers/activitypub-follow.ts
@@ -4,7 +4,7 @@ import { getLocalActorFollowActivityPubUrl } from '@server/lib/activitypub/url.j
import { Job } from 'bullmq'
import { sanitizeHost } from '../../../helpers/core-utils.js'
import { retryTransactionWrapper } from '../../../helpers/database-utils.js'
-import { logger } from '../../../helpers/logger.js'
+import { createLogger } from '../../../helpers/logger.js'
import { REMOTE_SCHEME, SERVER_ACTOR_NAME, WEBSERVER } from '../../../initializers/constants.js'
import { sequelizeTypescript } from '../../../initializers/database.js'
import { ActorFollowModel } from '../../../models/actor/actor-follow.js'
@@ -14,6 +14,8 @@ import { getOrCreateAPActor, loadActorUrlOrGetFromWebfinger } from '../../activi
import { sendFollow } from '../../activitypub/send/index.js'
import { Notifier } from '../../notifier/index.js'
+const logger = createLogger()
+
async function processActivityPubFollow (job: Job) {
const payload = job.data as ActivitypubFollowPayload
const host = payload.host
diff --git a/server/core/lib/job-queue/handlers/activitypub-http-broadcast.ts b/server/core/lib/job-queue/handlers/activitypub-http-broadcast.ts
index 06f62722dc..1553df3437 100644
--- a/server/core/lib/job-queue/handlers/activitypub-http-broadcast.ts
+++ b/server/core/lib/job-queue/handlers/activitypub-http-broadcast.ts
@@ -3,7 +3,9 @@ import { ActivitypubHttpBroadcastPayload } from '@peertube/peertube-models'
import { buildGlobalHTTPHeaders, buildSignedRequestOptions, computeBody } from '@server/lib/activitypub/send/http.js'
import { ActorFollowHealthCache } from '@server/lib/actor-follow-health-cache.js'
import { parallelHTTPBroadcastFromWorker, sequentialHTTPBroadcastFromWorker } from '@server/lib/worker/parent-process.js'
-import { logger } from '../../../helpers/logger.js'
+import { createLogger } from '../../../helpers/logger.js'
+
+const logger = createLogger()
// Prefer using a worker thread for HTTP requests because on high load we may have to sign many requests, which can be CPU intensive
diff --git a/server/core/lib/job-queue/handlers/activitypub-http-fetcher.ts b/server/core/lib/job-queue/handlers/activitypub-http-fetcher.ts
index 6ba84effbf..151dd8bb96 100644
--- a/server/core/lib/job-queue/handlers/activitypub-http-fetcher.ts
+++ b/server/core/lib/job-queue/handlers/activitypub-http-fetcher.ts
@@ -1,7 +1,7 @@
import { ActivitypubHttpFetcherPayload, FetchType } from '@peertube/peertube-models'
import { AccountModel } from '@server/models/account/account.js'
import { Job } from 'bullmq'
-import { logger } from '../../../helpers/logger.js'
+import { createLogger } from '../../../helpers/logger.js'
import { VideoCommentModel } from '../../../models/video/video-comment.js'
import { VideoShareModel } from '../../../models/video/video-share.js'
import { VideoModel } from '../../../models/video/video.js'
@@ -12,6 +12,8 @@ import { processActivities } from '../../activitypub/process/index.js'
import { addVideoShares } from '../../activitypub/share.js'
import { addVideoComments } from '../../activitypub/video-comments.js'
+const logger = createLogger()
+
async function processActivityPubHttpFetcher (job: Job) {
logger.info('Processing ActivityPub fetcher in job %s.', job.id)
@@ -25,9 +27,9 @@ async function processActivityPubHttpFetcher (job: Job) {
const fetcherType: { [id in FetchType]: (items: any[]) => Promise<any> } = {
'activity': items => processActivities(items, { outboxUrl: payload.uri, fromFetch: true }),
- 'video-shares': items => addVideoShares(items, video),
+ 'video-shares': items => logger.withContext([ video.uuid ], () => addVideoShares(items, video)),
'video-comments': items => addVideoComments(items),
- 'account-playlists': items => createAccountPlaylists(items, account)
+ 'account-playlists': items => logger.withContext([ account.Actor.url ], () => createAccountPlaylists(items, account))
}
const cleanerType: { [id in FetchType]?: (crawlStartDate: Date) => Promise<any> } = {
diff --git a/server/core/lib/job-queue/handlers/activitypub-http-unicast.ts b/server/core/lib/job-queue/handlers/activitypub-http-unicast.ts
index aa7ba1f7e1..7c06e4fe59 100644
--- a/server/core/lib/job-queue/handlers/activitypub-http-unicast.ts
+++ b/server/core/lib/job-queue/handlers/activitypub-http-unicast.ts
@@ -1,10 +1,12 @@
import { Job } from 'bullmq'
import { ActivitypubHttpUnicastPayload } from '@peertube/peertube-models'
import { buildGlobalHTTPHeaders, buildSignedRequestOptions, computeBody } from '@server/lib/activitypub/send/http.js'
-import { logger } from '../../../helpers/logger.js'
+import { createLogger } from '../../../helpers/logger.js'
import { ActorFollowHealthCache } from '../../actor-follow-health-cache.js'
import { httpUnicastFromWorker } from '@server/lib/worker/parent-process.js'
+const logger = createLogger()
+
async function processActivityPubHttpUnicast (job: Job) {
logger.info('Processing ActivityPub unicast in job %s.', job.id)
diff --git a/server/core/lib/job-queue/handlers/activitypub-refresher.ts b/server/core/lib/job-queue/handlers/activitypub-refresher.ts
index c009074885..4085c16111 100644
--- a/server/core/lib/job-queue/handlers/activitypub-refresher.ts
+++ b/server/core/lib/job-queue/handlers/activitypub-refresher.ts
@@ -3,11 +3,13 @@ import { refreshVideoPlaylistIfNeeded } from '@server/lib/activitypub/playlists/
import { refreshVideoIfNeeded } from '@server/lib/activitypub/videos/index.js'
import { loadVideoByUrl, VideoLoadByUrlType } from '@server/lib/model-loaders/index.js'
import { Job } from 'bullmq'
-import { logger } from '../../../helpers/logger.js'
+import { createLogger } from '../../../helpers/logger.js'
import { ActorModel } from '../../../models/actor/actor.js'
import { VideoPlaylistModel } from '../../../models/video/video-playlist.js'
import { refreshActorIfNeeded } from '../../activitypub/actors/index.js'
+const logger = createLogger()
+
async function refreshAPObject (job: Job) {
const payload = job.data as RefreshPayload
diff --git a/server/core/lib/job-queue/handlers/actor-keys.ts b/server/core/lib/job-queue/handlers/actor-keys.ts
index fd87120824..3fa7a641e3 100644
--- a/server/core/lib/job-queue/handlers/actor-keys.ts
+++ b/server/core/lib/job-queue/handlers/actor-keys.ts
@@ -2,7 +2,9 @@ import { Job } from 'bullmq'
import { generateAndSaveActorKeys } from '@server/lib/activitypub/actors/index.js'
import { ActorModel } from '@server/models/actor/actor.js'
import { ActorKeysPayload } from '@peertube/peertube-models'
-import { logger } from '../../../helpers/logger.js'
+import { createLogger } from '../../../helpers/logger.js'
+
+const logger = createLogger()
export async function processActorKeys (job: Job) {
const payload = job.data as ActorKeysPayload
diff --git a/server/core/lib/job-queue/handlers/after-video-channel-import.ts b/server/core/lib/job-queue/handlers/after-video-channel-import.ts
index 773e57da29..42238aa705 100644
--- a/server/core/lib/job-queue/handlers/after-video-channel-import.ts
+++ b/server/core/lib/job-queue/handlers/after-video-channel-import.ts
@@ -1,9 +1,9 @@
import { AfterVideoChannelImportPayload, StreamSyncState, VideoImportPreventExceptionResult } from '@peertube/peertube-models'
-import { logger, loggerTagsFactory } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { VideoChannelSyncModel } from '@server/models/video/video-channel-sync.js'
import { Job } from 'bullmq'
-const lTags = loggerTagsFactory('channel-synchronization')
+const logger = createLogger('channel-synchronization')
export async function processAfterVideoChannelImport (job: Job) {
const payload = job.data as AfterVideoChannelImportPayload
@@ -29,10 +29,10 @@ export async function processAfterVideoChannelImport (job: Job) {
if (errors > 0) {
sync.state = StreamSyncState.FAILED
- logger.error(`Finished synchronizing "${sync.VideoChannel.Actor.preferredUsername}" with failures.`, { errors, successes, ...lTags() })
+ logger.error(`Finished synchronizing "${sync.VideoChannel.Actor.preferredUsername}" with failures.`, { errors, successes })
} else {
sync.state = StreamSyncState.SYNCED
- logger.info(`Finished synchronizing "${sync.VideoChannel.Actor.preferredUsername}" successfully.`, { successes, ...lTags() })
+ logger.info(`Finished synchronizing "${sync.VideoChannel.Actor.preferredUsername}" successfully.`, { successes })
}
await sync.save()
diff --git a/server/core/lib/job-queue/handlers/build-automatic-tags.ts b/server/core/lib/job-queue/handlers/build-automatic-tags.ts
index 630aa87e32..fc4a2a1735 100644
--- a/server/core/lib/job-queue/handlers/build-automatic-tags.ts
+++ b/server/core/lib/job-queue/handlers/build-automatic-tags.ts
@@ -1,5 +1,5 @@
import { BuildAutomaticTagsPayload } from '@peertube/peertube-models'
-import { logger, loggerTagsFactory } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { AutomaticTagger } from '@server/lib/automatic-tags/automatic-tagger.js'
import { setAndSaveCommentAutomaticTags, setAndSaveVideoAutomaticTags } from '@server/lib/automatic-tags/automatic-tags.js'
import { getServerAccount } from '@server/models/application/application.js'
@@ -8,14 +8,14 @@ import { VideoModel } from '@server/models/video/video.js'
import { MAccount } from '@server/types/models/index.js'
import { Job } from 'bullmq'
-const lTags = loggerTagsFactory('job-queue')
+const logger = createLogger('job-queue')
const BATCH_SIZE = 250
export async function processBuildAutomaticTags (job: Job): Promise<void> {
const payload = job.data as BuildAutomaticTagsPayload
- logger.info('Processing build automatic tags in job %s.', job.id, { payload, ...lTags() })
+ logger.info('Processing build automatic tags in job %s.', job.id, { payload })
const serverAccount = await getServerAccount()
const accountId = payload.accountId
@@ -45,8 +45,7 @@ export async function processBuildAutomaticTags (job: Job): Promise<void> {
logger.info('Processed build automatic tags in job %s.', job.id, {
payload,
rebuiltComments: totalRebuiltComments,
- rebuiltVideos: totalRebuiltVideos,
- ...lTags()
+ rebuiltVideos: totalRebuiltVideos
})
}
diff --git a/server/core/lib/job-queue/handlers/create-user-export.ts b/server/core/lib/job-queue/handlers/create-user-export.ts
index 0c1bc07fe2..0adb0db023 100644
--- a/server/core/lib/job-queue/handlers/create-user-export.ts
+++ b/server/core/lib/job-queue/handlers/create-user-export.ts
@@ -1,20 +1,20 @@
import { Job } from 'bullmq'
-import { logger, loggerTagsFactory } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { CreateUserExportPayload } from '@peertube/peertube-models'
import { UserExportModel } from '@server/models/user/user-export.js'
import { UserExporter } from '@server/lib/user-import-export/user-exporter.js'
import { Emailer } from '@server/lib/emailer.js'
-const lTags = loggerTagsFactory('user-export')
+const logger = createLogger('user-export')
export async function processCreateUserExport (job: Job): Promise<void> {
const payload = job.data as CreateUserExportPayload
const exportModel = await UserExportModel.load(payload.userExportId)
- logger.info('Processing create user export %s in job %s.', payload.userExportId, job.id, lTags())
+ logger.info('Processing create user export %s in job %s.', payload.userExportId, job.id)
if (!exportModel) {
- logger.info(`User export ${payload.userExportId} does not exist anymore, do not create user export.`, lTags())
+ logger.info(`User export ${payload.userExportId} does not exist anymore, do not create user export.`)
return
}
@@ -25,7 +25,7 @@ export async function processCreateUserExport (job: Job): Promise<void> {
await Emailer.Instance.addUserExportCompletedOrErroredJob(exportModel)
- logger.info(`User export ${payload.userExportId} has been created`, lTags())
+ logger.info(`User export ${payload.userExportId} has been created`)
} catch (err) {
await Emailer.Instance.addUserExportCompletedOrErroredJob(exportModel)
diff --git a/server/core/lib/job-queue/handlers/email.ts b/server/core/lib/job-queue/handlers/email.ts
index 539a8cce16..0cc8d204c4 100644
--- a/server/core/lib/job-queue/handlers/email.ts
+++ b/server/core/lib/job-queue/handlers/email.ts
@@ -1,8 +1,10 @@
import { Job } from 'bullmq'
import { EmailPayload } from '@peertube/peertube-models'
-import { logger } from '../../../helpers/logger.js'
+import { createLogger } from '../../../helpers/logger.js'
import { Emailer } from '../../emailer.js'
+const logger = createLogger()
+
export function processEmail (job: Job) {
const payload = job.data as EmailPayload
logger.info('Processing email in job %s.', job.id)
diff --git a/server/core/lib/job-queue/handlers/federate-video.ts b/server/core/lib/job-queue/handlers/federate-video.ts
index 298f1de5b7..32ae798271 100644
--- a/server/core/lib/job-queue/handlers/federate-video.ts
+++ b/server/core/lib/job-queue/handlers/federate-video.ts
@@ -5,7 +5,9 @@ import { federateVideoIfNeeded } from '@server/lib/activitypub/videos/index.js'
import { ActorModel } from '@server/models/actor/actor.js'
import { VideoModel } from '@server/models/video/video.js'
import { Job } from 'bullmq'
-import { logger } from '../../../helpers/logger.js'
+import { createLogger } from '../../../helpers/logger.js'
+
+const logger = createLogger()
export function processFederateVideo (job: Job) {
const payload = job.data as FederateVideoPayload
diff --git a/server/core/lib/job-queue/handlers/generate-storyboard.ts b/server/core/lib/job-queue/handlers/generate-storyboard.ts
index 04012cca29..a851b02657 100644
--- a/server/core/lib/job-queue/handlers/generate-storyboard.ts
+++ b/server/core/lib/job-queue/handlers/generate-storyboard.ts
@@ -2,7 +2,7 @@ import { FFmpegImage } from '@peertube/peertube-ffmpeg'
import { GenerateStoryboardPayload, VideoFileStream } from '@peertube/peertube-models'
import { getFFmpegCommandWrapperOptions } from '@server/helpers/ffmpeg/index.js'
import { generateImageFilename, getImageSize } from '@server/helpers/image-utils.js'
-import { logger, loggerTagsFactory } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { CONFIG } from '@server/initializers/config.js'
import { STORYBOARD } from '@server/initializers/constants.js'
import { VideoPathManager } from '@server/lib/video-path-manager.js'
@@ -12,99 +12,98 @@ import { join } from 'path'
import { buildSpriteSize, buildTotalSprites, findGridSize, insertStoryboardInDatabase } from '../../storyboard.js'
import { buildPromiseForAbortSignal } from './shared/job-helpers.js'
-const lTagsBase = loggerTagsFactory('storyboard')
+const logger = createLogger('storyboard')
export async function processGenerateStoryboard (job: Job, abortSignal?: AbortSignal) {
const abortPromise = buildPromiseForAbortSignal(abortSignal)
- const run = async () => {
- const payload = job.data as GenerateStoryboardPayload
- const lTags = lTagsBase(payload.videoUUID)
+ const payload = job.data as GenerateStoryboardPayload
- logger.info(`Processing generate storyboard of ${payload.videoUUID} in job ${job.id}.`, lTags)
+ const run = () =>
+ logger.withContext([ payload.videoUUID ], async () => {
+ logger.info(`Processing generate storyboard of ${payload.videoUUID} in job ${job.id}.`)
- if (CONFIG.STORYBOARDS.ENABLED !== true) {
- logger.info(`Storyboard disabled, do not process storyboard of ${payload.videoUUID} in job ${job.id}.`, lTags)
- return
- }
-
- const inputFileMutexReleaser = await VideoPathManager.Instance.lockFiles(payload.videoUUID)
-
- try {
- const video = await VideoModel.loadFull(payload.videoUUID)
- if (!video) {
- logger.info(`Video ${payload.videoUUID} does not exist anymore, skipping storyboard generation.`, lTags)
- return
- }
-
- const inputFile = video.getMaxQualityFile(VideoFileStream.VIDEO)
- if (!inputFile) {
- logger.info(`Do not generate a storyboard of ${payload.videoUUID} since the video does not have a video stream`, lTags)
+ if (CONFIG.STORYBOARDS.ENABLED !== true) {
+ logger.info(`Storyboard disabled, do not process storyboard of ${payload.videoUUID} in job ${job.id}.`)
return
}
- await VideoPathManager.Instance.makeAvailableVideoFile(inputFile, async videoPath => {
- const { spriteHeight, spriteWidth } = await buildSpriteSize(videoPath)
+ const inputFileMutexReleaser = await VideoPathManager.Instance.lockFiles(payload.videoUUID)
- const { totalSprites, spriteDuration } = buildTotalSprites(video)
- if (totalSprites === 0) {
- logger.info(`Do not generate a storyboard of ${payload.videoUUID} because the video is not long enough`, lTags)
+ try {
+ const video = await VideoModel.loadFull(payload.videoUUID)
+ if (!video) {
+ logger.info(`Video ${payload.videoUUID} does not exist anymore, skipping storyboard generation.`)
return
}
- const spritesCount = findGridSize({
- toFind: totalSprites,
- maxEdgeCount: STORYBOARD.SPRITES_MAX_EDGE_COUNT
- })
-
- const filename = generateImageFilename()
- const destination = join(CONFIG.STORAGE.STORYBOARDS_DIR, filename)
-
- logger.debug(
- `Generating storyboard from video of ${video.uuid} to ${destination}`,
- { ...lTags, totalSprites, spritesCount, spriteDuration, videoDuration: video.duration, spriteHeight, spriteWidth }
- )
-
- const ffmpeg = new FFmpegImage({
- ...getFFmpegCommandWrapperOptions('thumbnail'),
+ const inputFile = video.getMaxQualityFile(VideoFileStream.VIDEO)
+ if (!inputFile) {
+ logger.info(`Do not generate a storyboard of ${payload.videoUUID} since the video does not have a video stream`)
+ return
+ }
- abortSignal
- })
+ await VideoPathManager.Instance.makeAvailableVideoFile(inputFile, async videoPath => {
+ const { spriteHeight, spriteWidth } = await buildSpriteSize(videoPath)
- await ffmpeg.generateStoryboardFromVideo({
- destination,
- path: videoPath,
- inputFileMutexReleaser,
- sprites: {
- size: {
- height: spriteHeight,
- width: spriteWidth
- },
- count: spritesCount,
- duration: spriteDuration
+ const { totalSprites, spriteDuration } = buildTotalSprites(video)
+ if (totalSprites === 0) {
+ logger.info(`Do not generate a storyboard of ${payload.videoUUID} because the video is not long enough`)
+ return
}
- })
-
- await insertStoryboardInDatabase({
- videoUUID: video.uuid,
- lTags,
- filename,
- destination,
-
- imageSize: await getImageSize(destination),
-
- spriteHeight,
- spriteWidth,
- spriteDuration,
-
- federate: payload.federate
+ const spritesCount = findGridSize({
+ toFind: totalSprites,
+ maxEdgeCount: STORYBOARD.SPRITES_MAX_EDGE_COUNT
+ })
+
+ const filename = generateImageFilename()
+ const destination = join(CONFIG.STORAGE.STORYBOARDS_DIR, filename)
+
+ logger.debug(
+ `Generating storyboard from video of ${video.uuid} to ${destination}`,
+ { totalSprites, spritesCount, spriteDuration, videoDuration: video.duration, spriteHeight, spriteWidth }
+ )
+
+ const ffmpeg = new FFmpegImage({
+ ...getFFmpegCommandWrapperOptions('thumbnail'),
+
+ abortSignal
+ })
+
+ await ffmpeg.generateStoryboardFromVideo({
+ destination,
+ path: videoPath,
+ inputFileMutexReleaser,
+ sprites: {
+ size: {
+ height: spriteHeight,
+ width: spriteWidth
+ },
+ count: spritesCount,
+ duration: spriteDuration
+ }
+ })
+
+ await insertStoryboardInDatabase({
+ videoUUID: video.uuid,
+
+ filename,
+ destination,
+
+ imageSize: await getImageSize(destination),
+
+ spriteHeight,
+ spriteWidth,
+ spriteDuration,
+
+ federate: payload.federate
+ })
})
- })
- } finally {
- inputFileMutexReleaser()
- }
- }
+ } finally {
+ inputFileMutexReleaser()
+ }
+ })
return Promise.race([ run(), abortPromise ])
}
diff --git a/server/core/lib/job-queue/handlers/import-user-archive.ts b/server/core/lib/job-queue/handlers/import-user-archive.ts
index 7a6d4b2c39..e95be9459b 100644
--- a/server/core/lib/job-queue/handlers/import-user-archive.ts
+++ b/server/core/lib/job-queue/handlers/import-user-archive.ts
@@ -1,20 +1,20 @@
-import { Job } from 'bullmq'
-import { logger, loggerTagsFactory } from '@server/helpers/logger.js'
import { ImportUserArchivePayload } from '@peertube/peertube-models'
-import { UserImportModel } from '@server/models/user/user-import.js'
-import { UserImporter } from '@server/lib/user-import-export/user-importer.js'
+import { createLogger } from '@server/helpers/logger.js'
import { Emailer } from '@server/lib/emailer.js'
+import { UserImporter } from '@server/lib/user-import-export/user-importer.js'
+import { UserImportModel } from '@server/models/user/user-import.js'
+import { Job } from 'bullmq'
-const lTags = loggerTagsFactory('user-import')
+const logger = createLogger('user-import')
export async function processImportUserArchive (job: Job): Promise<void> {
const payload = job.data as ImportUserArchivePayload
const importModel = await UserImportModel.load(payload.userImportId)
- logger.info(`Processing importing user archive ${payload.userImportId} in job ${job.id}`, lTags())
+ logger.info(`Processing importing user archive ${payload.userImportId} in job ${job.id}`)
if (!importModel) {
- logger.info(`User import ${payload.userImportId} does not exist anymore, do not create import data.`, lTags())
+ logger.info(`User import ${payload.userImportId} does not exist anymore, do not create import data.`)
return
}
@@ -24,7 +24,7 @@ export async function processImportUserArchive (job: Job): Promise<void> {
try {
await Emailer.Instance.addUserImportSuccessJob(importModel)
- logger.info(`User import ${payload.userImportId} ended`, lTags())
+ logger.info(`User import ${payload.userImportId} ended`)
} catch (err) {
await Emailer.Instance.addUserImportErroredJob(importModel)
diff --git a/server/core/lib/job-queue/handlers/manage-video-torrent.ts b/server/core/lib/job-queue/handlers/manage-video-torrent.ts
index a54ff967db..b2c223abb0 100644
--- a/server/core/lib/job-queue/handlers/manage-video-torrent.ts
+++ b/server/core/lib/job-queue/handlers/manage-video-torrent.ts
@@ -9,7 +9,9 @@ import { VideoInfohashModel } from '@server/models/video/video-infohash.js'
import { VideoStreamingPlaylistModel } from '@server/models/video/video-streaming-playlist.js'
import { VideoModel } from '@server/models/video/video.js'
import { Job } from 'bullmq'
-import { logger } from '../../../helpers/logger.js'
+import { createLogger } from '../../../helpers/logger.js'
+
+const logger = createLogger()
async function processManageVideoTorrent (job: Job) {
const payload = job.data as ManageVideoTorrentPayload
@@ -35,35 +37,37 @@ async function doCreateAction (payload: ManageVideoTorrentPayload & { action: 'c
if (!video || !file) return
- const fileMutexReleaser = await VideoPathManager.Instance.lockFiles(video.uuid)
+ await logger.withContext([ video.uuid ], async () => {
+ const fileMutexReleaser = await VideoPathManager.Instance.lockFiles(video.uuid)
- try {
- await video.reload()
- await file.reload()
+ try {
+ await video.reload()
+ await file.reload()
- const { infoHash, torrentFilename } = await createTorrentForFile(video, file)
+ const { infoHash, torrentFilename } = await createTorrentForFile(video, file)
- const saved = await retryTransactionWrapper(() => {
- return sequelizeTypescript.transaction(async transaction => {
- // Refresh videoFile because the createTorrentAndSetInfoHash could be long
- // Also reload on every attempt: after a rollback the previous instance has no changed attribute left to save
- const refreshedFile = await VideoFileModel.loadWithVideo(file.id, transaction)
- if (!refreshedFile) return false
+ const saved = await retryTransactionWrapper(() => {
+ return sequelizeTypescript.transaction(async transaction => {
+ // Refresh videoFile because the createTorrentAndSetInfoHash could be long
+ // Also reload on every attempt: after a rollback the previous instance has no changed attribute left to save
+ const refreshedFile = await VideoFileModel.loadWithVideo(file.id, transaction)
+ if (!refreshedFile) return false
- refreshedFile.torrentFilename = torrentFilename
- await refreshedFile.save({ transaction })
+ refreshedFile.torrentFilename = torrentFilename
+ await refreshedFile.save({ transaction })
- await VideoInfohashModel.replaceFileInfohash(refreshedFile.id, infoHash, transaction)
+ await VideoInfohashModel.replaceFileInfohash(refreshedFile.id, infoHash, transaction)
- return true
+ return true
+ })
})
- })
- // File does not exist anymore, remove the generated torrent
- if (!saved) await file.removeTorrent()
- } finally {
- fileMutexReleaser()
- }
+ // File does not exist anymore, remove the generated torrent
+ if (!saved) await file.removeTorrent()
+ } finally {
+ fileMutexReleaser()
+ }
+ })
}
async function doUpdateMetadataAction (payload: ManageVideoTorrentPayload & { action: 'update-metadata' }) {
@@ -76,13 +80,16 @@ async function doUpdateMetadataAction (payload: ManageVideoTorrentPayload & { ac
if ((!video && !streamingPlaylist) || !file) return
const extractedVideo = extractVideo(video || streamingPlaylist)
- const fileMutexReleaser = await VideoPathManager.Instance.lockFiles(extractedVideo.uuid)
- try {
- await updateTorrentForFileAndSave(video || streamingPlaylist, file)
- } finally {
- fileMutexReleaser()
- }
+ await logger.withContext([ extractedVideo.uuid ], async () => {
+ const fileMutexReleaser = await VideoPathManager.Instance.lockFiles(extractedVideo.uuid)
+
+ try {
+ await updateTorrentForFileAndSave(video || streamingPlaylist, file)
+ } finally {
+ fileMutexReleaser()
+ }
+ })
}
async function loadVideoOrLog (videoId: number) {
diff --git a/server/core/lib/job-queue/handlers/move-to-file-system.ts b/server/core/lib/job-queue/handlers/move-to-file-system.ts
index 80efd51baf..035d898670 100644
--- a/server/core/lib/job-queue/handlers/move-to-file-system.ts
+++ b/server/core/lib/job-queue/handlers/move-to-file-system.ts
@@ -1,28 +1,23 @@
import { isMoveCaptionPayload, isMoveVideoStoragePayload, MoveStoragePayload } from '@peertube/peertube-models'
-import { logger, loggerTagsFactory } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { moveCaptionToFS, moveVideoToFS, onMoveVideoToFSFailure } from '@server/lib/move-storage/move-to-file-system.js'
import { Job } from 'bullmq'
-const lTagsBase = loggerTagsFactory('move-file-system')
+const logger = createLogger('move-file-system')
export async function processMoveToFileSystem (job: Job) {
const payload = job.data as MoveStoragePayload
if (isMoveVideoStoragePayload(payload)) { // Move all video related files
- logger.info(`Moving video ${payload.videoUUID} to file system in job ${job.id}.`, lTagsBase(payload.videoUUID))
+ return logger.withContext([ payload.videoUUID ], async () => {
+ logger.info(`Moving video ${payload.videoUUID} to file system in job ${job.id}.`)
- return moveVideoToFS({
- videoUUID: payload.videoUUID,
- moveVideoState: payload.moveVideoState,
- loggerTags: lTagsBase().tags
+ return moveVideoToFS({ videoUUID: payload.videoUUID, moveVideoState: payload.moveVideoState })
})
} else if (isMoveCaptionPayload(payload)) { // Only caption file
- logger.info(`Moving video caption ${payload.captionId} to file system in job ${job.id}.`, lTagsBase(payload.captionId))
+ logger.info(`Moving video caption ${payload.captionId} to file system in job ${job.id}.`)
- return moveCaptionToFS({
- captionId: payload.captionId,
- loggerTags: lTagsBase().tags
- })
+ return moveCaptionToFS({ captionId: payload.captionId })
} else {
throw new Error('Unknown payload type')
}
@@ -33,9 +28,5 @@ export async function onMoveToFileSystemFailure (job: Job, err: any) {
if (!isMoveVideoStoragePayload(payload)) return
- await onMoveVideoToFSFailure({
- videoUUID: payload.videoUUID,
- err,
- loggerTags: lTagsBase().tags
- })
+ await logger.withContext([ payload.videoUUID ], () => onMoveVideoToFSFailure({ videoUUID: payload.videoUUID, err }))
}
diff --git a/server/core/lib/job-queue/handlers/move-to-object-storage.ts b/server/core/lib/job-queue/handlers/move-to-object-storage.ts
index 9b6900c5b4..bde991d182 100644
--- a/server/core/lib/job-queue/handlers/move-to-object-storage.ts
+++ b/server/core/lib/job-queue/handlers/move-to-object-storage.ts
@@ -1,5 +1,5 @@
import { isMoveCaptionPayload, isMoveVideoStoragePayload, MoveStoragePayload } from '@peertube/peertube-models'
-import { logger, loggerTagsFactory } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import {
moveCaptionToObjectStorage,
moveVideoToObjectStorage,
@@ -7,26 +7,21 @@ import {
} from '@server/lib/move-storage/move-to-object-storage.js'
import { Job } from 'bullmq'
-const lTagsBase = loggerTagsFactory('move-object-storage')
+const logger = createLogger('object-storage', 'move-object-storage')
export async function processMoveToObjectStorage (job: Job) {
const payload = job.data as MoveStoragePayload
if (isMoveVideoStoragePayload(payload)) { // Move all video related files
- logger.info(`Moving video ${payload.videoUUID} to object storage in job ${job.id}`, lTagsBase(payload.videoUUID))
+ await logger.withContext([ payload.videoUUID ], async () => {
+ logger.info(`Moving video ${payload.videoUUID} to object storage in job ${job.id}`)
- await moveVideoToObjectStorage({
- videoUUID: payload.videoUUID,
- moveVideoState: payload.moveVideoState,
- loggerTags: lTagsBase().tags
+ await moveVideoToObjectStorage({ videoUUID: payload.videoUUID, moveVideoState: payload.moveVideoState })
})
} else if (isMoveCaptionPayload(payload)) { // Only caption file
- logger.info(`Moving video caption ${payload.captionId} to object storage in job ${job.id}.`, lTagsBase(payload.captionId))
+ logger.info(`Moving video caption ${payload.captionId} to object storage in job ${job.id}.`)
- return moveCaptionToObjectStorage({
- captionId: payload.captionId,
- loggerTags: lTagsBase().tags
- })
+ return moveCaptionToObjectStorage({ captionId: payload.captionId })
} else {
throw new Error('Unknown payload type')
}
@@ -37,9 +32,5 @@ export async function onMoveToObjectStorageFailure (job: Job, err: any) {
if (!isMoveVideoStoragePayload(payload)) return
- await onMoveVideoToObjectStorageFailure({
- videoUUID: payload.videoUUID,
- err,
- loggerTags: lTagsBase().tags
- })
+ await logger.withContext([ payload.videoUUID ], () => onMoveVideoToObjectStorageFailure({ videoUUID: payload.videoUUID, err }))
}
diff --git a/server/core/lib/job-queue/handlers/notify.ts b/server/core/lib/job-queue/handlers/notify.ts
index 5a29104293..135e7f4333 100644
--- a/server/core/lib/job-queue/handlers/notify.ts
+++ b/server/core/lib/job-queue/handlers/notify.ts
@@ -2,7 +2,9 @@ import { Job } from 'bullmq'
import { Notifier } from '@server/lib/notifier/index.js'
import { VideoModel } from '@server/models/video/video.js'
import { NotifyPayload } from '@peertube/peertube-models'
-import { logger } from '../../../helpers/logger.js'
+import { createLogger } from '../../../helpers/logger.js'
+
+const logger = createLogger()
async function processNotify (job: Job) {
const payload = job.data as NotifyPayload
diff --git a/server/core/lib/job-queue/handlers/transcoding-job-builder.ts b/server/core/lib/job-queue/handlers/transcoding-job-builder.ts
index 726afbe808..e6a89326e5 100644
--- a/server/core/lib/job-queue/handlers/transcoding-job-builder.ts
+++ b/server/core/lib/job-queue/handlers/transcoding-job-builder.ts
@@ -4,9 +4,11 @@ import { UserModel } from '@server/models/user/user.js'
import { VideoJobInfoModel } from '@server/models/video/video-job-info.js'
import { VideoModel } from '@server/models/video/video.js'
import { Job } from 'bullmq'
-import { logger } from '../../../helpers/logger.js'
+import { createLogger } from '../../../helpers/logger.js'
import { JobQueue } from '../job-queue.js'
+const logger = createLogger()
+
/**
* Create transcoding jobs.
* They are not created directly so we can keep parent/children relationships using bullmq features
diff --git a/server/core/lib/job-queue/handlers/video-channel-import.ts b/server/core/lib/job-queue/handlers/video-channel-import.ts
index a92e1b6f1c..1d38ecfc39 100644
--- a/server/core/lib/job-queue/handlers/video-channel-import.ts
+++ b/server/core/lib/job-queue/handlers/video-channel-import.ts
@@ -1,5 +1,5 @@
import { Job } from 'bullmq'
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { CONFIG } from '@server/initializers/config.js'
import { synchronizeChannel } from '@server/lib/sync-channel.js'
import { VideoChannelModel } from '@server/models/video/video-channel.js'
@@ -7,6 +7,8 @@ import { VideoChannelSyncModel } from '@server/models/video/video-channel-sync.j
import { MChannelSync } from '@server/types/models/index.js'
import { VideoChannelImportPayload } from '@peertube/peertube-models'
+const logger = createLogger()
+
export async function processVideoChannelImport (job: Job) {
const payload = job.data as VideoChannelImportPayload
diff --git a/server/core/lib/job-queue/handlers/video-file-import.ts b/server/core/lib/job-queue/handlers/video-file-import.ts
index d51110f8e8..ecd249b163 100644
--- a/server/core/lib/job-queue/handlers/video-file-import.ts
+++ b/server/core/lib/job-queue/handlers/video-file-import.ts
@@ -11,10 +11,12 @@ import { VideoModel } from '@server/models/video/video.js'
import { MVideoFull } from '@server/types/models/index.js'
import { Job } from 'bullmq'
import { copy } from 'fs-extra/esm'
-import { logger } from '../../../helpers/logger.js'
+import { createLogger } from '../../../helpers/logger.js'
import { JobQueue } from '../job-queue.js'
-async function processVideoFileImport (job: Job) {
+const logger = createLogger()
+
+export async function processVideoFileImport (job: Job) {
const payload = job.data as VideoFileImportPayload
logger.info('Processing video file import in job %s.', job.id)
@@ -25,31 +27,29 @@ async function processVideoFileImport (job: Job) {
return undefined
}
- await updateVideoFile(video, payload.filePath)
-
- if (CONFIG.OBJECT_STORAGE.ENABLED) {
- await JobQueue.Instance.createJob(
- await buildMoveVideoJob({
- type: 'move-to-object-storage',
- video,
- moveVideoState: {
- previousVideoState: video.state
- }
- })
- )
- } else {
- scheduleVideoFederation({ video })
- }
-
- return video
+ return logger.withContext([ video.uuid ], async () => {
+ await updateVideoFile(video, payload.filePath)
+
+ if (CONFIG.OBJECT_STORAGE.ENABLED) {
+ await JobQueue.Instance.createJob(
+ await buildMoveVideoJob({
+ type: 'move-to-object-storage',
+ video,
+ moveVideoState: {
+ previousVideoState: video.state
+ }
+ })
+ )
+ } else {
+ scheduleVideoFederation({ video })
+ }
+
+ return video
+ })
}
// ---------------------------------------------------------------------------
-
-export {
- processVideoFileImport
-}
-
+// Private
// ---------------------------------------------------------------------------
async function updateVideoFile (video: MVideoFull, inputFilePath: string) {
diff --git a/server/core/lib/job-queue/handlers/video-import.ts b/server/core/lib/job-queue/handlers/video-import.ts
index 86cc4666e1..b66b0478af 100644
--- a/server/core/lib/job-queue/handlers/video-import.ts
+++ b/server/core/lib/job-queue/handlers/video-import.ts
@@ -34,7 +34,7 @@ import { Job } from 'bullmq'
import { FfprobeData } from 'fluent-ffmpeg'
import { move, remove } from 'fs-extra/esm'
import { stat } from 'fs/promises'
-import { logger } from '../../../helpers/logger.js'
+import { createLogger } from '../../../helpers/logger.js'
import { CONSTRAINTS_FIELDS, JOB_TTL } from '../../../initializers/constants.js'
import { sequelizeTypescript } from '../../../initializers/database.js'
import { VideoFileModel } from '../../../models/video/video-file.js'
@@ -45,46 +45,47 @@ import { Notifier } from '../../notifier/index.js'
import { createLocalVideoThumbnailsFromVideo } from '../../thumbnail.js'
import { JobQueue } from '../job-queue.js'
-async function processVideoImport (job: Job): Promise<VideoImportPreventExceptionResult> {
+const logger = createLogger()
+
+export async function processVideoImport (job: Job): Promise<VideoImportPreventExceptionResult> {
const payload = job.data as VideoImportPayload
const videoImport = await getVideoImportOrDie(payload)
- if (videoImport.state === VideoImportState.CANCELLED) {
- logger.info('Do not process import since it has been cancelled', { payload })
- return { resultType: 'success' }
- }
- if (videoImport.attempts >= CONFIG.IMPORT.VIDEOS.MAX_ATTEMPTS) {
- logger.info('Do not process import since it has reached the maximum number of attempts', { payload, attempts: videoImport.attempts })
-
- return { resultType: 'error' }
- }
+ return logger.withContext([ videoImport.Video.uuid ], async () => {
+ if (videoImport.state === VideoImportState.CANCELLED) {
+ logger.info('Do not process import since it has been cancelled', { payload })
+ return { resultType: 'success' }
+ }
- videoImport.attempts += 1
- videoImport.state = VideoImportState.PROCESSING
- await videoImport.save()
+ if (videoImport.attempts >= CONFIG.IMPORT.VIDEOS.MAX_ATTEMPTS) {
+ logger.info('Do not process import since it has reached the maximum number of attempts', { payload, attempts: videoImport.attempts })
- try {
- if (payload.type === 'youtube-dl') await processYoutubeDLImport(job, videoImport, payload)
- if (payload.type === 'magnet-uri' || payload.type === 'torrent-file') await processTorrentImport(job, videoImport, payload)
+ return { resultType: 'error' }
+ }
- return { resultType: 'success' }
- } catch (err) {
- // Processors already handle video import state change on error
+ videoImport.attempts += 1
+ videoImport.state = VideoImportState.PROCESSING
+ await videoImport.save()
- if (!payload.preventException) throw err
+ try {
+ if (payload.type === 'youtube-dl') await processYoutubeDLImport(job, videoImport, payload)
+ if (payload.type === 'magnet-uri' || payload.type === 'torrent-file') await processTorrentImport(job, videoImport, payload)
- logger.warn('Catch error in video import to send value to parent job.', { payload, err })
- return { resultType: 'error' }
- }
-}
+ return { resultType: 'success' }
+ } catch (err) {
+ // Processors already handle video import state change on error
-// ---------------------------------------------------------------------------
+ if (!payload.preventException) throw err
-export {
- processVideoImport
+ logger.warn('Catch error in video import to send value to parent job.', { payload, err })
+ return { resultType: 'error' }
+ }
+ })
}
+// ---------------------------------------------------------------------------
+// Private
// ---------------------------------------------------------------------------
async function processTorrentImport (job: Job, videoImport: MVideoImportDefault, payload: VideoImportTorrentPayload) {
diff --git a/server/core/lib/job-queue/handlers/video-live-ending.ts b/server/core/lib/job-queue/handlers/video-live-ending.ts
index 6f05a9b769..846d7dcaf9 100644
--- a/server/core/lib/job-queue/handlers/video-live-ending.ts
+++ b/server/core/lib/job-queue/handlers/video-live-ending.ts
@@ -45,80 +45,82 @@ import { Job } from 'bullmq'
import { pathExists, remove } from 'fs-extra/esm'
import { readdir } from 'fs/promises'
import { isAbsolute, join } from 'path'
-import { logger, loggerTagsFactory } from '../../../helpers/logger.js'
+import { createLogger } from '../../../helpers/logger.js'
-const lTags = loggerTagsFactory('live', 'job')
+const logger = createLogger('live', 'job')
export async function processVideoLiveEnding (job: Job) {
const payload = job.data as VideoLiveEndingPayload
- logger.info('Processing video live ending for %s.', payload.videoId, { payload, ...lTags() })
+ await logger.withContext([ payload.videoId ], async () => {
+ logger.info('Processing video live ending for %s.', payload.videoId, { payload })
- function logError () {
- logger.warn('Video live %d does not exist anymore. Cannot process live ending.', payload.videoId, lTags())
- }
-
- const video = await VideoModel.loadWithThumbnails(payload.videoId)
- const live = await VideoLiveModel.loadByVideoId(payload.videoId)
- const liveSession = await VideoLiveSessionModel.load(payload.liveSessionId)
-
- if (!video || !live || !liveSession) {
- logError()
- return
- }
-
- const permanentLive = live.permanentLive
+ function logError () {
+ logger.warn('Video live %d does not exist anymore. Cannot process live ending.', payload.videoId)
+ }
- liveSession.endingProcessed = true
- await liveSession.save()
+ const video = await VideoModel.loadWithThumbnails(payload.videoId)
+ const live = await VideoLiveModel.loadByVideoId(payload.videoId)
+ const liveSession = await VideoLiveSessionModel.load(payload.liveSessionId)
- if (liveSession.saveReplay !== true) {
- return cleanupLiveAndFederate({ permanentLive, video, streamingPlaylistId: payload.streamingPlaylistId })
- }
+ if (!video || !live || !liveSession) {
+ logError()
+ return
+ }
- let replayDirectory = payload.replayDirectory
+ const permanentLive = live.permanentLive
- if (!replayDirectory) {
- logger.info(`No replay directory found for live ${video.uuid}, skipping video replay creation.`, { ...lTags(video.uuid) })
+ liveSession.endingProcessed = true
+ await liveSession.save()
- return cleanupLiveAndFederate({ permanentLive, video, streamingPlaylistId: payload.streamingPlaylistId })
- }
+ if (liveSession.saveReplay !== true) {
+ return cleanupLiveAndFederate({ permanentLive, video, streamingPlaylistId: payload.streamingPlaylistId })
+ }
- // Introduced in PeerTube 7.2, allow to use the appropriate base directory even if the live privacy changed
- if (!isAbsolute(replayDirectory)) {
- replayDirectory = join(getLiveReplayBaseDirectory(video), replayDirectory)
- }
+ let replayDirectory = payload.replayDirectory
- const inputFileMutexReleaser = await VideoPathManager.Instance.lockFiles(video.uuid)
+ if (!replayDirectory) {
+ logger.info(`No replay directory found for live ${video.uuid}, skipping video replay creation.`)
- try {
- await video.reload()
+ return cleanupLiveAndFederate({ permanentLive, video, streamingPlaylistId: payload.streamingPlaylistId })
+ }
- if (await hasReplayFiles(replayDirectory) !== true) {
- logger.info(`No replay files found for live ${video.uuid}, skipping video replay creation.`, { ...lTags(video.uuid) })
+ // Introduced in PeerTube 7.2, allow to use the appropriate base directory even if the live privacy changed
+ if (!isAbsolute(replayDirectory)) {
+ replayDirectory = join(getLiveReplayBaseDirectory(video), replayDirectory)
+ }
- await cleanupLiveAndFederate({ permanentLive, video, streamingPlaylistId: payload.streamingPlaylistId })
- } else if (permanentLive) {
- await saveReplayToExternalVideo({
- liveVideo: video,
- liveSession,
- publishedAt: payload.publishedAt,
- replayDirectory
- })
+ const inputFileMutexReleaser = await VideoPathManager.Instance.lockFiles(video.uuid)
- await cleanupLiveAndFederate({ permanentLive, video, streamingPlaylistId: payload.streamingPlaylistId })
- } else {
- await replaceLiveByReplay({
- video,
- liveSession,
- live,
- permanentLive,
- replayDirectory
- })
+ try {
+ await video.reload()
+
+ if (await hasReplayFiles(replayDirectory) !== true) {
+ logger.info(`No replay files found for live ${video.uuid}, skipping video replay creation.`)
+
+ await cleanupLiveAndFederate({ permanentLive, video, streamingPlaylistId: payload.streamingPlaylistId })
+ } else if (permanentLive) {
+ await saveReplayToExternalVideo({
+ liveVideo: video,
+ liveSession,
+ publishedAt: payload.publishedAt,
+ replayDirectory
+ })
+
+ await cleanupLiveAndFederate({ permanentLive, video, streamingPlaylistId: payload.streamingPlaylistId })
+ } else {
+ await replaceLiveByReplay({
+ video,
+ liveSession,
+ live,
+ permanentLive,
+ replayDirectory
+ })
+ }
+ } finally {
+ inputFileMutexReleaser()
}
- } finally {
- inputFileMutexReleaser()
- }
+ })
}
// ---------------------------------------------------------------------------
@@ -140,8 +142,7 @@ async function saveReplayToExternalVideo (options: {
logger.warn(
'Live video %d or its replay settings %d do not exist anymore, skipping external replay creation.',
options.liveVideo.id,
- liveSession.replaySettingId,
- lTags()
+ liveSession.replaySettingId
)
return
}
@@ -173,63 +174,62 @@ async function saveReplayToExternalVideo (options: {
channelId: liveVideo.channelId
}) as MVideoWithAllFiles & MVideoTag
- replayVideo.Thumbnails = []
- replayVideo.VideoFiles = []
- replayVideo.VideoStreamingPlaylists = []
+ await logger.withContext([ replayVideo.uuid ], async () => {
+ replayVideo.Thumbnails = []
+ replayVideo.VideoFiles = []
+ replayVideo.VideoStreamingPlaylists = []
- replayVideo.url = getLocalVideoActivityPubUrl(replayVideo)
+ replayVideo.url = getLocalVideoActivityPubUrl(replayVideo)
- await replayVideo.save()
+ await replayVideo.save()
- await setVideoTags({ video: replayVideo, tags: liveVideo.Tags.map(t => t.name) })
+ await setVideoTags({ video: replayVideo, tags: liveVideo.Tags.map(t => t.name) })
- liveSession.replayVideoId = replayVideo.id
- await liveSession.save()
+ liveSession.replayVideoId = replayVideo.id
+ await liveSession.save()
- // If live is blacklisted, also blacklist the replay
- const blacklist = await VideoBlacklistModel.loadByVideoId(liveVideo.id)
- if (blacklist) {
- await VideoBlacklistModel.create({
- videoId: replayVideo.id,
- unfederated: blacklist.unfederated,
- reason: blacklist.reason,
- type: blacklist.type
- })
- }
+ // If live is blacklisted, also blacklist the replay
+ const blacklist = await VideoBlacklistModel.loadByVideoId(liveVideo.id)
+ if (blacklist) {
+ await VideoBlacklistModel.create({
+ videoId: replayVideo.id,
+ unfederated: blacklist.unfederated,
+ reason: blacklist.reason,
+ type: blacklist.type
+ })
+ }
- // Inherit player settings
- const playerSettings = await PlayerSettingModel.loadByVideoId(liveVideo.id)
- if (playerSettings) {
- await PlayerSettingModel.create({
- videoId: replayVideo.id,
- theme: playerSettings.theme
- })
- }
+ // Inherit player settings
+ const playerSettings = await PlayerSettingModel.loadByVideoId(liveVideo.id)
+ if (playerSettings) {
+ await PlayerSettingModel.create({
+ videoId: replayVideo.id,
+ theme: playerSettings.theme
+ })
+ }
- // Inherit video embed privacy
- const domains = await VideoEmbedPrivacyDomainModel.list(liveVideo.id)
- if (domains.length !== 0) {
- await VideoEmbedPrivacyDomainModel.addDomains(domains.map(d => d.domain), replayVideo.id)
- }
+ // Inherit video embed privacy
+ const domains = await VideoEmbedPrivacyDomainModel.list(liveVideo.id)
+ if (domains.length !== 0) {
+ await VideoEmbedPrivacyDomainModel.addDomains(domains.map(d => d.domain), replayVideo.id)
+ }
- await assignReplayFilesToVideo({ video: replayVideo, replayDirectory })
+ await assignReplayFilesToVideo({ video: replayVideo, replayDirectory })
- logger.info(`Removing replay directory ${replayDirectory}`, lTags(liveVideo.uuid))
- await remove(replayDirectory)
+ logger.info(`Removing replay directory ${replayDirectory}`)
+ await remove(replayDirectory)
- try {
- await copyOrRegenerateThumbnails({ liveVideo, replayVideo })
- } catch (err) {
- logger.error(
- `Cannot copy/regenerate thumbnails of ended live ${liveVideo.uuid} to external video ${replayVideo.uuid}`,
- lTags(liveVideo.uuid, replayVideo.uuid)
- )
- }
+ try {
+ await copyOrRegenerateThumbnails({ liveVideo, replayVideo })
+ } catch (err) {
+ logger.error(`Cannot copy/regenerate thumbnails of ended live ${liveVideo.uuid} to external video ${replayVideo.uuid}`)
+ }
- await createStoryboardJob(replayVideo)
- await createTranscriptionTaskIfNeeded(replayVideo)
+ await createStoryboardJob(replayVideo)
+ await createTranscriptionTaskIfNeeded(replayVideo)
- await moveToNextState({ video: replayVideo })
+ await moveToNextState({ video: replayVideo })
+ })
}
async function copyOrRegenerateThumbnails (options: {
@@ -276,8 +276,7 @@ async function replaceLiveByReplay (options: {
logger.warn(
'Live video %d or its replay settings %d do not exist anymore, skipping live-to-replay replacement.',
liveVideo.id,
- liveSession.replaySettingId,
- lTags()
+ liveSession.replaySettingId
)
return
}
@@ -285,7 +284,7 @@ async function replaceLiveByReplay (options: {
const hlsPlaylist = videoWithFiles.getHLSPlaylist()
const replayInAnotherDirectory = isVideoInPublicDirectory(liveVideo.privacy) !== isVideoInPublicDirectory(replaySettings.privacy)
- logger.info(`Replacing live ${liveVideo.uuid} by replay ${replayDirectory}.`, { replayInAnotherDirectory, ...lTags(liveVideo.uuid) })
+ logger.info(`Replacing live ${liveVideo.uuid} by replay ${replayDirectory}.`, { replayInAnotherDirectory })
await cleanupTMPLiveFiles(videoWithFiles, hlsPlaylist)
@@ -328,7 +327,7 @@ async function replaceLiveByReplay (options: {
try {
await regenerateLocalVideoThumbnailsFromVideoIfNeeded(videoWithFiles, undefined)
} catch (err) {
- logger.error(`Cannot regenerate thumbnails of ended live ${videoWithFiles.uuid}`, lTags(liveVideo.uuid))
+ logger.error(`Cannot regenerate thumbnails of ended live ${videoWithFiles.uuid}`)
}
// We consider this is a new video
@@ -346,7 +345,7 @@ async function assignReplayFilesToVideo (options: {
const concatenatedTsFiles = await readdir(replayDirectory)
- logger.info(`Assigning replays ${replayDirectory} to video ${video.uuid}.`, { concatenatedTsFiles, ...lTags(video.uuid) })
+ logger.info(`Assigning replays ${replayDirectory} to video ${video.uuid}.`, { concatenatedTsFiles })
for (const concatenatedTsFile of concatenatedTsFiles) {
// Generating hls playlist can be long, reload the video in this case
diff --git a/server/core/lib/job-queue/handlers/video-redundancy.ts b/server/core/lib/job-queue/handlers/video-redundancy.ts
index b4c96219c9..bc0c26952f 100644
--- a/server/core/lib/job-queue/handlers/video-redundancy.ts
+++ b/server/core/lib/job-queue/handlers/video-redundancy.ts
@@ -1,7 +1,9 @@
import { Job } from 'bullmq'
import { VideosRedundancyScheduler } from '@server/lib/schedulers/videos-redundancy-scheduler.js'
import { VideoRedundancyPayload } from '@peertube/peertube-models'
-import { logger } from '../../../helpers/logger.js'
+import { createLogger } from '../../../helpers/logger.js'
+
+const logger = createLogger()
async function processVideoRedundancy (job: Job) {
const payload = job.data as VideoRedundancyPayload
diff --git a/server/core/lib/job-queue/handlers/video-stats.ts b/server/core/lib/job-queue/handlers/video-stats.ts
index 916d091944..c7a9765bb1 100644
--- a/server/core/lib/job-queue/handlers/video-stats.ts
+++ b/server/core/lib/job-queue/handlers/video-stats.ts
@@ -1,9 +1,11 @@
import { isTestOrDevInstance } from '@peertube/peertube-node-utils'
import { VideoStatModel } from '@server/models/stat/video-stat.js'
-import { logger } from '../../../helpers/logger.js'
+import { createLogger } from '../../../helpers/logger.js'
import { VideoModel } from '../../../models/video/video.js'
import { Redis } from '../../redis.js'
+const logger = createLogger()
+
/**
* Add number of stats grabbed in a time-range to the database, so we can calculate stats timeseries
*/
diff --git a/server/core/lib/job-queue/handlers/video-studio-edition.ts b/server/core/lib/job-queue/handlers/video-studio-edition.ts
index b112baa56f..5c9d791057 100644
--- a/server/core/lib/job-queue/handlers/video-studio-edition.ts
+++ b/server/core/lib/job-queue/handlers/video-studio-edition.ts
@@ -26,97 +26,97 @@ import { MutexInterface } from 'async-mutex'
import { Job } from 'bullmq'
import { remove } from 'fs-extra/esm'
import { extname, join } from 'path'
-import { logger, loggerTagsFactory } from '../../../helpers/logger.js'
+import { createLogger } from '../../../helpers/logger.js'
import { buildPromiseForAbortSignal } from './shared/job-helpers.js'
-const lTagsBase = loggerTagsFactory('video-studio')
+const logger = createLogger('studio')
async function processVideoStudioEdition (job: Job, abortSignal?: AbortSignal) {
const abortPromise = buildPromiseForAbortSignal(abortSignal)
- const run = async () => {
- const payload = job.data as VideoStudioEditionPayload
- const lTags = lTagsBase(payload.videoUUID)
+ const payload = job.data as VideoStudioEditionPayload
- logger.info('Process video studio edition of %s in job %s.', payload.videoUUID, job.id, lTags)
+ // Inner functions (processTask, buildFFmpegEdition...) inherit these tags without having to inject them
+ const run = () =>
+ logger.withContext([ payload.videoUUID ], async () => {
+ logger.info('Process video studio edition of %s in job %s.', payload.videoUUID, job.id)
- let inputFileMutexReleaser = await VideoPathManager.Instance.lockFiles(payload.videoUUID)
+ let inputFileMutexReleaser = await VideoPathManager.Instance.lockFiles(payload.videoUUID)
- try {
- const video = await VideoModel.loadFull(payload.videoUUID)
+ try {
+ const video = await VideoModel.loadFull(payload.videoUUID)
- // No video, maybe deleted?
- if (!video) {
- logger.info('Can\'t process job %d, video does not exist.', job.id, lTags)
+ // No video, maybe deleted?
+ if (!video) {
+ logger.info('Can\'t process job %d, video does not exist.', job.id)
- await safeCleanupStudioTMPFiles(payload.tasks)
- return undefined
- }
+ await safeCleanupStudioTMPFiles(payload.tasks)
+ return undefined
+ }
- await checkUserQuotaOrThrow(video, payload)
+ await checkUserQuotaOrThrow(video, payload)
- await video.reload()
+ await video.reload()
- const editionResultPath = await VideoPathManager.Instance.makeAvailableMaxQualityFiles(video, async ({
- videoPath: originalVideoFilePath,
- separatedAudioPath
- }) => {
- let tmpInputFilePath: string
- let outputPath: string
+ const editionResultPath = await VideoPathManager.Instance.makeAvailableMaxQualityFiles(video, async ({
+ videoPath: originalVideoFilePath,
+ separatedAudioPath
+ }) => {
+ let tmpInputFilePath: string
+ let outputPath: string
- for (const task of payload.tasks) {
- const outputFilename = buildUUID() + extname(originalVideoFilePath)
- outputPath = join(CONFIG.STORAGE.TMP_DIR, outputFilename)
+ for (const task of payload.tasks) {
+ const outputFilename = buildUUID() + extname(originalVideoFilePath)
+ outputPath = join(CONFIG.STORAGE.TMP_DIR, outputFilename)
- await processTask({
- videoInputPath: tmpInputFilePath ?? originalVideoFilePath,
+ await processTask({
+ videoInputPath: tmpInputFilePath ?? originalVideoFilePath,
- separatedAudioInputPath: tmpInputFilePath
- ? undefined
- : separatedAudioPath,
+ separatedAudioInputPath: tmpInputFilePath
+ ? undefined
+ : separatedAudioPath,
- inputFileMutexReleaser,
+ inputFileMutexReleaser,
- video,
- outputPath,
- task,
- lTags,
+ video,
+ outputPath,
+ task,
- abortSignal
- })
+ abortSignal
+ })
- if (tmpInputFilePath) await remove(tmpInputFilePath)
+ if (tmpInputFilePath) await remove(tmpInputFilePath)
- // For the next iteration
- tmpInputFilePath = outputPath
- inputFileMutexReleaser = undefined
- }
+ // For the next iteration
+ tmpInputFilePath = outputPath
+ inputFileMutexReleaser = undefined
+ }
+
+ return outputPath
+ })
- return outputPath
- })
+ logger.info('Video edition ended for video %s.', video.uuid)
- logger.info('Video edition ended for video %s.', video.uuid, lTags)
+ await onVideoStudioEnded({ video, editionResultPath, tasks: payload.tasks })
+ } catch (err) {
+ await safeCleanupStudioTMPFiles(payload.tasks)
- await onVideoStudioEnded({ video, editionResultPath, tasks: payload.tasks })
- } catch (err) {
- await safeCleanupStudioTMPFiles(payload.tasks)
+ try {
+ await sequelizeTypescript.transaction(async transaction => {
+ const video = await VideoModel.load(payload.videoUUID, transaction)
+ if (!video || video.state === VideoState.PUBLISHED) return
- try {
- await sequelizeTypescript.transaction(async transaction => {
- const video = await VideoModel.load(payload.videoUUID, transaction)
- if (!video || video.state === VideoState.PUBLISHED) return
+ await video.setNewStateAndPublishedAt({ newState: VideoState.PUBLISHED, transaction })
+ })
+ } catch (err) {
+ logger.error('Cannot reset video state after studio error', { err })
+ }
- await video.setNewStateAndPublishedAt({ newState: VideoState.PUBLISHED, transaction })
- })
- } catch (err) {
- logger.error('Cannot reset video state after studio error', { err, ...lTags })
+ throw err
+ } finally {
+ if (inputFileMutexReleaser) inputFileMutexReleaser()
}
-
- throw err
- } finally {
- if (inputFileMutexReleaser) inputFileMutexReleaser()
- }
- }
+ })
return Promise.race([ run(), abortPromise ])
}
@@ -138,7 +138,6 @@ type TaskProcessorOptions<T extends VideoStudioTaskPayload = VideoStudioTaskPayl
outputPath: string
video: MVideo
task: T
- lTags: { tags: (string | number)[] }
abortSignal?: AbortSignal
}
@@ -152,9 +151,9 @@ const taskProcessors: { [id in VideoStudioTask['name']]: (options: TaskProcessor
}
async function processTask (options: TaskProcessorOptions) {
- const { video, task, lTags } = options
+ const { video, task } = options
- logger.info('Processing %s task for video %s.', task.name, video.uuid, { task, ...lTags })
+ logger.info('Processing %s task for video %s.', task.name, video.uuid, { task })
const processor = taskProcessors[options.task.name]
if (!process) throw new Error('Unknown task ' + task.name)
@@ -163,9 +162,9 @@ async function processTask (options: TaskProcessorOptions) {
}
function processAddIntroOutro (options: TaskProcessorOptions<VideoStudioTaskIntroPayload | VideoStudioTaskOutroPayload>) {
- const { task, lTags, abortSignal } = options
+ const { task, abortSignal } = options
- logger.debug('Will add intro/outro to the video.', { options, ...lTags })
+ logger.debug('Will add intro/outro to the video.', { options })
return buildFFmpegEdition(abortSignal).addIntroOutro({
...pick(options, [ 'inputFileMutexReleaser', 'videoInputPath', 'separatedAudioInputPath', 'outputPath' ]),
@@ -178,9 +177,9 @@ function processAddIntroOutro (options: TaskProcessorOptions<VideoStudioTaskIntr
}
function processCut (options: TaskProcessorOptions<VideoStudioTaskCutPayload>) {
- const { task, lTags, abortSignal } = options
+ const { task, abortSignal } = options
- logger.debug('Will cut the video.', { options, ...lTags })
+ logger.debug('Will cut the video.', { options })
return buildFFmpegEdition(abortSignal).cutVideo({
...pick(options, [ 'inputFileMutexReleaser', 'videoInputPath', 'separatedAudioInputPath', 'outputPath' ]),
@@ -191,9 +190,9 @@ function processCut (options: TaskProcessorOptions<VideoStudioTaskCutPayload>) {
}
function processRemoveSegments (options: TaskProcessorOptions<VideoStudioTaskRemoveSegmentsPayload>) {
- const { task, lTags, abortSignal } = options
+ const { task, abortSignal } = options
- logger.debug('Will remove segments from the video.', { options, ...lTags })
+ logger.debug('Will remove segments from the video.', { options })
return buildFFmpegEdition(abortSignal).removeSegments({
...pick(options, [ 'inputFileMutexReleaser', 'videoInputPath', 'separatedAudioInputPath', 'outputPath' ]),
@@ -203,9 +202,9 @@ function processRemoveSegments (options: TaskProcessorOptions<VideoStudioTaskRem
}
function processAddWatermark (options: TaskProcessorOptions<VideoStudioTaskWatermarkPayload>) {
- const { task, lTags, abortSignal } = options
+ const { task, abortSignal } = options
- logger.debug('Will add watermark to the video.', { options, ...lTags })
+ logger.debug('Will add watermark to the video.', { options })
return buildFFmpegEdition(abortSignal).addWatermark({
...pick(options, [ 'inputFileMutexReleaser', 'videoInputPath', 'separatedAudioInputPath', 'outputPath' ]),
diff --git a/server/core/lib/job-queue/handlers/video-transcoding.ts b/server/core/lib/job-queue/handlers/video-transcoding.ts
index 7bf1c74545..81e71161cb 100644
--- a/server/core/lib/job-queue/handlers/video-transcoding.ts
+++ b/server/core/lib/job-queue/handlers/video-transcoding.ts
@@ -6,6 +6,7 @@ import {
VideoResolution,
VideoTranscodingPayload
} from '@peertube/peertube-models'
+import { createLogger } from '@server/helpers/logger.js'
import { CONFIG } from '@server/initializers/config.js'
import { hasMissingHLSStreams } from '@server/lib/runners/job-handlers/shared/utils.js'
import { onTranscodingEnded } from '@server/lib/transcoding/ended-transcoding.js'
@@ -18,10 +19,11 @@ import { UserModel } from '@server/models/user/user.js'
import { VideoJobInfoModel } from '@server/models/video/video-job-info.js'
import { MUser, MVideoFull } from '@server/types/models/index.js'
import { Job } from 'bullmq'
-import { logger, loggerTagsFactory } from '../../../helpers/logger.js'
import { VideoModel } from '../../../models/video/video.js'
import { buildPromiseForAbortSignal } from './shared/job-helpers.js'
+const logger = createLogger('transcoding')
+
type HandlerFunction = (options: {
job: Job
payload: VideoTranscodingPayload
@@ -37,44 +39,45 @@ const handlers: { [id in VideoTranscodingPayload['type']]: HandlerFunction } = {
'optimize-to-web-video': handleWebVideoOptimizeJob
}
-const lTags = loggerTagsFactory('transcoding')
-
async function processVideoTranscoding (job: Job, abortSignal: AbortSignal) {
const abortPromise = buildPromiseForAbortSignal(abortSignal)
- const run = async () => {
+ const run = () => {
const payload = job.data as VideoTranscodingPayload
- logger.info('Processing transcoding job %s.', job.id, lTags(payload.videoUUID))
- const video = await VideoModel.loadFull(payload.videoUUID)
- // No video, maybe deleted?
- if (!video) {
- logger.info(`Do not process job ${job.id}, video does not exist.`, lTags(payload.videoUUID))
- return undefined
- }
+ return logger.withContext([ payload.videoUUID ], async () => {
+ logger.info('Processing transcoding job %s.', job.id)
+
+ const video = await VideoModel.loadFull(payload.videoUUID)
+ // No video, maybe deleted?
+ if (!video) {
+ logger.info(`Do not process job ${job.id}, video does not exist.`)
+ return undefined
+ }
- const user = await UserModel.loadByChannelActorId(video.VideoChannel.Actor.id)
+ const user = await UserModel.loadByChannelActorId(video.VideoChannel.Actor.id)
- const handler = handlers[payload.type]
+ const handler = handlers[payload.type]
- if (!handler) {
- await moveToFailedTranscodingState(video)
- await VideoJobInfoModel.decrease(video.uuid, 'pendingTranscode')
+ if (!handler) {
+ await moveToFailedTranscodingState(video)
+ await VideoJobInfoModel.decrease(video.uuid, 'pendingTranscode')
- throw new Error('Cannot find transcoding handler for ' + payload.type)
- }
+ throw new Error('Cannot find transcoding handler for ' + payload.type)
+ }
- try {
- await handler({ job, payload, video, user, abortSignal })
- } catch (error) {
- await moveToFailedTranscodingState(video)
+ try {
+ await handler({ job, payload, video, user, abortSignal })
+ } catch (error) {
+ await moveToFailedTranscodingState(video)
- await VideoJobInfoModel.decrease(video.uuid, 'pendingTranscode')
+ await VideoJobInfoModel.decrease(video.uuid, 'pendingTranscode')
- throw error
- }
+ throw error
+ }
- return video
+ return video
+ })
}
return Promise.race([ run(), abortPromise ])
@@ -99,11 +102,11 @@ async function handleWebVideoMergeAudioJob (options: {
}) {
const { job, payload, video, abortSignal } = options
- logger.info('Handling merge audio transcoding job for %s.', video.uuid, lTags(video.uuid), { payload })
+ logger.info('Handling merge audio transcoding job for %s.', video.uuid, { payload })
await mergeAudioVideofile({ video, resolution: payload.resolution, fps: payload.fps, job, abortSignal })
- logger.info('Merge audio transcoding job for %s ended.', video.uuid, lTags(video.uuid), { payload })
+ logger.info('Merge audio transcoding job for %s ended.', video.uuid, { payload })
await onTranscodingEnded({ moveVideoToNextState: payload.canMoveVideoState, video })
}
@@ -117,11 +120,11 @@ async function handleWebVideoOptimizeJob (options: {
}) {
const { job, payload, video, abortSignal } = options
- logger.info('Handling optimize transcoding job for %s.', video.uuid, lTags(video.uuid), { payload })
+ logger.info('Handling optimize transcoding job for %s.', video.uuid, { payload })
await optimizeOriginalVideofile({ video, job, abortSignal })
- logger.info('Optimize transcoding job for %s ended.', video.uuid, lTags(video.uuid), { payload })
+ logger.info('Optimize transcoding job for %s ended.', video.uuid, { payload })
await onTranscodingEnded({ moveVideoToNextState: payload.canMoveVideoState, video })
}
@@ -137,11 +140,11 @@ async function handleNewWebVideoResolutionJob (options: {
}) {
const { job, payload, video, abortSignal } = options
- logger.info('Handling Web Video transcoding job for %s.', video.uuid, lTags(video.uuid), { payload })
+ logger.info('Handling Web Video transcoding job for %s.', video.uuid, { payload })
await transcodeNewWebVideoResolution({ video, resolution: payload.resolution, fps: payload.fps, job, abortSignal })
- logger.info('Web Video transcoding job for %s ended.', video.uuid, lTags(video.uuid), { payload })
+ logger.info('Web Video transcoding job for %s ended.', video.uuid, { payload })
// Always move video to next state, we're ready enough with this resolution
await onTranscodingEnded({ moveVideoToNextState: payload.canMoveVideoState, video })
@@ -158,7 +161,7 @@ async function handleHLSJob (options: {
}) {
const { job, payload, video: videoArg, abortSignal } = options
- logger.info('Handling HLS transcoding job for %s.', videoArg.uuid, lTags(videoArg.uuid), { payload })
+ logger.info('Handling HLS transcoding job for %s.', videoArg.uuid, { payload })
const inputFileMutexReleaser = await VideoPathManager.Instance.lockFiles(videoArg.uuid)
let video: MVideoFull
@@ -192,7 +195,7 @@ async function handleHLSJob (options: {
inputFileMutexReleaser()
}
- logger.info('HLS transcoding job for %s ended.', video.uuid, lTags(video.uuid), { payload })
+ logger.info('HLS transcoding job for %s ended.', video.uuid, { payload })
const missingStream = await hasMissingHLSStreams({
inputStreams: payload.inputStreams,
@@ -205,10 +208,7 @@ async function handleHLSJob (options: {
? [ VideoResolution.H_NOVIDEO ]
: []
- logger.info('Removing Web Video files of %s now we have a HLS version of it.', video.uuid, {
- resolutionExceptions,
- ...lTags(video.uuid)
- })
+ logger.info('Removing Web Video files of %s now we have a HLS version of it.', video.uuid, { resolutionExceptions })
await removeAllWebVideoFiles(video, { resolutionExceptions })
}
diff --git a/server/core/lib/job-queue/handlers/video-transcription.ts b/server/core/lib/job-queue/handlers/video-transcription.ts
index 027a3b7da8..a88c03f2f0 100644
--- a/server/core/lib/job-queue/handlers/video-transcription.ts
+++ b/server/core/lib/job-queue/handlers/video-transcription.ts
@@ -1,11 +1,11 @@
import { VideoTranscriptionPayload } from '@peertube/peertube-models'
import { generateSubtitle } from '@server/lib/video-captions.js'
import { Job } from 'bullmq'
-import { logger, loggerTagsFactory } from '../../../helpers/logger.js'
+import { createLogger } from '../../../helpers/logger.js'
import { VideoModel } from '../../../models/video/video.js'
import { buildPromiseForAbortSignal } from './shared/job-helpers.js'
-const lTags = loggerTagsFactory('transcription')
+const logger = createLogger('transcription')
export async function processVideoTranscription (job: Job, abortSignal?: AbortSignal) {
const abortPromise = buildPromiseForAbortSignal(abortSignal)
@@ -13,15 +13,17 @@ export async function processVideoTranscription (job: Job, abortSignal?: AbortSi
const run = async () => {
const payload = job.data as VideoTranscriptionPayload
- logger.info('Processing video transcription in job %s.', job.id)
+ await logger.withContext([ payload.videoUUID ], async () => {
+ logger.info('Processing video transcription in job %s.', job.id)
- const video = await VideoModel.load(payload.videoUUID)
- if (!video) {
- logger.info('Do not process transcription job %d, video does not exist.', job.id, lTags(payload.videoUUID))
- return
- }
+ const video = await VideoModel.load(payload.videoUUID)
+ if (!video) {
+ logger.info('Do not process transcription job %d, video does not exist.', job.id)
+ return
+ }
- return generateSubtitle({ video, signal: abortSignal })
+ return generateSubtitle({ video, signal: abortSignal })
+ })
}
return Promise.race([ run(), abortPromise ])
diff --git a/server/core/lib/job-queue/job-queue.ts b/server/core/lib/job-queue/job-queue.ts
index a978bbe7c1..4e29f431bf 100644
--- a/server/core/lib/job-queue/job-queue.ts
+++ b/server/core/lib/job-queue/job-queue.ts
@@ -43,7 +43,7 @@ import {
Worker,
WorkerOptions
} from 'bullmq'
-import { logger } from '../../helpers/logger.js'
+import { createLogger } from '../../helpers/logger.js'
import { JOB_ATTEMPTS, JOB_CONCURRENCY, JOB_REMOVAL_OPTIONS, JOB_TTL, REPEAT_JOBS, WEBSERVER } from '../../initializers/constants.js'
import { Hooks } from '../plugins/hooks.js'
import { Redis } from '../redis.js'
@@ -78,6 +78,8 @@ import { processVideoStudioEdition } from './handlers/video-studio-edition.js'
import { processVideoTranscoding } from './handlers/video-transcoding.js'
import { processVideoTranscription } from './handlers/video-transcription.js'
+const logger = createLogger('job-queue')
+
export type CreateJobTypeAndPayload =
| { type: 'build-automatic-tags', payload: BuildAutomaticTagsPayload }
| { type: 'activitypub-http-broadcast', payload: ActivitypubHttpBroadcastPayload }
@@ -262,10 +264,13 @@ class JobQueue {
.finally(() => clearTimeout(timeoutId))
}
- const processor = async (jobArg: Job, _, signal: AbortSignal) => {
- const job = await Hooks.wrapObject(jobArg, 'filter:job-queue.process.params', { type: handlerName })
+ const processor = (jobArg: Job, _, signal: AbortSignal) => {
+ // So every logger call performed by the handler is tagged with the job, without having to inject tags manually
+ return logger.withContext([ handlerName, jobArg.id ], async () => {
+ const job = await Hooks.wrapObject(jobArg, 'filter:job-queue.process.params', { type: handlerName })
- return Hooks.wrapPromiseFun(handler, { job, signal }, 'filter:job-queue.process.result')
+ return Hooks.wrapPromiseFun(handler, { job, signal }, 'filter:job-queue.process.result')
+ })
}
const worker = new Worker(handlerName, processor, workerOptions)
diff --git a/server/core/lib/live/live-manager.ts b/server/core/lib/live/live-manager.ts
index f9e2cec727..55dd52be46 100644
--- a/server/core/lib/live/live-manager.ts
+++ b/server/core/lib/live/live-manager.ts
@@ -9,7 +9,7 @@ import {
} from '@peertube/peertube-ffmpeg'
import { LiveVideoError, LiveVideoErrorType, VideoResolution, VideoState } from '@peertube/peertube-models'
import { retryTransactionWrapper } from '@server/helpers/database-utils.js'
-import { logger, loggerTagsFactory } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { CONFIG, registerConfigChangedHandler } from '@server/initializers/config.js'
import { VIDEO_LIVE, WEBSERVER } from '@server/initializers/constants.js'
import { sequelizeTypescript } from '@server/initializers/database.js'
@@ -41,6 +41,8 @@ import { LiveQuotaStore } from './live-quota-store.js'
import { cleanupAndDestroyPermanentLive, getLiveSegmentTime } from './live-utils.js'
import { MuxingSession } from './shared/index.js'
+const logger = createLogger('live')
+
// Disable node media server logs
nodeMediaServerLogger.setLogType(0)
@@ -54,8 +56,6 @@ const config = {
}
}
-const lTags = loggerTagsFactory('live')
-
class LiveManager {
private static instance: LiveManager
@@ -77,28 +77,32 @@ class LiveManager {
init () {
const events = this.getContext().nodeEvent
events.on('postPublish', (sessionId: string, streamPath: string) => {
- // Don't log streamPath: it contains the stream key, which is a long lived secret
- logger.debug('RTMP received stream', { id: sessionId, ...lTags(sessionId) })
-
- const splittedPath = streamPath.split('/')
- if (splittedPath.length !== 3 || splittedPath[1] !== VIDEO_LIVE.RTMP.BASE_PATH) {
- logger.warn('Live path is incorrect.', { ...lTags(sessionId) })
- return this.abortSession(sessionId)
- }
+ logger.withContext([ sessionId ], () => {
+ // Don't log streamPath: it contains the stream key, which is a long lived secret
+ logger.debug('RTMP received stream', { id: sessionId })
+
+ const splittedPath = streamPath.split('/')
+ if (splittedPath.length !== 3 || splittedPath[1] !== VIDEO_LIVE.RTMP.BASE_PATH) {
+ logger.warn('Live path is incorrect.')
+ return this.abortSession(sessionId)
+ }
- const session = this.getContext().sessions.get(sessionId)
- const inputLocalUrl = session.inputOriginLocalUrl + streamPath
- const inputPublicUrl = session.inputOriginPublicUrl + streamPath
+ const session = this.getContext().sessions.get(sessionId)
+ const inputLocalUrl = session.inputOriginLocalUrl + streamPath
+ const inputPublicUrl = session.inputOriginPublicUrl + streamPath
- this.handleSession({ sessionId, inputPublicUrl, inputLocalUrl, streamKey: splittedPath[2] })
- .catch(err => logger.error('Cannot handle session', { err, ...lTags(sessionId) }))
+ this.handleSession({ sessionId, inputPublicUrl, inputLocalUrl, streamKey: splittedPath[2] })
+ .catch(err => logger.error('Cannot handle session', { err }))
+ })
})
events.on('donePublish', (sessionId: string) => {
- logger.info('Live session ended.', { sessionId, ...lTags(sessionId) })
+ logger.withContext([ sessionId ], () => {
+ logger.info('Live session ended.', { sessionId })
- // Force session aborting, so we kill ffmpeg even if it still has data to process (slow CPU)
- setTimeout(() => this.abortSession(sessionId), VIDEO_LIVE.ABORT_DELAY_ON_RTMP_DISCONNECT)
+ // Force session aborting, so we kill ffmpeg even if it still has data to process (slow CPU)
+ setTimeout(() => this.abortSession(sessionId), VIDEO_LIVE.ABORT_DELAY_ON_RTMP_DISCONNECT)
+ })
})
registerConfigChangedHandler(() => {
@@ -114,14 +118,14 @@ class LiveManager {
// Cleanup broken lives, that were terminated by a server restart for example
this.handleBrokenLives()
- .catch(err => logger.error('Cannot handle broken lives.', { err, ...lTags() }))
+ .catch(err => logger.error('Cannot handle broken lives.', { err }))
}
async run () {
this.running = true
if (CONFIG.LIVE.RTMP.ENABLED) {
- logger.info('Running RTMP server on port %d', CONFIG.LIVE.RTMP.PORT, lTags())
+ logger.info('Running RTMP server on port %d', CONFIG.LIVE.RTMP.PORT)
this.rtmpServer = createServer(socket => {
const session = new NodeRtmpSession(config, socket)
@@ -132,14 +136,14 @@ class LiveManager {
})
this.rtmpServer.on('error', err => {
- logger.error('Cannot run RTMP server.', { err, ...lTags() })
+ logger.error('Cannot run RTMP server.', { err })
})
this.rtmpServer.listen(CONFIG.LIVE.RTMP.PORT, CONFIG.LIVE.RTMP.HOSTNAME)
}
if (CONFIG.LIVE.RTMPS.ENABLED) {
- logger.info('Running RTMPS server on port %d', CONFIG.LIVE.RTMPS.PORT, lTags())
+ logger.info('Running RTMPS server on port %d', CONFIG.LIVE.RTMPS.PORT)
const [ key, cert ] = await Promise.all([
readFile(CONFIG.LIVE.RTMPS.KEY_FILE),
@@ -156,7 +160,7 @@ class LiveManager {
})
this.rtmpsServer.on('error', err => {
- logger.error('Cannot run RTMPS server.', { err, ...lTags() })
+ logger.error('Cannot run RTMPS server.', { err })
})
this.rtmpsServer.listen(CONFIG.LIVE.RTMPS.PORT, CONFIG.LIVE.RTMPS.HOSTNAME)
@@ -167,14 +171,14 @@ class LiveManager {
this.running = false
if (this.rtmpServer) {
- logger.info('Stopping RTMP server.', lTags())
+ logger.info('Stopping RTMP server.')
this.rtmpServer.close()
this.rtmpServer = undefined
}
if (this.rtmpsServer) {
- logger.info('Stopping RTMPS server.', lTags())
+ logger.info('Stopping RTMPS server.')
this.rtmpsServer.close()
this.rtmpsServer = undefined
@@ -202,33 +206,33 @@ class LiveManager {
const { videoUUID, expectedSessionId, error } = options
const sessionId = this.videoSessions.get(videoUUID)
+
if (!sessionId) {
- logger.debug('No live session to stop for video %s', videoUUID, lTags(sessionId, videoUUID))
+ logger.debug('No live session to stop for video %s', videoUUID)
return
}
- if (expectedSessionId && expectedSessionId !== sessionId) {
- logger.debug(
- `No live session ${expectedSessionId} to stop for video ${videoUUID} (current session: ${sessionId})`,
- lTags(sessionId, videoUUID)
- )
- return
- }
+ await logger.withContext([ videoUUID ], async () => {
+ if (expectedSessionId && expectedSessionId !== sessionId) {
+ logger.debug(`No live session ${expectedSessionId} to stop for video ${videoUUID} (current session: ${sessionId})`)
+ return
+ }
- this.videoSessions.delete(videoUUID)
+ this.videoSessions.delete(videoUUID)
- logger.info('Stopping live session of video %s', videoUUID, { error, ...lTags(sessionId, videoUUID) })
+ logger.info('Stopping live session of video %s', videoUUID, { error })
- // Await the ending session write before tearing down: abortSession() triggers ffmpeg shutdown,
- // which eventually fires 'after-cleanup' and onAfterMuxingCleanup() reading this same row
- // So this write must be committed first to avoid two unsynchronized writers racing on it
- try {
- await this.saveEndingSession(options)
- } catch (err) {
- logger.error('Cannot save ending session.', { err, ...lTags(sessionId, videoUUID) })
- }
+ // Await the ending session write before tearing down: abortSession() triggers ffmpeg shutdown,
+ // which eventually fires 'after-cleanup' and onAfterMuxingCleanup() reading this same row
+ // So this write must be committed first to avoid two unsynchronized writers racing on it
+ try {
+ await this.saveEndingSession(options)
+ } catch (err) {
+ logger.error('Cannot save ending session.', { err })
+ }
- this.abortSession(sessionId)
+ this.abortSession(sessionId)
+ })
}
private getContext () {
@@ -266,177 +270,165 @@ class LiveManager {
}) {
const { inputLocalUrl, inputPublicUrl, sessionId, streamKey } = options
- logger.debug(`Handling session ${sessionId}`, lTags(sessionId))
+ logger.debug(`Handling session ${sessionId}`)
const videoLive = await VideoLiveModel.loadByStreamKey(streamKey)
if (!videoLive) {
// Don't log the stream key, which is a long lived secret
- logger.warn('Unknown live video stream key.', lTags(sessionId))
+ logger.warn('Unknown live video stream key.')
return this.abortSession(sessionId)
}
const video = videoLive.Video
- if (video.isBlacklisted()) {
- logger.warn('Video is blacklisted. Refusing stream of video %s.', video.uuid, lTags(sessionId, video.uuid))
- return this.abortSession(sessionId)
- }
- const user = await UserModel.loadByLiveId(videoLive.id)
- if (user.blocked) {
- logger.warn('User is blocked. Refusing stream of video %s.', video.uuid, lTags(sessionId, video.uuid))
- return this.abortSession(sessionId)
- }
+ await logger.withContext([ video.uuid ], async () => {
+ if (video.isBlacklisted()) {
+ logger.warn('Video is blacklisted. Refusing stream of video %s.', video.uuid)
+ return this.abortSession(sessionId)
+ }
- if (this.videoSessions.has(video.uuid)) {
- logger.warn(
- `Video ${video.uuid} has already a live session ${this.videoSessions.get(video.uuid)}. Refusing stream.`,
- lTags(sessionId, video.uuid)
- )
- return this.abortSession(sessionId)
- }
+ const user = await UserModel.loadByLiveId(videoLive.id)
+ if (user.blocked) {
+ logger.warn('User is blocked. Refusing stream of video %s.', video.uuid)
+ return this.abortSession(sessionId)
+ }
- this.videoSessions.set(video.uuid, sessionId)
+ if (this.videoSessions.has(video.uuid)) {
+ logger.warn(`Video ${video.uuid} has already a live session ${this.videoSessions.get(video.uuid)}. Refusing stream.`)
+ return this.abortSession(sessionId)
+ }
- try {
- if (videoLive.saveReplay && await isUserQuotaValid({ channelUserId: user.id, uploadSize: 1000 }) !== true) {
- logger.warn('User quota exceeded. Refusing stream of video %s.', video.uuid, lTags(sessionId, video.uuid))
+ this.videoSessions.set(video.uuid, sessionId)
- try {
- await this.saveEndingSession({ videoUUID: video.uuid, error: LiveVideoError.QUOTA_EXCEEDED })
- } catch (err) {
- logger.error('Cannot save ending session of live with quota exceeded error.', { err, ...lTags(sessionId, video.uuid) })
- }
+ try {
+ if (videoLive.saveReplay && await isUserQuotaValid({ channelUserId: user.id, uploadSize: 1000 }) !== true) {
+ logger.warn('User quota exceeded. Refusing stream of video %s.', video.uuid)
- this.videoSessions.delete(video.uuid)
- return this.abortSession(sessionId)
- }
+ try {
+ await this.saveEndingSession({ videoUUID: video.uuid, error: LiveVideoError.QUOTA_EXCEEDED })
+ } catch (err) {
+ logger.error('Cannot save ending session of live with quota exceeded error.', { err })
+ }
- // A previous session of this permanent live may still be writing its last segments on disk
- // Wait for it, so we don't cleanup/write the same files from two sessions at the same time
- const previous = this.sessionCleanups.get(video.uuid)
- if (previous) {
- logger.info(
- 'Waiting for the previous live session %s of video %s to be cleaned up.',
- previous.sessionId,
- video.uuid,
- lTags(sessionId, video.uuid)
- )
+ this.videoSessions.delete(video.uuid)
+ return this.abortSession(sessionId)
+ }
- // Never block this live forever if the previous cleanup is stuck (a hanging object storage upload for example)
- try {
- await timeoutPromise(previous.cleanup, VIDEO_LIVE.PREVIOUS_SESSION_CLEANUP_TIMEOUT)
- } catch (err) {
- logger.warn(
- 'Previous live session %s of video %s is still not cleaned up, starting the new session anyway.',
+ // A previous session of this permanent live may still be writing its last segments on disk
+ // Wait for it, so we don't cleanup/write the same files from two sessions at the same time
+ const previous = this.sessionCleanups.get(video.uuid)
+ if (previous) {
+ logger.info(
+ 'Waiting for the previous live session %s of video %s to be cleaned up.',
previous.sessionId,
- video.uuid,
- { err, ...lTags(sessionId, video.uuid) }
+ video.uuid
)
+
+ // Never block this live forever if the previous cleanup is stuck (a hanging object storage upload for example)
+ try {
+ await timeoutPromise(previous.cleanup, VIDEO_LIVE.PREVIOUS_SESSION_CLEANUP_TIMEOUT)
+ } catch (err) {
+ logger.warn(
+ 'Previous live session %s of video %s is still not cleaned up, starting the new session anyway.',
+ previous.sessionId,
+ video.uuid,
+ { err }
+ )
+ }
}
- }
- // Cleanup old potential live (could happen with a permanent live)
- const oldStreamingPlaylist = await VideoStreamingPlaylistModel.loadHLSByVideo(video.id)
- if (oldStreamingPlaylist) {
- if (!videoLive.permanentLive) throw new Error('Found previous session in a non permanent live: ' + video.uuid)
+ // Cleanup old potential live (could happen with a permanent live)
+ const oldStreamingPlaylist = await VideoStreamingPlaylistModel.loadHLSByVideo(video.id)
+ if (oldStreamingPlaylist) {
+ if (!videoLive.permanentLive) throw new Error('Found previous session in a non permanent live: ' + video.uuid)
- PeerTubeSocket.Instance.sendVideoForceEnd(video)
+ PeerTubeSocket.Instance.sendVideoForceEnd(video)
- await cleanupAndDestroyPermanentLive(video, oldStreamingPlaylist)
+ await cleanupAndDestroyPermanentLive(video, oldStreamingPlaylist)
+ }
+ } catch (err) {
+ this.videoSessions.delete(video.uuid)
+
+ throw err
}
- } catch (err) {
- this.videoSessions.delete(video.uuid)
- throw err
- }
+ logger.debug('Probing ' + inputLocalUrl)
- logger.debug('Probing ' + inputLocalUrl, lTags(sessionId, video.uuid))
+ const now = Date.now()
+ let probe: FfprobeData
- const now = Date.now()
- let probe: FfprobeData
+ try {
+ probe = await ffprobePromise(inputLocalUrl)
+ } catch (err) {
+ logger.error('Cannot probe ' + inputLocalUrl, { err })
- try {
- probe = await ffprobePromise(inputLocalUrl)
- } catch (err) {
- logger.error('Cannot probe ' + inputLocalUrl, { err, ...lTags(sessionId, video.uuid) })
+ this.videoSessions.delete(video.uuid)
+ return this.abortSession(sessionId)
+ }
- this.videoSessions.delete(video.uuid)
- return this.abortSession(sessionId)
- }
+ const [ { resolution, ratio }, fps, bitrate, hasAudio, hasVideo ] = await Promise.all([
+ getVideoStreamDimensionsInfo(inputLocalUrl, probe),
+ getVideoStreamFPS(inputLocalUrl, probe),
+ getVideoStreamBitrate(inputLocalUrl, probe),
+ hasAudioStream(inputLocalUrl, probe),
+ hasVideoStream(inputLocalUrl, probe)
+ ])
- const [ { resolution, ratio }, fps, bitrate, hasAudio, hasVideo ] = await Promise.all([
- getVideoStreamDimensionsInfo(inputLocalUrl, probe),
- getVideoStreamFPS(inputLocalUrl, probe),
- getVideoStreamBitrate(inputLocalUrl, probe),
- hasAudioStream(inputLocalUrl, probe),
- hasVideoStream(inputLocalUrl, probe)
- ])
-
- if (!hasAudio && !hasVideo) {
- logger.warn(
- 'Not audio and video streams were found for video %s. Refusing stream %s.',
- video.uuid,
- streamKey,
- lTags(sessionId, video.uuid)
- )
+ if (!hasAudio && !hasVideo) {
+ logger.warn('Not audio and video streams were found for video %s. Refusing stream %s.', video.uuid, streamKey)
- this.videoSessions.delete(video.uuid)
- return this.abortSession(sessionId)
- }
+ this.videoSessions.delete(video.uuid)
+ return this.abortSession(sessionId)
+ }
- logger.info(
- '%s probing took %d ms (bitrate: %d, fps: %d, resolution: %d)',
- inputLocalUrl,
- Date.now() - now,
- bitrate,
- fps,
- resolution,
- lTags(sessionId, video.uuid)
- )
-
- const allResolutions = await Hooks.wrapObject(
- this.buildAllResolutionsToTranscode(resolution, hasAudio),
- 'filter:transcoding.auto.resolutions-to-transcode.result',
- { video }
- )
-
- if (!hasAudio && allResolutions.length === 1 && allResolutions[0] === VideoResolution.H_NOVIDEO) {
- logger.warn(
- 'Cannot stream live to audio only because no video stream is available for video %s. Refusing stream %s.',
- video.uuid,
- streamKey,
- lTags(sessionId, video.uuid)
+ logger.info(
+ '%s probing took %d ms (bitrate: %d, fps: %d, resolution: %d)',
+ inputLocalUrl,
+ Date.now() - now,
+ bitrate,
+ fps,
+ resolution
)
- this.videoSessions.delete(video.uuid)
- return this.abortSession(sessionId)
- }
+ const allResolutions = await Hooks.wrapObject(
+ this.buildAllResolutionsToTranscode(resolution, hasAudio),
+ 'filter:transcoding.auto.resolutions-to-transcode.result',
+ { video }
+ )
- logger.info(
- 'Handling live video of original resolution %d.',
- resolution,
- { allResolutions, ...lTags(sessionId, video.uuid) }
- )
+ if (!hasAudio && allResolutions.length === 1 && allResolutions[0] === VideoResolution.H_NOVIDEO) {
+ logger.warn(
+ 'Cannot stream live to audio only because no video stream is available for video %s. Refusing stream %s.',
+ video.uuid,
+ streamKey
+ )
- return this.runMuxingSession({
- sessionId,
- videoLive,
+ this.videoSessions.delete(video.uuid)
+ return this.abortSession(sessionId)
+ }
- user,
+ logger.info('Handling live video of original resolution %d.', resolution, { allResolutions })
- inputLocalUrl,
- inputPublicUrl,
+ return this.runMuxingSession({
+ sessionId,
+ videoLive,
- fps,
- bitrate,
- ratio,
+ user,
- inputResolution: resolution,
- allResolutions,
+ inputLocalUrl,
+ inputPublicUrl,
- hasAudio,
- hasVideo,
- probe
+ fps,
+ bitrate,
+ ratio,
+
+ inputResolution: resolution,
+ allResolutions,
+
+ hasAudio,
+ hasVideo,
+ probe
+ })
})
}
@@ -462,7 +454,6 @@ class LiveManager {
}) {
const { sessionId, videoLive, user, ratio, allResolutions } = options
const videoUUID = videoLive.Video.uuid
- const localLTags = lTags(sessionId, videoUUID)
const audioOnlyOutput = allResolutions.every(r => r === VideoResolution.H_NOVIDEO)
@@ -470,7 +461,7 @@ class LiveManager {
try {
liveSession = await this.saveStartingSession(videoLive)
} catch (err) {
- logger.error('Cannot save starting live session.', { err, ...localLTags })
+ logger.error('Cannot save starting live session.', { err })
this.videoSessions.delete(videoUUID)
return this.abortSession(sessionId)
@@ -501,32 +492,31 @@ class LiveManager {
// Track the cleanup from the session creation: a new session must not write in the live directory before this one flushed its files
this.sessionCleanups.set(videoUUID, { sessionId, cleanup: muxingSession.waitForCleanup() })
- muxingSession.on('live-ready', () => this.publishAndFederateLive({ live: videoLive, ratio, audioOnlyOutput, localLTags }))
+ muxingSession.on('live-ready', () => this.publishAndFederateLive({ live: videoLive, ratio, audioOnlyOutput }))
const safeStopSession = (error: LiveVideoErrorType) => {
this.stopSessionOfVideo({ videoUUID, error })
- .catch(err => logger.error('Cannot stop session of video ' + videoUUID, { err, ...localLTags }))
+ .catch(err => logger.error('Cannot stop session of video ' + videoUUID, { err }))
}
muxingSession.on('bad-socket-health', ({ videoUUID }) => {
logger.error(
'Too much data in client socket stream (ffmpeg is too slow to transcode the video).' +
' Stopping session of video %s.',
- videoUUID,
- localLTags
+ videoUUID
)
safeStopSession(LiveVideoError.BAD_SOCKET_HEALTH)
})
muxingSession.on('duration-exceeded', ({ videoUUID }) => {
- logger.info('Stopping session of %s: max duration exceeded.', videoUUID, localLTags)
+ logger.info('Stopping session of %s: max duration exceeded.', videoUUID)
safeStopSession(LiveVideoError.DURATION_EXCEEDED)
})
muxingSession.on('quota-exceeded', ({ videoUUID }) => {
- logger.info('Stopping session of %s: user quota exceeded.', videoUUID, localLTags)
+ logger.info('Stopping session of %s: user quota exceeded.', videoUUID)
safeStopSession(LiveVideoError.QUOTA_EXCEEDED)
})
@@ -548,14 +538,14 @@ class LiveManager {
muxingSession.destroy()
return this.onAfterMuxingCleanup({ videoUUID, liveSessionId: liveSession.id })
- .catch(err => logger.error('Error in end transmuxing.', { err, ...localLTags }))
+ .catch(err => logger.error('Error in end transmuxing.', { err }))
})
this.muxingSessions.set(sessionId, muxingSession)
muxingSession.runMuxing()
.catch(err => {
- logger.error('Cannot run muxing.', { err, ...localLTags })
+ logger.error('Cannot run muxing.', { err })
this.muxingSessions.delete(sessionId)
this.deleteSessionCleanup(videoUUID, sessionId)
@@ -569,7 +559,7 @@ class LiveManager {
videoUUID,
error: err.liveVideoErrorCode || LiveVideoError.UNKNOWN_ERROR,
errorOnReplay: true // Replay cannot be processed as muxing session failed directly
- }).catch(stopErr => logger.error('Cannot stop session of video %s.', videoUUID, { err: stopErr, ...localLTags }))
+ }).catch(stopErr => logger.error('Cannot stop session of video %s.', videoUUID, { err: stopErr }))
})
}
@@ -577,16 +567,15 @@ class LiveManager {
live: MVideoLiveVideo
audioOnlyOutput: boolean
ratio: number
- localLTags: { tags: (string | number)[] }
}) {
- const { live, ratio, audioOnlyOutput, localLTags } = options
+ const { live, ratio, audioOnlyOutput } = options
const videoId = live.videoId
try {
const video = await VideoModel.loadFull(videoId)
- logger.info('Will publish and federate live %s.', video.url, localLTags)
+ logger.info('Will publish and federate live %s.', video.url)
video.state = VideoState.PUBLISHED
@@ -610,7 +599,7 @@ class LiveManager {
Hooks.runAction('action:live.video.state.updated', { video })
} catch (err) {
- logger.error('Cannot save/federate live video %d.', videoId, { err, ...localLTags })
+ logger.error('Cannot save/federate live video %d.', videoId, { err })
}
}
@@ -622,7 +611,7 @@ class LiveManager {
this.videoSessions.delete(videoUUID)
this.saveEndingSession({ videoUUID, error: null })
- .catch(err => logger.error('Cannot save ending session.', { err, ...lTags(sessionId) }))
+ .catch(err => logger.error('Cannot save ending session.', { err }))
}
private async onAfterMuxingCleanup (options: {
@@ -632,7 +621,7 @@ class LiveManager {
}) {
const { videoUUID, liveSessionId, cleanupNow = false } = options
- logger.debug('Live of video %s has been cleaned up. Moving to its next state.', videoUUID, lTags(videoUUID))
+ logger.debug('Live of video %s has been cleaned up. Moving to its next state.', videoUUID)
try {
const fullVideo = await VideoModel.loadFull(videoUUID)
@@ -683,7 +672,7 @@ class LiveManager {
Hooks.runAction('action:live.video.state.updated', { video: fullVideo })
} catch (err) {
- logger.error('Cannot save/federate new video state of live streaming of video %s.', videoUUID, { err, ...lTags(videoUUID) })
+ logger.error('Cannot save/federate new video state of live streaming of video %s.', videoUUID, { err })
}
}
@@ -693,7 +682,9 @@ class LiveManager {
const videoUUIDs = await VideoModel.listPublishedLiveUUIDs()
for (const uuid of videoUUIDs) {
- await this.onAfterMuxingCleanup({ videoUUID: uuid, cleanupNow: true })
+ await logger.withContext([ uuid ], async () => {
+ await this.onAfterMuxingCleanup({ videoUUID: uuid, cleanupNow: true })
+ })
}
}
diff --git a/server/core/lib/live/live-segment-sha-store.ts b/server/core/lib/live/live-segment-sha-store.ts
index b282795aec..f63d581bc8 100644
--- a/server/core/lib/live/live-segment-sha-store.ts
+++ b/server/core/lib/live/live-segment-sha-store.ts
@@ -1,6 +1,6 @@
import { buildSUUID } from '@peertube/peertube-node-utils'
import { mapToJSON } from '@server/helpers/core-utils.js'
-import { logger, loggerTagsFactory } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { LRU_CACHE } from '@server/initializers/constants.js'
import { MStreamingPlaylistVideo } from '@server/types/models/index.js'
import { writeJson } from 'fs-extra/esm'
@@ -10,7 +10,7 @@ import { basename, dirname, join } from 'path'
import { buildSha256Segment } from '../hls.js'
import { storeHLSFileFromPath } from '../object-storage/index.js'
-const lTags = loggerTagsFactory('live')
+const logger = createLogger('live')
class LiveSegmentShaStore {
private readonly segmentsSha256 = new Map<string, string>()
@@ -50,11 +50,11 @@ class LiveSegmentShaStore {
// This segment has already been removed (its "unlink" event ran before we finished hashing it)
if (this.removedSegments.delete(segmentName)) {
- logger.debug('Segment %s was removed before its hash could be added, ignoring it.', segmentPath, lTags(this.videoUUID))
+ logger.debug('Segment %s was removed before its hash could be added, ignoring it.', segmentPath)
return
}
- logger.debug('Adding live sha segment %s.', segmentPath, lTags(this.videoUUID))
+ logger.debug('Adding live sha segment %s.', segmentPath)
const shaResult = await buildSha256Segment(segmentPath)
@@ -66,15 +66,10 @@ class LiveSegmentShaStore {
removeSegmentSha (segmentPath: string) {
const segmentName = basename(segmentPath)
- logger.debug('Removing live sha segment %s.', segmentPath, lTags(this.videoUUID))
+ logger.debug('Removing live sha segment %s.', segmentPath)
if (!this.segmentsSha256.has(segmentName)) {
- logger.debug(
- 'Unknown segment in live segment hash store for video %s and segment %s.',
- this.videoUUID,
- segmentPath,
- lTags(this.videoUUID)
- )
+ logger.debug('Unknown segment in live segment hash store for video %s and segment %s.', this.videoUUID, segmentPath)
// Its hash may still be pending (addSegmentSha hasn't run yet)
// Remember it so we discard the hash instead of leaking it
@@ -112,7 +107,7 @@ class LiveSegmentShaStore {
}
private async writeOnce () {
- logger.debug(`Writing segment sha JSON ${this.sha256Path} of ${this.videoUUID} on disk.`, lTags(this.videoUUID))
+ logger.debug(`Writing segment sha JSON ${this.sha256Path} of ${this.videoUUID} on disk.`)
// Atomic write: use rename instead of move that is not atomic
// FIXME: jsonfile typings
diff --git a/server/core/lib/live/live-utils.ts b/server/core/lib/live/live-utils.ts
index 2df2939eba..45d1043744 100644
--- a/server/core/lib/live/live-utils.ts
+++ b/server/core/lib/live/live-utils.ts
@@ -1,6 +1,6 @@
import { wait } from '@peertube/peertube-core-utils'
import { FileStorage, LiveVideoLatencyMode, LiveVideoLatencyModeType, VideoState } from '@peertube/peertube-models'
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { CONFIG } from '@server/initializers/config.js'
import { VIDEO_LIVE } from '@server/initializers/constants.js'
import { MStreamingPlaylist, MStreamingPlaylistVideo, MVideo } from '@server/types/models/index.js'
@@ -11,6 +11,8 @@ import { basename, join } from 'path'
import { listHLSFileKeysOf, removeHLSFileObjectStorageByFullKey, removeHLSObjectStorage } from '../object-storage/index.js'
import { getLiveDirectory, getLiveReplayBaseDirectory } from '../paths.js'
+const logger = createLogger()
+
export function buildConcatenatedName (segmentOrPlaylistPath: string) {
const num = basename(segmentOrPlaylistPath).match(/^(\d+)(-|\.)/)
diff --git a/server/core/lib/live/shared/muxing-session.ts b/server/core/lib/live/shared/muxing-session.ts
index a8825e40cf..33f72c786e 100644
--- a/server/core/lib/live/shared/muxing-session.ts
+++ b/server/core/lib/live/shared/muxing-session.ts
@@ -8,7 +8,7 @@ import {
VideoStreamingPlaylistType
} from '@peertube/peertube-models'
import { computeOutputFPS } from '@server/helpers/ffmpeg/index.js'
-import { logger, loggerTagsFactory, LoggerTagsFn } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { CONFIG } from '@server/initializers/config.js'
import { MEMOIZE_TTL, P2P_MEDIA_LOADER_PEER_VERSION, VIDEO_LIVE } from '@server/initializers/constants.js'
import { removeHLSFileObjectStorageByPath, storeHLSFileFromContent, storeHLSFileFromPath } from '@server/lib/object-storage/index.js'
@@ -36,6 +36,8 @@ import { LiveSegmentShaStore } from '../live-segment-sha-store.js'
import { buildConcatenatedName, getLiveSegmentListSize, getLiveSegmentTime } from '../live-utils.js'
import { AbstractTranscodingWrapper, FFmpegTranscodingWrapper, RemoteTranscodingWrapper } from './transcoding-wrapper/index.js'
+const logger = createLogger('muxing')
+
interface MuxingSessionEvents {
'live-ready': (options: { videoUUID: string }) => void
@@ -93,8 +95,6 @@ class MuxingSession extends EventEmitter implements MuxingSession {
private readonly outDirectory: string
private readonly replayDirectory: string
- private readonly lTags: LoggerTagsFn
-
// Path -> Queue
private readonly objectStorageSendQueues = new Map<string, PQueue>()
@@ -184,8 +184,6 @@ class MuxingSession extends EventEmitter implements MuxingSession {
this.outDirectory = getLiveDirectory(this.videoLive.Video)
this.replayDirectory = join(getLiveReplayBaseDirectory(this.videoLive.Video), new Date().toISOString())
-
- this.lTags = loggerTagsFactory('live', this.sessionId, this.videoUUID)
}
async runMuxing () {
@@ -219,7 +217,7 @@ class MuxingSession extends EventEmitter implements MuxingSession {
// abort() was called before the wrapper existed
// Abort the wrapper anyway, so it emits 'end' and the cleanup of this session is scheduled
if (this.aborted) {
- logger.debug('Live muxing of %s was aborted before the transcoding process started.', this.videoUUID, this.lTags())
+ logger.debug('Live muxing of %s was aborted before the transcoding process started.', this.videoUUID)
this.transcodingWrapper.abort()
return
@@ -246,7 +244,7 @@ class MuxingSession extends EventEmitter implements MuxingSession {
// Ensure the files watcher is always closed, even when the cleanup was never scheduled
// (e.g. an ffmpeg error makes the transcoding wrapper abort() short-circuit without emitting 'end')
this.closeWatcher()
- .catch(err => logger.error('Cannot close files watcher of %s.', this.outDirectory, { err, ...this.lTags() }))
+ .catch(err => logger.error('Cannot close files watcher of %s.', this.outDirectory, { err }))
// We removed its listeners below, so don't leave a pending timer that would emit an event nobody handles
this.transcodingWrapper?.destroy()
@@ -273,7 +271,7 @@ class MuxingSession extends EventEmitter implements MuxingSession {
private trackWatcherHandler (handler: Promise<void>) {
const tracked: Promise<void> = handler
.catch(err => {
- logger.error('Error in live files watcher handler of %s.', this.outDirectory, { err, ...this.lTags() })
+ logger.error('Error in live files watcher handler of %s.', this.outDirectory, { err })
})
.finally(() => {
this.pendingWatcherHandlers.delete(tracked)
@@ -291,7 +289,7 @@ class MuxingSession extends EventEmitter implements MuxingSession {
if (this.streamingPlaylist.storage === FileStorage.OBJECT_STORAGE) {
const masterContent = await this.readNonEmptyMasterPlaylist(path)
- logger.debug('Uploading live master playlist on object storage for %s', this.videoUUID, { masterContent, ...this.lTags() })
+ logger.debug('Uploading live master playlist on object storage for %s', this.videoUUID, { masterContent })
await storeHLSFileFromContent(
{
@@ -314,7 +312,7 @@ class MuxingSession extends EventEmitter implements MuxingSession {
await this.streamingPlaylist.save()
} catch (err) {
- logger.error('Cannot update streaming playlist.', { err, ...this.lTags() })
+ logger.error('Cannot update streaming playlist.', { err })
// Don't set masterPlaylistCreated: without a stored master playlist the live would be published but unplayable
// Stop the session instead, so we don't federate a broken live
@@ -324,7 +322,7 @@ class MuxingSession extends EventEmitter implements MuxingSession {
this.masterPlaylistCreated = true
- logger.info('Master playlist file for %s has been created', this.videoUUID, this.lTags())
+ logger.info('Master playlist file for %s has been created', this.videoUUID)
}
this.filesWatcher.on('add', path => this.trackWatcherHandler(addHandler(path)))
@@ -355,11 +353,11 @@ class MuxingSession extends EventEmitter implements MuxingSession {
const addHandler = (segmentPath: string) => {
if (segmentPath.endsWith('.ts') !== true) return
- logger.debug('Live add handler of TS file %s.', segmentPath, this.lTags())
+ logger.debug('Live add handler of TS file %s.', segmentPath)
const playlistId = this.getPlaylistIdFromTS(segmentPath)
if (!playlistId) {
- logger.warn('Cannot get the playlist id of live segment %s, ignoring it.', segmentPath, this.lTags())
+ logger.warn('Cannot get the playlist id of live segment %s, ignoring it.', segmentPath)
return
}
@@ -380,7 +378,7 @@ class MuxingSession extends EventEmitter implements MuxingSession {
const deleteHandler = async (segmentPath: string) => {
if (segmentPath.endsWith('.ts') !== true) return
- logger.debug('Live delete handler of TS file %s.', segmentPath, this.lTags())
+ logger.debug('Live delete handler of TS file %s.', segmentPath)
// The segment does not exist anymore so the cleanup won't list it: don't track it forever
this.processedSegments.delete(segmentPath)
@@ -391,7 +389,7 @@ class MuxingSession extends EventEmitter implements MuxingSession {
try {
await removeHLSFileObjectStorageByPath(this.streamingPlaylist.Video, segmentPath)
} catch (err) {
- logger.error('Cannot remove segment %s from object storage', segmentPath, { err, ...this.lTags() })
+ logger.error('Cannot remove segment %s from object storage', segmentPath, { err })
}
}
}
@@ -413,7 +411,7 @@ class MuxingSession extends EventEmitter implements MuxingSession {
return canUpload !== true
} catch (err) {
- logger.error('Cannot stat %s or check quota of %d.', segmentPath, this.user.id, { err, ...this.lTags() })
+ logger.error('Cannot stat %s or check quota of %d.', segmentPath, this.user.id, { err })
}
}
@@ -433,7 +431,7 @@ class MuxingSession extends EventEmitter implements MuxingSession {
})
VideoFileModel.customUpsert(file, 'streaming-playlist', null)
- .catch(err => logger.error('Cannot create file for live streaming.', { err, ...this.lTags() }))
+ .catch(err => logger.error('Cannot create file for live streaming.', { err }))
}
}
@@ -468,14 +466,14 @@ class MuxingSession extends EventEmitter implements MuxingSession {
.catch(err => {
if (this.aborted) return
- logger.error('Cannot process segment %s.', segmentPath, { err, ...this.lTags() })
+ logger.error('Cannot process segment %s.', segmentPath, { err })
})
})
)
.catch(err => {
if (this.aborted) return
- logger.error('Cannot process segments', { err, ...this.lTags() })
+ logger.error('Cannot process segments', { err })
})
}
@@ -517,7 +515,7 @@ class MuxingSession extends EventEmitter implements MuxingSession {
await this.processM3U8ToObjectStorage(segmentPath)
} catch (err) {
- logger.error('Cannot store TS segment %s in object storage', segmentPath, { err, ...this.lTags() })
+ logger.error('Cannot store TS segment %s in object storage', segmentPath, { err })
}
}
} catch (err) {
@@ -538,7 +536,7 @@ class MuxingSession extends EventEmitter implements MuxingSession {
private async processM3U8ToObjectStorage (segmentPath: string) {
const m3u8Path = join(this.outDirectory, this.getPlaylistNameFromTS(segmentPath))
- logger.debug('Process M3U8 file %s.', m3u8Path, this.lTags())
+ logger.debug('Process M3U8 file %s.', m3u8Path)
const segmentName = basename(segmentPath)
@@ -560,7 +558,7 @@ class MuxingSession extends EventEmitter implements MuxingSession {
})
)
} catch (err) {
- logger.error('Cannot store in object storage m3u8 file %s', m3u8Path, { err, ...this.lTags() })
+ logger.error('Cannot store in object storage m3u8 file %s', m3u8Path, { err })
}
}
@@ -581,7 +579,7 @@ class MuxingSession extends EventEmitter implements MuxingSession {
private onTranscodedEnded () {
// Don't log the input URL, which contains the stream key (a long lived secret)
- logger.info('RTMP transmuxing for video %s ended. Scheduling cleanup', this.videoUUID, this.lTags())
+ logger.info('RTMP transmuxing for video %s ended. Scheduling cleanup', this.videoUUID)
// Schedule it before emitting so listeners can wait for the cleanup to complete
this.scheduleCleanup()
@@ -595,7 +593,7 @@ class MuxingSession extends EventEmitter implements MuxingSession {
this.cleanupScheduled = true
this.runCleanup()
- .catch(err => logger.error('Cannot run cleanup of %s.', this.outDirectory, { err, ...this.lTags() }))
+ .catch(err => logger.error('Cannot run cleanup of %s.', this.outDirectory, { err }))
}
private async runCleanup () {
@@ -616,7 +614,7 @@ class MuxingSession extends EventEmitter implements MuxingSession {
logger.error(
'Cannot close watchers of %s or process remaining hash segments.',
this.outDirectory,
- { err, ...this.lTags() }
+ { err }
)
}
@@ -651,7 +649,7 @@ class MuxingSession extends EventEmitter implements MuxingSession {
if (remainingCount === 0) return
- logger.debug('Processing %d remaining live segments of %s.', remainingCount, this.videoUUID, this.lTags())
+ logger.debug('Processing %d remaining live segments of %s.', remainingCount, this.videoUUID)
await Promise.all(
Array.from(perPlaylist, ([ playlistId, paths ]) => this.processSegments(playlistId, paths))
@@ -662,7 +660,7 @@ class MuxingSession extends EventEmitter implements MuxingSession {
const rtmpSession = this.context.sessions.get(sessionId)
if (!rtmpSession) {
- logger.warn('Cannot get session %s to check players socket health.', sessionId, this.lTags())
+ logger.warn('Cannot get session %s to check players socket health.', sessionId)
return
}
@@ -670,7 +668,7 @@ class MuxingSession extends EventEmitter implements MuxingSession {
const playerSession = this.context.sessions.get(playerSessionId)
if (!playerSession) {
- logger.error('Cannot get player session %s to check socket health.', playerSession, this.lTags())
+ logger.error('Cannot get player session %s to check socket health.', playerSession)
continue
}
@@ -686,14 +684,14 @@ class MuxingSession extends EventEmitter implements MuxingSession {
const segmentName = basename(segmentPath)
const dest = join(this.replayDirectory, buildConcatenatedName(segmentName))
- logger.debug(`Add segment ${segmentPath} to replay ${dest}`, this.lTags())
+ logger.debug(`Add segment ${segmentPath} to replay ${dest}`)
try {
const data = await readFile(segmentPath)
await appendFile(dest, data)
} catch (err) {
- logger.error('Cannot copy segment %s to replay directory.', segmentPath, { err, ...this.lTags() })
+ logger.error('Cannot copy segment %s to replay directory.', segmentPath, { err })
}
}
@@ -727,8 +725,6 @@ class MuxingSession extends EventEmitter implements MuxingSession {
streamingPlaylist: this.streamingPlaylist,
videoLive: this.videoLive,
- lTags: this.lTags,
-
sessionId: this.sessionId,
inputLocalUrl: this.inputLocalUrl,
inputPublicUrl: this.inputPublicUrl,
diff --git a/server/core/lib/live/shared/transcoding-wrapper/abstract-transcoding-wrapper.ts b/server/core/lib/live/shared/transcoding-wrapper/abstract-transcoding-wrapper.ts
index 5ae8ae2b77..40423d0214 100644
--- a/server/core/lib/live/shared/transcoding-wrapper/abstract-transcoding-wrapper.ts
+++ b/server/core/lib/live/shared/transcoding-wrapper/abstract-transcoding-wrapper.ts
@@ -1,5 +1,4 @@
import { LiveVideoErrorType } from '@peertube/peertube-models'
-import { LoggerTagsFn } from '@server/helpers/logger.js'
import { MStreamingPlaylistVideo, MVideoLiveVideo } from '@server/types/models/index.js'
import EventEmitter from 'events'
import { FfprobeData } from 'fluent-ffmpeg'
@@ -27,8 +26,6 @@ interface AbstractTranscodingWrapperOptions {
streamingPlaylist: MStreamingPlaylistVideo
videoLive: MVideoLiveVideo
- lTags: LoggerTagsFn
-
sessionId: string
inputLocalUrl: string
inputPublicUrl: string
@@ -77,15 +74,11 @@ abstract class AbstractTranscodingWrapper extends EventEmitter {
protected readonly outDirectory: string
- protected readonly lTags: LoggerTagsFn
-
protected readonly streamingPlaylist: MStreamingPlaylistVideo
constructor (options: AbstractTranscodingWrapperOptions) {
super()
- this.lTags = options.lTags
-
this.videoLive = options.videoLive
this.videoUUID = options.videoLive.Video.uuid
this.streamingPlaylist = options.streamingPlaylist
diff --git a/server/core/lib/live/shared/transcoding-wrapper/ffmpeg-transcoding-wrapper.ts b/server/core/lib/live/shared/transcoding-wrapper/ffmpeg-transcoding-wrapper.ts
index 0d0373584c..3d561adbbc 100644
--- a/server/core/lib/live/shared/transcoding-wrapper/ffmpeg-transcoding-wrapper.ts
+++ b/server/core/lib/live/shared/transcoding-wrapper/ffmpeg-transcoding-wrapper.ts
@@ -1,6 +1,6 @@
import { FFmpegLive } from '@peertube/peertube-ffmpeg'
import { getFFmpegCommandWrapperOptions } from '@server/helpers/ffmpeg/index.js'
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { CONFIG } from '@server/initializers/config.js'
import { VIDEO_LIVE } from '@server/initializers/constants.js'
import { VideoTranscodingProfilesManager } from '@server/lib/transcoding/default-transcoding-profiles.js'
@@ -8,6 +8,8 @@ import { FfmpegCommand } from 'fluent-ffmpeg'
import { getLiveSegmentTime } from '../../live-utils.js'
import { AbstractTranscodingWrapper } from './abstract-transcoding-wrapper.js'
+const logger = createLogger('live', 'transcoding', 'ffmpeg')
+
export class FFmpegTranscodingWrapper extends AbstractTranscodingWrapper {
private ffmpegCommand: FfmpegCommand
@@ -51,19 +53,19 @@ export class FFmpegTranscodingWrapper extends AbstractTranscodingWrapper {
// abort() may have been called while we were building the command: don't spawn an ffmpeg process nobody watches
if (this.aborted || this.ended || this.errored) {
- logger.debug('Live transcoding of %s was aborted before ffmpeg started.', this.videoUUID, this.lTags())
+ logger.debug('Live transcoding of %s was aborted before ffmpeg started.', this.videoUUID)
return
}
this.ffmpegCommand = ffmpegCommand
- logger.info('Running local live muxing/transcoding for %s.', this.videoUUID, this.lTags())
+ logger.info('Running local live muxing/transcoding for %s.', this.videoUUID)
let ffmpegShellCommand: string
this.ffmpegCommand.on('start', cmdline => {
ffmpegShellCommand = cmdline
- logger.debug('Running ffmpeg command for live', { ffmpegShellCommand, ...this.lTags() })
+ logger.debug('Running ffmpeg command for live', { ffmpegShellCommand })
})
this.ffmpegCommand.on('error', (err, stdout, stderr) => {
@@ -88,14 +90,14 @@ export class FFmpegTranscodingWrapper extends AbstractTranscodingWrapper {
return
}
- logger.debug('Killing ffmpeg after live abort of ' + this.videoUUID, this.lTags())
+ logger.debug('Killing ffmpeg after live abort of ' + this.videoUUID)
this.ffmpegCommand.kill('SIGINT')
// Don't emit 'end' yet: on SIGINT ffmpeg still has to write its last segments and update the playlists
// We wait for the process to actually exit so listeners know the live directory is not written anymore
this.exitTimeout = setTimeout(() => {
- logger.warn('FFmpeg did not exit %d ms after SIGINT of %s, killing it.', VIDEO_LIVE.FFMPEG_EXIT_TIMEOUT, this.videoUUID, this.lTags())
+ logger.warn('FFmpeg did not exit %d ms after SIGINT of %s, killing it.', VIDEO_LIVE.FFMPEG_EXIT_TIMEOUT, this.videoUUID)
this.ffmpegCommand.kill('SIGKILL')
this.emitEnded()
@@ -119,7 +121,7 @@ export class FFmpegTranscodingWrapper extends AbstractTranscodingWrapper {
logger.debug(
'Ignoring ffmpeg error of %s because we aborted the live.',
this.videoUUID,
- { err, stdout, stderr, ffmpegShellCommand, ...this.lTags() }
+ { err, stdout, stderr, ffmpegShellCommand }
)
return this.emitEnded()
@@ -129,7 +131,7 @@ export class FFmpegTranscodingWrapper extends AbstractTranscodingWrapper {
if (err?.message?.includes('Exiting normally')) return
if (this.ended || this.errored) return
- logger.error('FFmpeg transcoding error.', { err, stdout, stderr, ffmpegShellCommand, ...this.lTags() })
+ logger.error('FFmpeg transcoding error.', { err, stdout, stderr, ffmpegShellCommand })
this.errored = true
this.emit('error', { err })
@@ -138,7 +140,7 @@ export class FFmpegTranscodingWrapper extends AbstractTranscodingWrapper {
private onFFmpegEnded () {
if (this.errored) return
- logger.debug('Live ffmpeg transcoding ended for ' + this.videoUUID, this.lTags())
+ logger.debug('Live ffmpeg transcoding ended for ' + this.videoUUID)
this.emitEnded()
}
diff --git a/server/core/lib/live/shared/transcoding-wrapper/remote-transcoding-wrapper.ts b/server/core/lib/live/shared/transcoding-wrapper/remote-transcoding-wrapper.ts
index 1b77311f2f..1614fbe4b3 100644
--- a/server/core/lib/live/shared/transcoding-wrapper/remote-transcoding-wrapper.ts
+++ b/server/core/lib/live/shared/transcoding-wrapper/remote-transcoding-wrapper.ts
@@ -1,9 +1,11 @@
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { VIDEO_LIVE } from '@server/initializers/constants.js'
import { LiveRTMPHLSTranscodingJobHandler } from '@server/lib/runners/index.js'
import { MRunnerJob } from '@server/types/models/runners/index.js'
import { AbstractTranscodingWrapper } from './abstract-transcoding-wrapper.js'
+const logger = createLogger('live', 'transcoding', 'runner')
+
export class RemoteTranscodingWrapper extends AbstractTranscodingWrapper {
private aborted = false
@@ -23,7 +25,7 @@ export class RemoteTranscodingWrapper extends AbstractTranscodingWrapper {
// abort() may have been called while we were creating the job
if (this.aborted) {
- logger.debug('Cancelling remote live transcoding job of %s aborted before a runner processed it.', this.videoUUID, this.lTags())
+ logger.debug('Cancelling remote live transcoding job of %s aborted before a runner processed it.', this.videoUUID)
await this.cancelRunnerJob(runnerJob)
}
@@ -33,7 +35,7 @@ export class RemoteTranscodingWrapper extends AbstractTranscodingWrapper {
if (this.aborted) return
this.aborted = true
- logger.debug('Waiting for the remote runner of %s to flush its last chunks.', this.videoUUID, this.lTags())
+ logger.debug('Waiting for the remote runner of %s to flush its last chunks.', this.videoUUID)
// The runner uploads its chunks with HTTP requests that the API writes in our output directory, independently of this wrapper
// Add a delay to flush its last chunks before listeners consider the directory is not written anymore
@@ -48,7 +50,7 @@ export class RemoteTranscodingWrapper extends AbstractTranscodingWrapper {
try {
await new LiveRTMPHLSTranscodingJobHandler().cancel({ runnerJob })
} catch (err) {
- logger.error('Cannot cancel remote live transcoding job of %s.', this.videoUUID, { err, ...this.lTags() })
+ logger.error('Cannot cancel remote live transcoding job of %s.', this.videoUUID, { err })
}
}
}
diff --git a/server/core/lib/local-video-creator.ts b/server/core/lib/local-video-creator.ts
index 64e7bae2c0..912e5faa10 100644
--- a/server/core/lib/local-video-creator.ts
+++ b/server/core/lib/local-video-creator.ts
@@ -14,7 +14,7 @@ import {
} from '@peertube/peertube-models'
import { buildUUID } from '@peertube/peertube-node-utils'
import { retryTransactionWrapper } from '@server/helpers/database-utils.js'
-import { LoggerTagsFn, logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { CONFIG } from '@server/initializers/config.js'
import { sequelizeTypescript } from '@server/initializers/database.js'
import { getServerAccount } from '@server/models/application/application.js'
@@ -42,6 +42,8 @@ import { addVideoJobsAfterCreation } from './video-jobs.js'
import { VideoPathManager } from './video-path-manager.js'
import { setVideoTags } from './video.js'
+const logger = createLogger('video')
+
type VideoAttributes = Omit<VideoCreate, 'channelId'> & {
duration: number
isLive: boolean
@@ -81,8 +83,6 @@ type VideoAttributeHookFilter =
| 'filter:api.video.live.video-attribute.result'
export class LocalVideoCreator {
- private readonly lTags: LoggerTagsFn
-
private readonly videoFilePath: string | undefined
private readonly videoFileProbe: FfprobeData
@@ -98,8 +98,6 @@ export class LocalVideoCreator {
constructor (
private readonly options: {
- lTags: LoggerTagsFn
-
videoFile: {
path: string
probe: FfprobeData
@@ -129,8 +127,6 @@ export class LocalVideoCreator {
this.channel = options.channel
this.videoAttributeResultHook = options.videoAttributeResultHook
-
- this.lTags = options.lTags
}
async create () {
@@ -138,6 +134,10 @@ export class LocalVideoCreator {
await Hooks.wrapObject(this.buildVideo(this.videoAttributes, this.channel), this.videoAttributeResultHook)
)
+ return logger.withContext([ this.video.uuid ], () => this.runCreate())
+ }
+
+ private async runCreate () {
this.video.VideoChannel = this.channel
this.video.url = getLocalVideoActivityPubUrl(this.video)
@@ -253,7 +253,7 @@ export class LocalVideoCreator {
video: this.video,
videoFile: this.videoFile,
generateTranscription: this.videoAttributes.generateTranscription ?? true
- }).catch(err => logger.error('Cannot build new video jobs of %s.', this.video.uuid, { err, ...this.lTags(this.video.uuid) }))
+ }).catch(err => logger.error('Cannot build new video jobs of %s.', this.video.uuid, { err }))
})
} else {
scheduleVideoFederation({ video: this.video, transaction })
diff --git a/server/core/lib/local-video-updater.ts b/server/core/lib/local-video-updater.ts
index 343a407a3a..aaf4e0e84f 100644
--- a/server/core/lib/local-video-updater.ts
+++ b/server/core/lib/local-video-updater.ts
@@ -8,7 +8,7 @@ import {
VideoUpdate
} from '@peertube/peertube-models'
import { auditLoggerFactory, getAuditIdFromUser, VideoAuditView } from '@server/helpers/audit-logger.js'
-import { logger, loggerTagsFactory, LoggerTagsFn } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { sequelizeTypescript } from '@server/initializers/database.js'
import { getServerAccount } from '@server/models/application/application.js'
import { ScheduleVideoUpdateModel } from '@server/models/video/schedule-video-update.js'
@@ -31,9 +31,9 @@ import { isNewVideoForSubscription, moveFilesIfPrivacyChanged } from './video-pr
import { setVideoTags } from './video.js'
const auditLogger = auditLoggerFactory('videos')
+const logger = createLogger('video')
export class LocalVideoUpdater {
- private readonly lTags: LoggerTagsFn
private readonly oldVideo: MVideoFull
private readonly user: MUserAccountUrl | null
@@ -43,14 +43,11 @@ export class LocalVideoUpdater {
private readonly oldVideoAuditView: VideoAuditView
constructor (options: {
- tags: (string | number)[]
-
video: MVideoFull
user: MUserAccountUrl | null
}) {
this.user = options.user
this.oldVideo = options.video
- this.lTags = loggerTagsFactory(...options.tags, options.video.uuid)
this.hadPrivacyForFederation = isPrivacyForFederation(this.oldVideo.privacy)
this.oldPrivacy = this.oldVideo.privacy
@@ -58,7 +55,14 @@ export class LocalVideoUpdater {
this.oldVideoAuditView = new VideoAuditView(this.oldVideo.toFormattedDetailsJSON())
}
- async update (options: Omit<VideoUpdate, 'thumbnailfile' | 'previewfile'> & {
+ update (options: Omit<VideoUpdate, 'thumbnailfile' | 'previewfile'> & {
+ thumbnails?: MThumbnail[]
+ channel?: MChannelBannerAccountDefault
+ }) {
+ return logger.withContext([ this.oldVideo.uuid ], () => this.runUpdate(options))
+ }
+
+ private async runUpdate (options: Omit<VideoUpdate, 'thumbnailfile' | 'previewfile'> & {
thumbnails?: MThumbnail[]
channel?: MChannelBannerAccountDefault
}) {
@@ -225,7 +229,7 @@ export class LocalVideoUpdater {
)
}
- logger.info('Video with name %s and uuid %s updated.', video.name, video.uuid, this.lTags())
+ logger.info('Video with name %s and uuid %s updated.', video.name, video.uuid)
return { video, newVideoForSubscription }
})
@@ -334,7 +338,7 @@ export class LocalVideoUpdater {
const hls = video.getHLSPlaylist()
if (filePathChanged && hls) {
- logger.debug('Updating HLS playlist file paths after privacy change', this.lTags())
+ logger.debug('Updating HLS playlist file paths after privacy change')
await hls.buildAndSetInfoHashes(video, hls.VideoFiles)
await hls.save()
@@ -351,7 +355,7 @@ export class LocalVideoUpdater {
const jobs: CreateJobTypeAndPayload[] = []
if (!video.isLive && (nameChanged || filePathChanged)) {
- logger.debug('Updating video torrent metadata after name or file path change', this.lTags())
+ logger.debug('Updating video torrent metadata after name or file path change')
for (const file of (video.VideoFiles || [])) {
const payload: ManageVideoTorrentPayload = { action: 'update-metadata', videoId: video.id, videoFileId: file.id }
@@ -386,7 +390,7 @@ export class LocalVideoUpdater {
const { video, newVideoForSubscription } = options
if (!newVideoForSubscription) return []
- logger.debug('Video is considered new for subscriptions: create the notification job', this.lTags())
+ logger.debug('Video is considered new for subscriptions: create the notification job')
return [
{
diff --git a/server/core/lib/moderation.ts b/server/core/lib/moderation.ts
index e533030ed5..af5beb5746 100644
--- a/server/core/lib/moderation.ts
+++ b/server/core/lib/moderation.ts
@@ -3,7 +3,7 @@ import { PathLike } from 'fs-extra/esm'
import { Transaction } from 'sequelize'
import { AbuseAuditView, auditLoggerFactory } from '@server/helpers/audit-logger.js'
import { afterCommitIfTransaction } from '@server/helpers/database-utils.js'
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { AbuseModel } from '@server/models/abuse/abuse.js'
import { VideoAbuseModel } from '@server/models/abuse/video-abuse.js'
import { VideoCommentAbuseModel } from '@server/models/abuse/video-comment-abuse.js'
@@ -28,6 +28,8 @@ import { VideoModel } from '../models/video/video.js'
import { sendAbuse } from './activitypub/send/send-flag.js'
import { Notifier } from './notifier/index.js'
+const logger = createLogger()
+
export type AcceptResult = {
accepted: boolean
errorMessage?: string
diff --git a/server/core/lib/move-storage/move-to-file-system.ts b/server/core/lib/move-storage/move-to-file-system.ts
index fc06e06ac7..a903c44a56 100644
--- a/server/core/lib/move-storage/move-to-file-system.ts
+++ b/server/core/lib/move-storage/move-to-file-system.ts
@@ -1,5 +1,5 @@
import { FileStorage, VideoStateType } from '@peertube/peertube-models'
-import { logger, LoggerTags, loggerTagsFactory } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { CONFIG } from '@server/initializers/config.js'
import { P2P_MEDIA_LOADER_PEER_VERSION } from '@server/initializers/constants.js'
import {
@@ -29,7 +29,7 @@ import { join } from 'path'
import { moveCaptionToStorage } from './shared/move-caption.js'
import { moveVideoToStorage, onMoveVideoToStorageFailure } from './shared/move-video.js'
-const lTagsBase = loggerTagsFactory('move-file-system')
+const logger = createLogger()
export async function moveVideoToFS (options: {
videoUUID: string
@@ -37,14 +37,11 @@ export async function moveVideoToFS (options: {
moveVideoState?: {
previousVideoState: VideoStateType
}
-
- loggerTags: LoggerTags['tags']
}) {
- const { videoUUID, moveVideoState, loggerTags } = options
+ const { videoUUID, moveVideoState } = options
await moveVideoToStorage({
videoUUID,
- loggerTags: [ ...lTagsBase().tags, ...loggerTags ],
targetStorage: FileStorage.FILE_SYSTEM,
@@ -63,30 +60,19 @@ export async function moveVideoToFS (options: {
export function moveCaptionToFS (options: {
captionId: number
- loggerTags: LoggerTags['tags']
}) {
- const { captionId, loggerTags } = options
+ const { captionId } = options
- return moveCaptionToStorage({
- captionId,
- loggerTags: [ ...lTagsBase().tags, ...loggerTags ],
- moveCaptionFiles
- })
+ return moveCaptionToStorage({ captionId, moveCaptionFiles })
}
export async function onMoveVideoToFSFailure (options: {
videoUUID: string
- loggerTags: LoggerTags['tags']
err: Error
}) {
- const { videoUUID, err, loggerTags } = options
+ const { videoUUID, err } = options
- await onMoveVideoToStorageFailure({
- videoUUID,
- err,
- loggerTags: [ ...lTagsBase().tags, ...loggerTags ],
- moveToFailedState: moveToFailedMoveToFileSystemState
- })
+ await onMoveVideoToStorageFailure({ videoUUID, err, moveToFailedState: moveToFailedMoveToFileSystemState })
}
// ---------------------------------------------------------------------------
@@ -109,7 +95,7 @@ async function moveVideoSourceFile (source: MVideoSource) {
source.storage = FileStorage.FILE_SYSTEM
await source.save()
- logger.debug('Removing original video file %s because it\'s now on file system', oldFileUrl, lTagsBase())
+ logger.debug('Removing original video file %s because it\'s now on file system', oldFileUrl)
await removeOriginalFileObjectStorage(source)
}
@@ -193,7 +179,7 @@ async function onVideoFileMoved (options: {
await updateTorrentForFileAndSave(videoOrPlaylist, file)
- logger.debug('Removing web video file %s because it\'s now on file system', oldFileUrl, lTagsBase())
+ logger.debug('Removing web video file %s because it\'s now on file system', oldFileUrl)
await objetStorageRemover()
}
@@ -216,7 +202,7 @@ async function moveCaptionFiles (captions: MVideoCaption[], hls: MStreamingPlayl
await caption.save()
- logger.debug('Removing caption file %s because it\'s now on file system', oldFileUrl, lTagsBase())
+ logger.debug('Removing caption file %s because it\'s now on file system', oldFileUrl)
await removeCaptionObjectStorage(caption)
}
@@ -236,7 +222,7 @@ async function moveCaptionFiles (captions: MVideoCaption[], hls: MStreamingPlayl
await caption.save()
if (oldM3U8Filename) {
- logger.debug(`Removing video caption playlist file ${oldM3U8Url} because it's now on file system`, lTagsBase())
+ logger.debug(`Removing video caption playlist file ${oldM3U8Url} because it's now on file system`)
await removeHLSFileObjectStorageByFilename(hls.Video, oldM3U8Filename)
}
diff --git a/server/core/lib/move-storage/move-to-object-storage.ts b/server/core/lib/move-storage/move-to-object-storage.ts
index 3ef61eb3cf..3ffc695d2a 100644
--- a/server/core/lib/move-storage/move-to-object-storage.ts
+++ b/server/core/lib/move-storage/move-to-object-storage.ts
@@ -1,5 +1,5 @@
import { FileStorage, VideoStateType } from '@peertube/peertube-models'
-import { logger, LoggerTags, loggerTagsFactory } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { P2P_MEDIA_LOADER_PEER_VERSION } from '@server/initializers/constants.js'
import { buildCaptionM3U8Content } from '@server/lib/hls.js'
import {
@@ -25,7 +25,7 @@ import { scheduleVideoFederation } from '../activitypub/videos/federate.js'
import { moveCaptionToStorage } from './shared/move-caption.js'
import { moveVideoToStorage, onMoveVideoToStorageFailure } from './shared/move-video.js'
-const lTagsBase = loggerTagsFactory('object-storage', 'move-object-storage')
+const logger = createLogger()
export async function moveVideoToObjectStorage (options: {
videoUUID: string
@@ -33,14 +33,11 @@ export async function moveVideoToObjectStorage (options: {
moveVideoState?: {
previousVideoState: VideoStateType
}
-
- loggerTags: LoggerTags['tags']
}) {
- const { videoUUID, moveVideoState, loggerTags } = options
+ const { videoUUID, moveVideoState } = options
await moveVideoToStorage({
videoUUID,
- loggerTags: [ ...lTagsBase().tags, ...loggerTags ],
targetStorage: FileStorage.OBJECT_STORAGE,
@@ -60,30 +57,19 @@ export async function moveVideoToObjectStorage (options: {
export function moveCaptionToObjectStorage (options: {
captionId: number
- loggerTags: LoggerTags['tags']
}) {
- const { captionId, loggerTags } = options
+ const { captionId } = options
- return moveCaptionToStorage({
- captionId,
- loggerTags: [ ...lTagsBase().tags, ...loggerTags ],
- moveCaptionFiles
- })
+ return moveCaptionToStorage({ captionId, moveCaptionFiles })
}
export async function onMoveVideoToObjectStorageFailure (options: {
videoUUID: string
- loggerTags: LoggerTags['tags']
err: Error
}) {
- const { videoUUID, err, loggerTags } = options
+ const { videoUUID, err } = options
- await onMoveVideoToStorageFailure({
- videoUUID,
- err,
- loggerTags: [ ...lTagsBase().tags, ...loggerTags ],
- moveToFailedState: moveToFailedMoveToObjectStorageState
- })
+ await onMoveVideoToStorageFailure({ videoUUID, err, moveToFailedState: moveToFailedMoveToObjectStorageState })
}
// ---------------------------------------------------------------------------
@@ -97,7 +83,7 @@ async function moveVideoSourceFile (source: MVideoSource) {
source.storage = FileStorage.OBJECT_STORAGE
await source.save()
- logger.debug('Removing original video file ' + sourcePath + ' because it\'s now on object storage', lTagsBase())
+ logger.debug('Removing original video file ' + sourcePath + ' because it\'s now on object storage')
await remove(sourcePath)
}
@@ -117,7 +103,7 @@ async function moveCaptionFiles (captions: MVideoCaption[], hls: MStreamingPlayl
await caption.save()
- logger.debug(`Removing video caption file ${captionPath} because it's now on object storage`, lTagsBase())
+ logger.debug(`Removing video caption file ${captionPath} because it's now on object storage`)
await remove(captionPath)
}
@@ -140,7 +126,7 @@ async function moveCaptionFiles (captions: MVideoCaption[], hls: MStreamingPlayl
await caption.save()
if (m3u8PathToRemove) {
- logger.debug(`Removing video caption playlist file ${m3u8PathToRemove} because it's now on object storage`, lTagsBase())
+ logger.debug(`Removing video caption playlist file ${m3u8PathToRemove} because it's now on object storage`)
await remove(m3u8PathToRemove)
}
}
@@ -224,6 +210,6 @@ async function onVideoFileMoved (options: {
await updateTorrentForFileAndSave(videoOrPlaylist, file)
- logger.debug('Removing %s because it\'s now on object storage', oldPath, lTagsBase())
+ logger.debug('Removing %s because it\'s now on object storage', oldPath)
await remove(oldPath)
}
diff --git a/server/core/lib/move-storage/shared/move-caption.ts b/server/core/lib/move-storage/shared/move-caption.ts
index d78a288804..c36708103b 100644
--- a/server/core/lib/move-storage/shared/move-caption.ts
+++ b/server/core/lib/move-storage/shared/move-caption.ts
@@ -1,40 +1,40 @@
-import { logger, LoggerTags, loggerTagsFactory } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { scheduleVideoFederation } from '@server/lib/activitypub/videos/federate.js'
import { VideoPathManager } from '@server/lib/video-path-manager.js'
import { VideoCaptionModel } from '@server/models/video/video-caption.js'
import { VideoStreamingPlaylistModel } from '@server/models/video/video-streaming-playlist.js'
import { MStreamingPlaylistVideoUUID, MVideoCaption } from '@server/types/models/index.js'
+const logger = createLogger()
+
export async function moveCaptionToStorage (options: {
captionId: number
- loggerTags: LoggerTags['tags']
moveCaptionFiles: (captions: MVideoCaption[], hls: MStreamingPlaylistVideoUUID) => Promise<void>
}) {
const {
- loggerTags,
captionId,
moveCaptionFiles
} = options
- const lTagsBase = loggerTagsFactory(...loggerTags)
-
const caption = await VideoCaptionModel.loadWithVideo(captionId)
if (!caption) {
- logger.info(`Can't process caption ${captionId}, caption does not exist anymore.`, lTagsBase())
+ logger.info(`Can't process caption ${captionId}, caption does not exist anymore.`)
return
}
- const fileMutexReleaser = await VideoPathManager.Instance.lockFiles(caption.Video.uuid)
+ await logger.withContext([ caption.Video.uuid ], async () => {
+ const fileMutexReleaser = await VideoPathManager.Instance.lockFiles(caption.Video.uuid)
- const hls = await VideoStreamingPlaylistModel.loadHLSByVideoWithVideo(caption.videoId)
+ const hls = await VideoStreamingPlaylistModel.loadHLSByVideoWithVideo(caption.videoId)
- try {
- await moveCaptionFiles([ caption ], hls)
+ try {
+ await moveCaptionFiles([ caption ], hls)
- scheduleVideoFederation({ video: caption.Video })
- } finally {
- fileMutexReleaser()
- }
+ scheduleVideoFederation({ video: caption.Video })
+ } finally {
+ fileMutexReleaser()
+ }
+ })
}
diff --git a/server/core/lib/move-storage/shared/move-video.ts b/server/core/lib/move-storage/shared/move-video.ts
index 2fb073f350..004945818d 100644
--- a/server/core/lib/move-storage/shared/move-video.ts
+++ b/server/core/lib/move-storage/shared/move-video.ts
@@ -1,5 +1,5 @@
import { FileStorageType } from '@peertube/peertube-models'
-import { LoggerTags, logger, loggerTagsFactory } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { VideoPathManager } from '@server/lib/video-path-manager.js'
import { VideoCaptionModel } from '@server/models/video/video-caption.js'
import { VideoJobInfoModel } from '@server/models/video/video-job-info.js'
@@ -8,9 +8,10 @@ import { VideoModel } from '@server/models/video/video.js'
import { MStreamingPlaylistVideoUUID, MVideo, MVideoCaption, MVideoWithAllFiles } from '@server/types/models/index.js'
import { MVideoSource } from '@server/types/models/video/video-source.js'
+const logger = createLogger()
+
export async function moveVideoToStorage (options: {
videoUUID: string
- loggerTags: LoggerTags['tags']
targetStorage: FileStorageType
@@ -20,7 +21,6 @@ export async function moveVideoToStorage (options: {
moveCaptionFiles: (captions: MVideoCaption[], hls: MStreamingPlaylistVideoUUID) => Promise<void>
}) {
const {
- loggerTags,
videoUUID,
moveVideoSourceFile,
moveHLSFiles,
@@ -29,51 +29,47 @@ export async function moveVideoToStorage (options: {
targetStorage
} = options
- const lTagsBase = loggerTagsFactory(...loggerTags)
-
const fileMutexReleaser = await VideoPathManager.Instance.lockFiles(videoUUID)
const video = await VideoModel.loadWithFiles(videoUUID)
// No video, maybe deleted?
if (!video) {
- logger.info(`Can't move video ${videoUUID}, video does not exist.`, lTagsBase(videoUUID))
+ logger.info(`Can't move video ${videoUUID}, video does not exist.`)
fileMutexReleaser()
return undefined
}
- const lTags = lTagsBase(video.uuid, video.url)
-
try {
const { source, captions, hls, webFiles } = await filterVideoResourcesToBeMoved(video, targetStorage)
if (captions.length !== 0) {
- logger.debug(`Moving ${captions.length} captions of ${video.uuid}.`, lTags)
+ logger.debug(`Moving ${captions.length} captions of ${video.uuid}.`)
const hls = video.getHLSPlaylist()
await moveCaptionFiles(captions, hls)
}
if (source) {
- logger.debug(`Moving video source ${source.keptOriginalFilename} file of video ${video.uuid}`, lTags)
+ logger.debug(`Moving video source ${source.keptOriginalFilename} file of video ${video.uuid}`)
await moveVideoSourceFile(source)
}
if (webFiles.length !== 0) {
- logger.debug(`Moving ${webFiles.length} web video files for video ${video.uuid}.`, lTags)
+ logger.debug(`Moving ${webFiles.length} web video files for video ${video.uuid}.`)
await moveWebVideoFiles(video)
}
if (hls) {
- logger.debug(`Moving HLS playlist of ${video.uuid}.`, lTags)
+ logger.debug(`Moving HLS playlist of ${video.uuid}.`)
await moveHLSFiles(video)
}
const pendingMove = await VideoJobInfoModel.decrease(video.uuid, 'pendingMove')
- logger.info(`Moved video ${video.uuid}. Remaining pending move: ${pendingMove}.`, lTags)
+ logger.info(`Moved video ${video.uuid}. Remaining pending move: ${pendingMove}.`)
} finally { // Error handling is managed by the job queue
fileMutexReleaser()
}
@@ -82,15 +78,14 @@ export async function moveVideoToStorage (options: {
export async function onMoveVideoToStorageFailure (options: {
videoUUID: string
err: any
- loggerTags: LoggerTags['tags']
moveToFailedState: (video: MVideoWithAllFiles) => Promise<void>
}) {
- const { videoUUID, err, loggerTags, moveToFailedState } = options
+ const { videoUUID, err, moveToFailedState } = options
const video = await VideoModel.loadWithFiles(videoUUID)
if (!video) return
- logger.error(`Cannot move video ${video.url} storage.`, { err, tags: loggerTags })
+ logger.error(`Cannot move video ${video.url} storage.`, { err })
await moveToFailedState(video)
await VideoJobInfoModel.abortAllTasks(video.uuid, 'pendingMove')
diff --git a/server/core/lib/notifier/notifier.ts b/server/core/lib/notifier/notifier.ts
index fd2353bbbe..530ad15208 100644
--- a/server/core/lib/notifier/notifier.ts
+++ b/server/core/lib/notifier/notifier.ts
@@ -1,7 +1,7 @@
import { UserNotificationSettingValue, UserNotificationSettingValueType } from '@peertube/peertube-models'
import { MRegistration, MUser, MUserDefault, MUserWithNotificationSetting } from '@server/types/models/user/index.js'
import { MVideoBlacklistLightVideo, MVideoBlacklistVideo } from '@server/types/models/video/video-blacklist.js'
-import { logger, loggerTagsFactory } from '../../helpers/logger.js'
+import { createLogger } from '../../helpers/logger.js'
import { CONFIG } from '../../initializers/config.js'
import {
MAbuseFull,
@@ -61,7 +61,7 @@ import {
VideoTranscriptionGeneratedForOwner
} from './shared/index.js'
-const lTags = loggerTagsFactory('notifier')
+const logger = createLogger('notifier')
class Notifier {
private readonly notificationModels = {
@@ -119,7 +119,7 @@ class Notifier {
notifyOnNewVideoOrLiveIfNeeded (video: MVideoAccountLight): void {
const models = this.notificationModels.newVideoOrLive
- logger.debug('Notify on new video or live if needed', { video: video.url, ...lTags() })
+ logger.debug('Notify on new video or live if needed', { video: video.url })
this.sendNotifications(models, video)
.catch(err => logger.error('Cannot notify subscribers of new video %s.', video.url, { err }))
@@ -128,7 +128,7 @@ class Notifier {
notifyOnVideoPublishedAfterTranscoding (video: MVideoAccountLight & MVideoWithSchedule): void {
const models = this.notificationModels.publicationAfterTranscoding
- logger.debug('Notify on published video after transcoding', { video: video.url, ...lTags() })
+ logger.debug('Notify on published video after transcoding', { video: video.url })
this.sendNotifications(models, video)
.catch(err => logger.error('Cannot notify owner that its video %s has been published after transcoding.', video.url, { err }))
@@ -137,7 +137,7 @@ class Notifier {
notifyOnVideoPublishedAfterScheduledUpdate (video: MVideoAccountLight & MVideoWithSchedule): void {
const models = this.notificationModels.publicationAfterScheduleUpdate
- logger.debug('Notify on published video after scheduled update', { video: video.url, ...lTags() })
+ logger.debug('Notify on published video after scheduled update', { video: video.url })
this.sendNotifications(models, video)
.catch(err => logger.error('Cannot notify owner that its video %s has been published after scheduled update.', video.url, { err }))
@@ -146,7 +146,7 @@ class Notifier {
notifyOnVideoPublishedAfterRemovedFromAutoBlacklist (video: MVideoAccountLight & MVideoWithSchedule): void {
const models = this.notificationModels.publicationAfterAutoUnblacklist
- logger.debug('Notify on published video after being removed from auto blacklist', { video: video.url, ...lTags() })
+ logger.debug('Notify on published video after being removed from auto blacklist', { video: video.url })
this.sendNotifications(models, video)
.catch(err => {
@@ -157,7 +157,7 @@ class Notifier {
notifyOnNewComment (comment: MCommentOwnerVideo): void {
const models = this.notificationModels.newComment
- logger.debug('Notify on new comment', { comment: comment.url, ...lTags() })
+ logger.debug('Notify on new comment', { comment: comment.url })
this.sendNotifications(models, comment)
.catch(err => logger.error('Cannot notify of new comment %s.', comment.url, { err }))
@@ -166,7 +166,7 @@ class Notifier {
notifyOnNewCommentApproval (comment: MCommentOwnerVideo): void {
const models = this.notificationModels.commentApproval
- logger.debug('Notify on comment approval', { comment: comment.url, ...lTags() })
+ logger.debug('Notify on comment approval', { comment: comment.url })
this.sendNotifications(models, comment)
.catch(err => logger.error('Cannot notify on comment approval %s.', comment.url, { err }))
@@ -175,7 +175,7 @@ class Notifier {
notifyOnNewAbuse (payload: NewAbusePayload): void {
const models = this.notificationModels.newAbuse
- logger.debug('Notify on new abuse', { abuse: payload.abuseInstance.id, ...lTags() })
+ logger.debug('Notify on new abuse', { abuse: payload.abuseInstance.id })
this.sendNotifications(models, payload)
.catch(err => logger.error('Cannot notify of new abuse %d.', payload.abuseInstance.id, { err }))
@@ -184,7 +184,7 @@ class Notifier {
notifyOnVideoAutoBlacklist (videoBlacklist: MVideoBlacklistLightVideo): void {
const models = this.notificationModels.newAutoBlacklist
- logger.debug('Notify on video auto blacklist', { video: videoBlacklist?.Video?.url, ...lTags() })
+ logger.debug('Notify on video auto blacklist', { video: videoBlacklist?.Video?.url })
this.sendNotifications(models, videoBlacklist)
.catch(err => logger.error('Cannot notify of auto-blacklist of video %s.', videoBlacklist.Video.url, { err }))
@@ -193,7 +193,7 @@ class Notifier {
notifyOnVideoBlacklist (videoBlacklist: MVideoBlacklistVideo): void {
const models = this.notificationModels.newBlacklist
- logger.debug('Notify on video manual blacklist', { video: videoBlacklist?.Video?.url, ...lTags() })
+ logger.debug('Notify on video manual blacklist', { video: videoBlacklist?.Video?.url })
this.sendNotifications(models, videoBlacklist)
.catch(err => logger.error('Cannot notify video owner of new video blacklist of %s.', videoBlacklist.Video.url, { err }))
@@ -202,7 +202,7 @@ class Notifier {
notifyOnVideoUnblacklist (video: MVideoAccountLight): void {
const models = this.notificationModels.unblacklist
- logger.debug('Notify on video unblacklist', { video: video.url, ...lTags() })
+ logger.debug('Notify on video unblacklist', { video: video.url })
this.sendNotifications(models, video)
.catch(err => logger.error('Cannot notify video owner of unblacklist of %s.', video.url, { err }))
@@ -211,7 +211,7 @@ class Notifier {
notifyOnFinishedVideoImport (payload: ImportFinishedForOwnerPayload): void {
const models = this.notificationModels.importFinished
- logger.debug('Notify on finished video import', { import: payload.videoImport.getTargetIdentifier(), ...lTags() })
+ logger.debug('Notify on finished video import', { import: payload.videoImport.getTargetIdentifier() })
this.sendNotifications(models, payload)
.catch(err => {
@@ -222,7 +222,7 @@ class Notifier {
notifyOnNewDirectRegistration (user: MUserDefault): void {
const models = this.notificationModels.directRegistration
- logger.debug('Notify on new direct registration', { user: user.username, ...lTags() })
+ logger.debug('Notify on new direct registration', { user: user.username })
this.sendNotifications(models, user)
.catch(err => logger.error('Cannot notify moderators of new user registration (%s).', user.username, { err }))
@@ -231,7 +231,7 @@ class Notifier {
notifyOnNewRegistrationRequest (registration: MRegistration): void {
const models = this.notificationModels.registrationRequest
- logger.debug('Notify on new registration request', { registration: registration.username, ...lTags() })
+ logger.debug('Notify on new registration request', { registration: registration.username })
this.sendNotifications(models, registration)
.catch(err => logger.error('Cannot notify moderators of new registration request (%s).', registration.username, { err }))
@@ -243,7 +243,7 @@ class Notifier {
const following = actorFollow?.ActorFollowing?.VideoChannel?.getDisplayName()
const follower = actorFollow?.ActorFollower?.Account?.getDisplayName()
- logger.debug('Notify on new user follow', { following, follower, ...lTags() })
+ logger.debug('Notify on new user follow', { following, follower })
this.sendNotifications(models, actorFollow)
.catch(err => {
@@ -254,7 +254,7 @@ class Notifier {
notifyOfNewInstanceFollow (actorFollow: MActorFollowFull): void {
const models = this.notificationModels.instanceFollow
- logger.debug('Notify on new instance follow', { follower: actorFollow.ActorFollower.url, ...lTags() })
+ logger.debug('Notify on new instance follow', { follower: actorFollow.ActorFollower.url })
this.sendNotifications(models, actorFollow)
.catch(err => logger.error('Cannot notify administrators of new follower %s.', actorFollow.ActorFollower.url, { err }))
@@ -263,7 +263,7 @@ class Notifier {
notifyOfAutoInstanceFollowing (actorFollow: MActorFollowFull): void {
const models = this.notificationModels.autoInstanceFollow
- logger.debug('Notify on new instance auto following', { following: actorFollow.ActorFollowing.url, ...lTags() })
+ logger.debug('Notify on new instance auto following', { following: actorFollow.ActorFollowing.url })
this.sendNotifications(models, actorFollow)
.catch(err => logger.error('Cannot notify administrators of auto instance following %s.', actorFollow.ActorFollowing.url, { err }))
@@ -272,7 +272,7 @@ class Notifier {
notifyOnAbuseStateChange (abuse: MAbuseFull): void {
const models = this.notificationModels.abuseStateChange
- logger.debug('Notify on abuse state change', { abuse: abuse.id, ...lTags() })
+ logger.debug('Notify on abuse state change', { abuse: abuse.id })
this.sendNotifications(models, abuse)
.catch(err => logger.error('Cannot notify of abuse %d state change.', abuse.id, { err }))
@@ -281,7 +281,7 @@ class Notifier {
notifyOnAbuseMessage (abuse: MAbuseFull, message: MAbuseMessage): void {
const models = this.notificationModels.newAbuseMessage
- logger.debug('Notify on abuse message', { abuse: abuse.id, message, ...lTags() })
+ logger.debug('Notify on abuse message', { abuse: abuse.id, message })
this.sendNotifications(models, { abuse, message })
.catch(err => logger.error('Cannot notify on new abuse %d message.', abuse.id, { err }))
@@ -290,7 +290,7 @@ class Notifier {
notifyOfNewPeerTubeVersion (application: MApplication, latestVersion: string) {
const models = this.notificationModels.newPeertubeVersion
- logger.debug('Notify on new peertube version', { currentVersion: application.version, latestVersion, ...lTags() })
+ logger.debug('Notify on new peertube version', { currentVersion: application.version, latestVersion })
this.sendNotifications(models, { application, latestVersion })
.catch(err => logger.error('Cannot notify on new PeerTube version %s.', latestVersion, { err }))
@@ -299,7 +299,7 @@ class Notifier {
notifyOfNewPluginVersion (plugin: MPlugin) {
const models = this.notificationModels.newPluginVersion
- logger.debug('Notify on new plugin version', { plugin: plugin.name, ...lTags() })
+ logger.debug('Notify on new plugin version', { plugin: plugin.name })
this.sendNotifications(models, plugin)
.catch(err => logger.error('Cannot notify on new plugin version %s.', plugin.name, { err }))
@@ -313,7 +313,7 @@ class Notifier {
}) {
const models = this.notificationModels.automaticBlocklist
- logger.debug(`Notify on automatic blocklist subscription update`, { ...options, ...lTags() })
+ logger.debug(`Notify on automatic blocklist subscription update`, { ...options })
this.sendNotifications(models, options)
.catch(err => logger.error(`Cannot notify on automatic blocklist update.`, { err, ...options }))
@@ -322,7 +322,7 @@ class Notifier {
notifyOfFinishedVideoStudioEdition (video: MVideoFull) {
const models = this.notificationModels.videoStudioEditionFinished
- logger.debug('Notify on finished video studio edition', { video: video.url, ...lTags() })
+ logger.debug('Notify on finished video studio edition', { video: video.url })
this.sendNotifications(models, video)
.catch(err => logger.error('Cannot notify on finished studio edition %s.', video.url, { err }))
@@ -332,7 +332,7 @@ class Notifier {
const models = this.notificationModels.videoTranscriptionGenerated
const video = caption.Video
- logger.debug('Notify on generated video transcription', { language: caption.language, video: video.url, ...lTags() })
+ logger.debug('Notify on generated video transcription', { language: caption.language, video: video.url })
this.sendNotifications(models, caption)
.catch(err => logger.error('Cannot notify on generated video transcription %s of video %s.', caption.language, video.url, { err }))
@@ -344,7 +344,7 @@ class Notifier {
const channelName = channel.Actor.preferredUsername
const collaboratorName = collaborator.Account.Actor.preferredUsername
- logger.debug('Notify on channel collaborator invitation', { channelName, collaboratorName, ...lTags() })
+ logger.debug('Notify on channel collaborator invitation', { channelName, collaboratorName })
this.sendNotifications(models, { channel, collaborator })
.catch(err => logger.error(`Cannot notify ${collaboratorName} of invitation to collaborate to channel ${channelName}`, { err }))
@@ -356,7 +356,7 @@ class Notifier {
const channelName = channel.Actor.preferredUsername
const channelOwner = collaborator.Account.Actor.preferredUsername
- logger.debug('Notify of accepted channel collaboration invitation', { channelName, channelOwner, ...lTags() })
+ logger.debug('Notify of accepted channel collaboration invitation', { channelName, channelOwner })
this.sendNotifications(models, { channel, collaborator })
.catch(err => logger.error(`Cannot notify ${channelOwner} of accepted invitation to collaborate to channel ${channelName}`, { err }))
@@ -368,7 +368,7 @@ class Notifier {
const channelName = channel.Actor.preferredUsername
const channelOwner = collaborator.Account.Actor.preferredUsername
- logger.debug('Notify of refused channel collaboration invitation', { channelName, channelOwner, ...lTags() })
+ logger.debug('Notify of refused channel collaboration invitation', { channelName, channelOwner })
this.sendNotifications(models, { channel, collaborator })
.catch(err => logger.error(`Cannot notify ${channelOwner} of refused invitation to collaborate to channel ${channelName}`, { err }))
@@ -381,7 +381,7 @@ class Notifier {
notifyOfRequestedVideoOwnershipChange (changeOwnership: MChangeOwnershipFull) {
const models = this.notificationModels.changeVideoOwnershipRequest
- logger.debug('Notify on requested video ownership change', { id: changeOwnership.id, video: changeOwnership.Video.url, ...lTags() })
+ logger.debug('Notify on requested video ownership change', { id: changeOwnership.id, video: changeOwnership.Video.url })
this.sendNotifications(models, changeOwnership)
.catch(err => logger.error('Cannot notify requested video ownership change %d.', changeOwnership.id, { err }))
@@ -390,7 +390,7 @@ class Notifier {
notifyOfAcceptedVideoOwnershipChange (changeOwnership: MChangeOwnershipFull) {
const models = this.notificationModels.changeVideoOwnershipAccepted
- logger.debug('Notify on accepted video ownership change', { id: changeOwnership.id, video: changeOwnership.Video.url, ...lTags() })
+ logger.debug('Notify on accepted video ownership change', { id: changeOwnership.id, video: changeOwnership.Video.url })
this.sendNotifications(models, changeOwnership)
.catch(err => logger.error('Cannot notify accepted video ownership change %d.', changeOwnership.id, { err }))
@@ -399,7 +399,7 @@ class Notifier {
notifyOfRejectedVideoOwnershipChange (changeOwnership: MChangeOwnershipFull) {
const models = this.notificationModels.changeVideoOwnershipRejected
- logger.debug('Notify on rejected video ownership change', { id: changeOwnership.id, video: changeOwnership.Video.url, ...lTags() })
+ logger.debug('Notify on rejected video ownership change', { id: changeOwnership.id, video: changeOwnership.Video.url })
this.sendNotifications(models, changeOwnership)
.catch(err => logger.error('Cannot notify rejected video ownership change %d.', changeOwnership.id, { err }))
@@ -414,7 +414,7 @@ class Notifier {
const channelName = changeOwnership.VideoChannel.Actor.preferredUsername
- logger.debug(`Notify on requested channel ${channelName} ownership change`, { id: changeOwnership.id, channelName, ...lTags() })
+ logger.debug(`Notify on requested channel ${channelName} ownership change`, { id: changeOwnership.id, channelName })
this.sendNotifications(models, changeOwnership)
.catch(err => logger.error('Cannot notify requested channel ownership change %d.', changeOwnership.id, { err }))
@@ -425,7 +425,7 @@ class Notifier {
const channelName = changeOwnership.VideoChannel.Actor.preferredUsername
- logger.debug(`Notify on accepted channel ${channelName} ownership change`, { id: changeOwnership.id, channelName, ...lTags() })
+ logger.debug(`Notify on accepted channel ${channelName} ownership change`, { id: changeOwnership.id, channelName })
this.sendNotifications(models, changeOwnership)
.catch(err => logger.error('Cannot notify accepted channel ownership change %d.', changeOwnership.id, { err }))
@@ -436,7 +436,7 @@ class Notifier {
const channelName = changeOwnership.VideoChannel.Actor.preferredUsername
- logger.debug(`Notify on rejected channel ${channelName} ownership change`, { id: changeOwnership.id, channelName, ...lTags() })
+ logger.debug(`Notify on rejected channel ${channelName} ownership change`, { id: changeOwnership.id, channelName })
this.sendNotifications(models, changeOwnership)
.catch(err => logger.error('Cannot notify rejected channel ownership change %d.', changeOwnership.id, { err }))
diff --git a/server/core/lib/notifier/shared/abuse/abuse-state-change-for-reporter.ts b/server/core/lib/notifier/shared/abuse/abuse-state-change-for-reporter.ts
index 7f12aa4e92..9caa28a113 100644
--- a/server/core/lib/notifier/shared/abuse/abuse-state-change-for-reporter.ts
+++ b/server/core/lib/notifier/shared/abuse/abuse-state-change-for-reporter.ts
@@ -1,6 +1,6 @@
import { AbuseState, UserNotificationType } from '@peertube/peertube-models'
import { t } from '@server/helpers/i18n.js'
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { getAbuseIdentifier } from '@server/lib/activitypub/url.js'
import { getUserAbuseUrl } from '@server/lib/client-urls.js'
import { UserNotificationModel } from '@server/models/user/user-notification.js'
@@ -8,6 +8,8 @@ import { UserModel } from '@server/models/user/user.js'
import { MAbuseFull, MUserDefault, MUserWithNotificationSetting, UserNotificationModelForApi } from '@server/types/models/index.js'
import { AbstractNotification } from '../common/abstract-notification.js'
+const logger = createLogger()
+
export class AbuseStateChangeForReporter extends AbstractNotification<MAbuseFull> {
private user: MUserDefault
diff --git a/server/core/lib/notifier/shared/abuse/new-abuse-for-moderators.ts b/server/core/lib/notifier/shared/abuse/new-abuse-for-moderators.ts
index f5f87d9155..fec77f25e9 100644
--- a/server/core/lib/notifier/shared/abuse/new-abuse-for-moderators.ts
+++ b/server/core/lib/notifier/shared/abuse/new-abuse-for-moderators.ts
@@ -1,6 +1,6 @@
import { MailTo, UserAbuse, UserNotificationType, UserRight } from '@peertube/peertube-models'
import { t } from '@server/helpers/i18n.js'
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { WEBSERVER } from '@server/initializers/constants.js'
import { getAbuseIdentifier } from '@server/lib/activitypub/url.js'
import { getAdminAbuseUrl } from '@server/lib/client-urls.js'
@@ -9,6 +9,8 @@ import { UserModel } from '@server/models/user/user.js'
import { MAbuseFull, MUserDefault, MUserWithNotificationSetting, UserNotificationModelForApi } from '@server/types/models/index.js'
import { AbstractNotification } from '../common/abstract-notification.js'
+const logger = createLogger()
+
export type NewAbusePayload = { abuse: Pick<UserAbuse, 'reason' | 'video'>, abuseInstance: MAbuseFull, reporter: string }
export class NewAbuseForModerators extends AbstractNotification<NewAbusePayload> {
diff --git a/server/core/lib/notifier/shared/abuse/new-abuse-message-for-moderators.ts b/server/core/lib/notifier/shared/abuse/new-abuse-message-for-moderators.ts
index 9f0f7e3f0c..8551ff6c82 100644
--- a/server/core/lib/notifier/shared/abuse/new-abuse-message-for-moderators.ts
+++ b/server/core/lib/notifier/shared/abuse/new-abuse-message-for-moderators.ts
@@ -1,10 +1,12 @@
import { UserRight } from '@peertube/peertube-models'
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { getAbuseIdentifier } from '@server/lib/activitypub/url.js'
import { UserModel } from '@server/models/user/user.js'
import { MUserDefault, MUserWithNotificationSetting } from '@server/types/models/index.js'
import { AbstractNewAbuseMessage } from './abstract-new-abuse-message.js'
+const logger = createLogger()
+
export class NewAbuseMessageForModerators extends AbstractNewAbuseMessage {
private moderators: MUserDefault[]
diff --git a/server/core/lib/notifier/shared/abuse/new-abuse-message-for-reporter.ts b/server/core/lib/notifier/shared/abuse/new-abuse-message-for-reporter.ts
index 810eda9161..915f648650 100644
--- a/server/core/lib/notifier/shared/abuse/new-abuse-message-for-reporter.ts
+++ b/server/core/lib/notifier/shared/abuse/new-abuse-message-for-reporter.ts
@@ -1,9 +1,11 @@
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { getAbuseIdentifier } from '@server/lib/activitypub/url.js'
import { UserModel } from '@server/models/user/user.js'
import { MUserDefault, MUserWithNotificationSetting } from '@server/types/models/index.js'
import { AbstractNewAbuseMessage } from './abstract-new-abuse-message.js'
+const logger = createLogger()
+
export class NewAbuseMessageForReporter extends AbstractNewAbuseMessage {
private reporter: MUserDefault
diff --git a/server/core/lib/notifier/shared/blacklist/new-auto-blacklist-for-moderators.ts b/server/core/lib/notifier/shared/blacklist/new-auto-blacklist-for-moderators.ts
index 6ab7771c00..676e62687a 100644
--- a/server/core/lib/notifier/shared/blacklist/new-auto-blacklist-for-moderators.ts
+++ b/server/core/lib/notifier/shared/blacklist/new-auto-blacklist-for-moderators.ts
@@ -1,6 +1,6 @@
import { UserNotificationType, UserRight } from '@peertube/peertube-models'
import { tu } from '@server/helpers/i18n.js'
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { WEBSERVER } from '@server/initializers/constants.js'
import { videoAutoBlacklistUrl } from '@server/lib/client-urls.js'
import { UserNotificationModel } from '@server/models/user/user-notification.js'
@@ -14,6 +14,8 @@ import {
} from '@server/types/models/index.js'
import { AbstractNotification } from '../common/abstract-notification.js'
+const logger = createLogger()
+
export class NewAutoBlacklistForModerators extends AbstractNotification<MVideoBlacklistLightVideo> {
private moderators: MUserDefault[]
diff --git a/server/core/lib/notifier/shared/blacklist/new-blacklist-for-owner.ts b/server/core/lib/notifier/shared/blacklist/new-blacklist-for-owner.ts
index 4b04d002e5..2bfce5701a 100644
--- a/server/core/lib/notifier/shared/blacklist/new-blacklist-for-owner.ts
+++ b/server/core/lib/notifier/shared/blacklist/new-blacklist-for-owner.ts
@@ -1,6 +1,6 @@
import { UserNotificationType } from '@peertube/peertube-models'
import { tu } from '@server/helpers/i18n.js'
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { WEBSERVER } from '@server/initializers/constants.js'
import { UserNotificationModel } from '@server/models/user/user-notification.js'
import { UserModel } from '@server/models/user/user.js'
@@ -12,6 +12,8 @@ import {
} from '@server/types/models/index.js'
import { AbstractNotification } from '../common/abstract-notification.js'
+const logger = createLogger()
+
export class NewBlacklistForOwner extends AbstractNotification<MVideoBlacklistVideo> {
private user: MUserDefault
diff --git a/server/core/lib/notifier/shared/blacklist/unblacklist-for-owner.ts b/server/core/lib/notifier/shared/blacklist/unblacklist-for-owner.ts
index babc407598..335ac2d968 100644
--- a/server/core/lib/notifier/shared/blacklist/unblacklist-for-owner.ts
+++ b/server/core/lib/notifier/shared/blacklist/unblacklist-for-owner.ts
@@ -1,12 +1,14 @@
import { UserNotificationType } from '@peertube/peertube-models'
import { tu } from '@server/helpers/i18n.js'
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { WEBSERVER } from '@server/initializers/constants.js'
import { UserNotificationModel } from '@server/models/user/user-notification.js'
import { UserModel } from '@server/models/user/user.js'
import { MUserDefault, MUserWithNotificationSetting, MVideoAccountLight, UserNotificationModelForApi } from '@server/types/models/index.js'
import { AbstractNotification } from '../common/abstract-notification.js'
+const logger = createLogger()
+
export class UnblacklistForOwner extends AbstractNotification<MVideoAccountLight> {
private user: MUserDefault
diff --git a/server/core/lib/notifier/shared/caption/video-transcription-generated-for-owner.ts b/server/core/lib/notifier/shared/caption/video-transcription-generated-for-owner.ts
index bcb0a2dc7a..02dbcbf3c2 100644
--- a/server/core/lib/notifier/shared/caption/video-transcription-generated-for-owner.ts
+++ b/server/core/lib/notifier/shared/caption/video-transcription-generated-for-owner.ts
@@ -1,12 +1,14 @@
import { UserNotificationType } from '@peertube/peertube-models'
import { t } from '@server/helpers/i18n.js'
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { VIDEO_LANGUAGES, WEBSERVER } from '@server/initializers/constants.js'
import { UserNotificationModel } from '@server/models/user/user-notification.js'
import { UserModel } from '@server/models/user/user.js'
import { MUserDefault, MUserWithNotificationSetting, MVideoCaptionVideo, UserNotificationModelForApi } from '@server/types/models/index.js'
import { AbstractNotification } from '../common/abstract-notification.js'
+const logger = createLogger()
+
export class VideoTranscriptionGeneratedForOwner extends AbstractNotification<MVideoCaptionVideo> {
private user: MUserDefault
diff --git a/server/core/lib/notifier/shared/change-ownership/channel-change-ownership-accepted.ts b/server/core/lib/notifier/shared/change-ownership/channel-change-ownership-accepted.ts
index 36148c6c54..45f93a4645 100644
--- a/server/core/lib/notifier/shared/change-ownership/channel-change-ownership-accepted.ts
+++ b/server/core/lib/notifier/shared/change-ownership/channel-change-ownership-accepted.ts
@@ -1,10 +1,12 @@
import { UserNotificationType } from '@peertube/peertube-models'
import { t } from '@server/helpers/i18n.js'
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { WEBSERVER } from '@server/initializers/constants.js'
import { MUserWithNotificationSetting } from '@server/types/models/index.js'
import { AbstractChannelChangeOwnershipResponse } from './abstract-channel-change-ownership-response.js'
+const logger = createLogger()
+
export class ChannelChangeOwnershipAccepted extends AbstractChannelChangeOwnershipResponse {
log () {
logger.info(
diff --git a/server/core/lib/notifier/shared/change-ownership/channel-change-ownership-rejected.ts b/server/core/lib/notifier/shared/change-ownership/channel-change-ownership-rejected.ts
index 6da5408f36..a8256c485a 100644
--- a/server/core/lib/notifier/shared/change-ownership/channel-change-ownership-rejected.ts
+++ b/server/core/lib/notifier/shared/change-ownership/channel-change-ownership-rejected.ts
@@ -1,10 +1,12 @@
import { UserNotificationType } from '@peertube/peertube-models'
import { t } from '@server/helpers/i18n.js'
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { WEBSERVER } from '@server/initializers/constants.js'
import { MUserWithNotificationSetting } from '@server/types/models/index.js'
import { AbstractChannelChangeOwnershipResponse } from './abstract-channel-change-ownership-response.js'
+const logger = createLogger()
+
export class ChannelChangeOwnershipRejected extends AbstractChannelChangeOwnershipResponse {
log () {
logger.info(
diff --git a/server/core/lib/notifier/shared/change-ownership/request-channel-change-ownership.ts b/server/core/lib/notifier/shared/change-ownership/request-channel-change-ownership.ts
index b86072e354..c750daacff 100644
--- a/server/core/lib/notifier/shared/change-ownership/request-channel-change-ownership.ts
+++ b/server/core/lib/notifier/shared/change-ownership/request-channel-change-ownership.ts
@@ -1,6 +1,6 @@
import { UserNotificationSettingValue, UserNotificationType } from '@peertube/peertube-models'
import { t } from '@server/helpers/i18n.js'
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { WEBSERVER } from '@server/initializers/constants.js'
import { AccountBlocklistModel } from '@server/models/blocklist/account-blocklist.js'
import { UserModel } from '@server/models/user/user.js'
@@ -9,6 +9,8 @@ import { MChangeOwnershipFull } from '@server/types/models/video/change-ownershi
import { AbstractNotification } from '../common/abstract-notification.js'
import { buildChangeOwnershipNotification } from './change-ownership-utils.js'
+const logger = createLogger()
+
export class RequestChannelChangeOwnership extends AbstractNotification<MChangeOwnershipFull> {
private user: MUserDefault
private channelAccountMuted: boolean
diff --git a/server/core/lib/notifier/shared/change-ownership/request-video-change-ownership.ts b/server/core/lib/notifier/shared/change-ownership/request-video-change-ownership.ts
index e743d964b0..22f5397c25 100644
--- a/server/core/lib/notifier/shared/change-ownership/request-video-change-ownership.ts
+++ b/server/core/lib/notifier/shared/change-ownership/request-video-change-ownership.ts
@@ -1,6 +1,6 @@
import { UserNotificationSettingValue, UserNotificationType } from '@peertube/peertube-models'
import { t } from '@server/helpers/i18n.js'
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { WEBSERVER } from '@server/initializers/constants.js'
import { AccountBlocklistModel } from '@server/models/blocklist/account-blocklist.js'
import { UserModel } from '@server/models/user/user.js'
@@ -9,6 +9,8 @@ import { MChangeOwnershipFull } from '@server/types/models/video/change-ownershi
import { AbstractNotification } from '../common/abstract-notification.js'
import { buildChangeOwnershipNotification } from './change-ownership-utils.js'
+const logger = createLogger()
+
export class RequestVideoChangeOwnership extends AbstractNotification<MChangeOwnershipFull> {
private user: MUserDefault
private channelAccountMuted: boolean
diff --git a/server/core/lib/notifier/shared/change-ownership/video-change-ownership-accepted.ts b/server/core/lib/notifier/shared/change-ownership/video-change-ownership-accepted.ts
index 41dfdb158e..c70e854bf0 100644
--- a/server/core/lib/notifier/shared/change-ownership/video-change-ownership-accepted.ts
+++ b/server/core/lib/notifier/shared/change-ownership/video-change-ownership-accepted.ts
@@ -1,10 +1,12 @@
import { UserNotificationType } from '@peertube/peertube-models'
import { t } from '@server/helpers/i18n.js'
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { WEBSERVER } from '@server/initializers/constants.js'
import { MUserWithNotificationSetting } from '@server/types/models/index.js'
import { AbstractVideoChangeOwnershipResponse } from './abstract-video-change-ownership-response.js'
+const logger = createLogger()
+
export class VideoChangeOwnershipAccepted extends AbstractVideoChangeOwnershipResponse {
log () {
logger.info('Notifying source channel members that ownership change of %s was accepted.', this.payload.Video.url)
diff --git a/server/core/lib/notifier/shared/change-ownership/video-change-ownership-rejected.ts b/server/core/lib/notifier/shared/change-ownership/video-change-ownership-rejected.ts
index 674e55b050..56a3ab4d31 100644
--- a/server/core/lib/notifier/shared/change-ownership/video-change-ownership-rejected.ts
+++ b/server/core/lib/notifier/shared/change-ownership/video-change-ownership-rejected.ts
@@ -1,10 +1,12 @@
import { UserNotificationType } from '@peertube/peertube-models'
import { t } from '@server/helpers/i18n.js'
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { WEBSERVER } from '@server/initializers/constants.js'
import { MUserWithNotificationSetting } from '@server/types/models/index.js'
import { AbstractVideoChangeOwnershipResponse } from './abstract-video-change-ownership-response.js'
+const logger = createLogger()
+
export class VideoChangeOwnershipRejected extends AbstractVideoChangeOwnershipResponse {
log () {
logger.info('Notifying source channel members that ownership change of %s was rejected.', this.payload.Video.url)
diff --git a/server/core/lib/notifier/shared/channel/accepted-to-collaborate-to-channel.ts b/server/core/lib/notifier/shared/channel/accepted-to-collaborate-to-channel.ts
index b6123906ac..5ea4d423c5 100644
--- a/server/core/lib/notifier/shared/channel/accepted-to-collaborate-to-channel.ts
+++ b/server/core/lib/notifier/shared/channel/accepted-to-collaborate-to-channel.ts
@@ -1,11 +1,13 @@
import { UserNotificationSettingValue, UserNotificationType } from '@peertube/peertube-models'
import { t } from '@server/helpers/i18n.js'
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { UserModel } from '@server/models/user/user.js'
import { MUserDefault, MUserWithNotificationSetting } from '@server/types/models/index.js'
import { AbstractNotification } from '../common/abstract-notification.js'
import { buildCollaborateToChannelNotification, NotificationCollaboratePayload } from './collaborate-to-channel-utils.js'
+const logger = createLogger()
+
export class AcceptedToCollaborateToChannel extends AbstractNotification<NotificationCollaboratePayload> {
private user: MUserDefault
diff --git a/server/core/lib/notifier/shared/channel/invited-to-collaborate-to-channel.ts b/server/core/lib/notifier/shared/channel/invited-to-collaborate-to-channel.ts
index 16616b4f6e..08f4398fe2 100644
--- a/server/core/lib/notifier/shared/channel/invited-to-collaborate-to-channel.ts
+++ b/server/core/lib/notifier/shared/channel/invited-to-collaborate-to-channel.ts
@@ -1,6 +1,6 @@
import { UserNotificationSettingValue, UserNotificationType } from '@peertube/peertube-models'
import { t } from '@server/helpers/i18n.js'
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { WEBSERVER } from '@server/initializers/constants.js'
import { AccountBlocklistModel } from '@server/models/blocklist/account-blocklist.js'
import { UserModel } from '@server/models/user/user.js'
@@ -8,6 +8,8 @@ import { MUserDefault, MUserWithNotificationSetting } from '@server/types/models
import { AbstractNotification } from '../common/abstract-notification.js'
import { buildCollaborateToChannelNotification, NotificationCollaboratePayload } from './collaborate-to-channel-utils.js'
+const logger = createLogger()
+
export class InvitedToCollaborateToChannel extends AbstractNotification<NotificationCollaboratePayload> {
private user: MUserDefault
private channelAccountMuted = false
diff --git a/server/core/lib/notifier/shared/channel/refused-to-collaborate-to-channel.ts b/server/core/lib/notifier/shared/channel/refused-to-collaborate-to-channel.ts
index 44ca44dc4e..967c46c9a6 100644
--- a/server/core/lib/notifier/shared/channel/refused-to-collaborate-to-channel.ts
+++ b/server/core/lib/notifier/shared/channel/refused-to-collaborate-to-channel.ts
@@ -1,11 +1,13 @@
import { UserNotificationSettingValue, UserNotificationType } from '@peertube/peertube-models'
import { t } from '@server/helpers/i18n.js'
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { UserModel } from '@server/models/user/user.js'
import { MUserDefault, MUserWithNotificationSetting } from '@server/types/models/index.js'
import { AbstractNotification } from '../common/abstract-notification.js'
import { buildCollaborateToChannelNotification, NotificationCollaboratePayload } from './collaborate-to-channel-utils.js'
+const logger = createLogger()
+
export class RefusedToCollaborateToChannel extends AbstractNotification<NotificationCollaboratePayload> {
private user: MUserDefault
diff --git a/server/core/lib/notifier/shared/comment/comment-mention.ts b/server/core/lib/notifier/shared/comment/comment-mention.ts
index 696ab8429a..b1933484c3 100644
--- a/server/core/lib/notifier/shared/comment/comment-mention.ts
+++ b/server/core/lib/notifier/shared/comment/comment-mention.ts
@@ -1,6 +1,6 @@
import { UserNotificationSettingValue, UserNotificationType } from '@peertube/peertube-models'
import { tu } from '@server/helpers/i18n.js'
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { toSafeHtml } from '@server/helpers/markdown.js'
import { WEBSERVER } from '@server/initializers/constants.js'
import { getServerAccount } from '@server/models/application/application.js'
@@ -17,6 +17,8 @@ import {
} from '@server/types/models/index.js'
import { AbstractNotification } from '../common/index.js'
+const logger = createLogger()
+
export class CommentMention extends AbstractNotification<MCommentOwnerVideo, MUserNotifSettingAccount> {
private users: MUserDefault[]
diff --git a/server/core/lib/notifier/shared/comment/new-comment-for-video-owner.ts b/server/core/lib/notifier/shared/comment/new-comment-for-video-owner.ts
index 1b2a664950..fda31cb530 100644
--- a/server/core/lib/notifier/shared/comment/new-comment-for-video-owner.ts
+++ b/server/core/lib/notifier/shared/comment/new-comment-for-video-owner.ts
@@ -1,6 +1,6 @@
import { UserNotificationType } from '@peertube/peertube-models'
import { t } from '@server/helpers/i18n.js'
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { toSafeHtml } from '@server/helpers/markdown.js'
import { WEBSERVER } from '@server/initializers/constants.js'
import { isBlockedByServerOrAccount } from '@server/lib/blocklist.js'
@@ -9,6 +9,8 @@ import { UserModel } from '@server/models/user/user.js'
import { MCommentOwnerVideo, MUserDefault, MUserWithNotificationSetting, UserNotificationModelForApi } from '@server/types/models/index.js'
import { AbstractNotification } from '../common/abstract-notification.js'
+const logger = createLogger()
+
export class NewCommentForVideoOwner extends AbstractNotification<MCommentOwnerVideo> {
private user: MUserDefault
diff --git a/server/core/lib/notifier/shared/follow/auto-follow-for-instance.ts b/server/core/lib/notifier/shared/follow/auto-follow-for-instance.ts
index 3efade61d9..c8ed42e543 100644
--- a/server/core/lib/notifier/shared/follow/auto-follow-for-instance.ts
+++ b/server/core/lib/notifier/shared/follow/auto-follow-for-instance.ts
@@ -1,12 +1,14 @@
import { UserNotificationType, UserRight } from '@peertube/peertube-models'
import { t } from '@server/helpers/i18n.js'
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { instanceFollowingUrl } from '@server/lib/client-urls.js'
import { UserNotificationModel } from '@server/models/user/user-notification.js'
import { UserModel } from '@server/models/user/user.js'
import { MActorFollowFull, MUserDefault, MUserWithNotificationSetting, UserNotificationModelForApi } from '@server/types/models/index.js'
import { AbstractNotification } from '../common/abstract-notification.js'
+const logger = createLogger()
+
export class AutoFollowForInstance extends AbstractNotification<MActorFollowFull> {
private admins: MUserDefault[]
diff --git a/server/core/lib/notifier/shared/follow/follow-for-instance.ts b/server/core/lib/notifier/shared/follow/follow-for-instance.ts
index ec5ceee859..ce0d07ca12 100644
--- a/server/core/lib/notifier/shared/follow/follow-for-instance.ts
+++ b/server/core/lib/notifier/shared/follow/follow-for-instance.ts
@@ -1,6 +1,6 @@
import { UserNotificationType, UserRight } from '@peertube/peertube-models'
import { t } from '@server/helpers/i18n.js'
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { CONFIG } from '@server/initializers/config.js'
import { WEBSERVER } from '@server/initializers/constants.js'
import { isBlockedByServerOrAccount } from '@server/lib/blocklist.js'
@@ -9,6 +9,8 @@ import { UserModel } from '@server/models/user/user.js'
import { MActorFollowFull, MUserDefault, MUserWithNotificationSetting, UserNotificationModelForApi } from '@server/types/models/index.js'
import { AbstractNotification } from '../common/abstract-notification.js'
+const logger = createLogger()
+
export class FollowForInstance extends AbstractNotification<MActorFollowFull> {
private admins: MUserDefault[]
diff --git a/server/core/lib/notifier/shared/follow/follow-for-user.ts b/server/core/lib/notifier/shared/follow/follow-for-user.ts
index 8dd37a9ee9..12682507de 100644
--- a/server/core/lib/notifier/shared/follow/follow-for-user.ts
+++ b/server/core/lib/notifier/shared/follow/follow-for-user.ts
@@ -1,12 +1,14 @@
import { UserNotificationType } from '@peertube/peertube-models'
import { t } from '@server/helpers/i18n.js'
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { isBlockedByServerOrAccount } from '@server/lib/blocklist.js'
import { UserNotificationModel } from '@server/models/user/user-notification.js'
import { UserModel } from '@server/models/user/user.js'
import { MActorFollowFull, MUserDefault, MUserWithNotificationSetting, UserNotificationModelForApi } from '@server/types/models/index.js'
import { AbstractNotification } from '../common/abstract-notification.js'
+const logger = createLogger()
+
export class FollowForUser extends AbstractNotification<MActorFollowFull> {
private followType: 'account' | 'channel'
private user: MUserDefault
diff --git a/server/core/lib/notifier/shared/instance/automatic-blocklist-for-moderators.ts b/server/core/lib/notifier/shared/instance/automatic-blocklist-for-moderators.ts
index 00b564a52b..5b80cb87f4 100644
--- a/server/core/lib/notifier/shared/instance/automatic-blocklist-for-moderators.ts
+++ b/server/core/lib/notifier/shared/instance/automatic-blocklist-for-moderators.ts
@@ -1,13 +1,15 @@
import { pick } from '@peertube/peertube-core-utils'
import { UserNotificationType, UserRight } from '@peertube/peertube-models'
import { t } from '@server/helpers/i18n.js'
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { CONFIG } from '@server/initializers/config.js'
import { UserNotificationModel } from '@server/models/user/user-notification.js'
import { UserModel } from '@server/models/user/user.js'
import { MUserDefault, MUserWithNotificationSetting, UserNotificationModelForApi } from '@server/types/models/index.js'
import { AbstractNotification } from '../common/abstract-notification.js'
+const logger = createLogger()
+
export class AutomaticBlocklistForModerators extends AbstractNotification<{
blockedAccountsCount: number
blockedHostsCount: number
diff --git a/server/core/lib/notifier/shared/instance/direct-registration-for-moderators.ts b/server/core/lib/notifier/shared/instance/direct-registration-for-moderators.ts
index 179513a649..1b448f9d67 100644
--- a/server/core/lib/notifier/shared/instance/direct-registration-for-moderators.ts
+++ b/server/core/lib/notifier/shared/instance/direct-registration-for-moderators.ts
@@ -1,6 +1,6 @@
import { UserNotificationType, UserRight } from '@peertube/peertube-models'
import { t } from '@server/helpers/i18n.js'
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { CONFIG } from '@server/initializers/config.js'
import { adminUsersListUrl } from '@server/lib/client-urls.js'
import { UserNotificationModel } from '@server/models/user/user-notification.js'
@@ -8,6 +8,8 @@ import { UserModel } from '@server/models/user/user.js'
import { MUserDefault, MUserWithNotificationSetting, UserNotificationModelForApi } from '@server/types/models/index.js'
import { AbstractNotification } from '../common/abstract-notification.js'
+const logger = createLogger()
+
export class DirectRegistrationForModerators extends AbstractNotification<MUserDefault> {
private moderators: MUserDefault[]
diff --git a/server/core/lib/notifier/shared/instance/new-peertube-version-for-admins.ts b/server/core/lib/notifier/shared/instance/new-peertube-version-for-admins.ts
index c7944bd9c1..c67d77a09c 100644
--- a/server/core/lib/notifier/shared/instance/new-peertube-version-for-admins.ts
+++ b/server/core/lib/notifier/shared/instance/new-peertube-version-for-admins.ts
@@ -1,11 +1,13 @@
import { UserNotificationType, UserRight } from '@peertube/peertube-models'
import { t } from '@server/helpers/i18n.js'
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { UserNotificationModel } from '@server/models/user/user-notification.js'
import { UserModel } from '@server/models/user/user.js'
import { MApplication, MUserDefault, MUserWithNotificationSetting, UserNotificationModelForApi } from '@server/types/models/index.js'
import { AbstractNotification } from '../common/abstract-notification.js'
+const logger = createLogger()
+
export type NewPeerTubeVersionForAdminsPayload = {
application: MApplication
latestVersion: string
diff --git a/server/core/lib/notifier/shared/instance/new-plugin-version-for-admins.ts b/server/core/lib/notifier/shared/instance/new-plugin-version-for-admins.ts
index 091b82d2d0..a19a023505 100644
--- a/server/core/lib/notifier/shared/instance/new-plugin-version-for-admins.ts
+++ b/server/core/lib/notifier/shared/instance/new-plugin-version-for-admins.ts
@@ -1,12 +1,14 @@
import { PluginType, UserNotificationType, UserRight } from '@peertube/peertube-models'
import { t } from '@server/helpers/i18n.js'
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { getPluginUrl } from '@server/lib/client-urls.js'
import { UserNotificationModel } from '@server/models/user/user-notification.js'
import { UserModel } from '@server/models/user/user.js'
import { MPlugin, MUserDefault, MUserWithNotificationSetting, UserNotificationModelForApi } from '@server/types/models/index.js'
import { AbstractNotification } from '../common/abstract-notification.js'
+const logger = createLogger()
+
export class NewPluginVersionForAdmins extends AbstractNotification<MPlugin> {
private admins: MUserDefault[]
diff --git a/server/core/lib/notifier/shared/instance/registration-request-for-moderators.ts b/server/core/lib/notifier/shared/instance/registration-request-for-moderators.ts
index a34ae3d04d..de35c2480d 100644
--- a/server/core/lib/notifier/shared/instance/registration-request-for-moderators.ts
+++ b/server/core/lib/notifier/shared/instance/registration-request-for-moderators.ts
@@ -1,12 +1,14 @@
import { UserNotificationType, UserRight } from '@peertube/peertube-models'
import { t } from '@server/helpers/i18n.js'
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { adminRegistrationsListUrl } from '@server/lib/client-urls.js'
import { UserNotificationModel } from '@server/models/user/user-notification.js'
import { UserModel } from '@server/models/user/user.js'
import { MRegistration, MUserDefault, MUserWithNotificationSetting, UserNotificationModelForApi } from '@server/types/models/index.js'
import { AbstractNotification } from '../common/abstract-notification.js'
+const logger = createLogger()
+
export class RegistrationRequestForModerators extends AbstractNotification<MRegistration> {
private moderators: MUserDefault[]
diff --git a/server/core/lib/notifier/shared/video-publication/abstract-owned-video-publication.ts b/server/core/lib/notifier/shared/video-publication/abstract-owned-video-publication.ts
index 49d91dc728..78a60ac866 100644
--- a/server/core/lib/notifier/shared/video-publication/abstract-owned-video-publication.ts
+++ b/server/core/lib/notifier/shared/video-publication/abstract-owned-video-publication.ts
@@ -1,6 +1,6 @@
import { UserNotificationType } from '@peertube/peertube-models'
import { t } from '@server/helpers/i18n.js'
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { WEBSERVER } from '@server/initializers/constants.js'
import { UserNotificationModel } from '@server/models/user/user-notification.js'
import { UserModel } from '@server/models/user/user.js'
@@ -13,6 +13,8 @@ import {
} from '@server/types/models/index.js'
import { AbstractNotification } from '../common/abstract-notification.js'
+const logger = createLogger()
+
export abstract class AbstractOwnedVideoPublication extends AbstractNotification<MVideoWithRights & MVideoWithSchedule> {
protected user: MUserDefault
diff --git a/server/core/lib/notifier/shared/video-publication/import-finished-for-owner.ts b/server/core/lib/notifier/shared/video-publication/import-finished-for-owner.ts
index 2c854ec116..c669ffffa5 100644
--- a/server/core/lib/notifier/shared/video-publication/import-finished-for-owner.ts
+++ b/server/core/lib/notifier/shared/video-publication/import-finished-for-owner.ts
@@ -1,6 +1,6 @@
import { MailTo, UserNotificationType } from '@peertube/peertube-models'
import { t } from '@server/helpers/i18n.js'
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { WEBSERVER } from '@server/initializers/constants.js'
import { myVideoImportsUrl } from '@server/lib/client-urls.js'
import { UserNotificationModel } from '@server/models/user/user-notification.js'
@@ -8,6 +8,8 @@ import { UserModel } from '@server/models/user/user.js'
import { MUserDefault, MUserWithNotificationSetting, MVideoImportVideo, UserNotificationModelForApi } from '@server/types/models/index.js'
import { AbstractNotification } from '../common/abstract-notification.js'
+const logger = createLogger()
+
export type ImportFinishedForOwnerPayload = {
videoImport: MVideoImportVideo
success: boolean
diff --git a/server/core/lib/notifier/shared/video-publication/new-video-or-live-for-subscribers.ts b/server/core/lib/notifier/shared/video-publication/new-video-or-live-for-subscribers.ts
index 823bb7719e..bf40f360fa 100644
--- a/server/core/lib/notifier/shared/video-publication/new-video-or-live-for-subscribers.ts
+++ b/server/core/lib/notifier/shared/video-publication/new-video-or-live-for-subscribers.ts
@@ -1,5 +1,5 @@
import { UserNotificationType, VideoPrivacy, VideoState } from '@peertube/peertube-models'
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { WEBSERVER } from '@server/initializers/constants.js'
import { UserNotificationModel } from '@server/models/user/user-notification.js'
import { UserModel } from '@server/models/user/user.js'
@@ -7,6 +7,8 @@ import { MUserWithNotificationSetting, MVideoAccountLight, UserNotificationModel
import { AbstractNotification } from '../common/abstract-notification.js'
import { t } from '@server/helpers/i18n.js'
+const logger = createLogger()
+
export class NewVideoOrLiveForSubscribers extends AbstractNotification<MVideoAccountLight> {
private users: MUserWithNotificationSetting[]
diff --git a/server/core/lib/notifier/shared/video-publication/studio-edition-finished-for-owner.ts b/server/core/lib/notifier/shared/video-publication/studio-edition-finished-for-owner.ts
index a2cf651bca..190bf12974 100644
--- a/server/core/lib/notifier/shared/video-publication/studio-edition-finished-for-owner.ts
+++ b/server/core/lib/notifier/shared/video-publication/studio-edition-finished-for-owner.ts
@@ -1,12 +1,14 @@
import { UserNotificationType } from '@peertube/peertube-models'
import { t } from '@server/helpers/i18n.js'
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { WEBSERVER } from '@server/initializers/constants.js'
import { UserNotificationModel } from '@server/models/user/user-notification.js'
import { UserModel } from '@server/models/user/user.js'
import { MUserDefault, MUserWithNotificationSetting, MVideoFull, UserNotificationModelForApi } from '@server/types/models/index.js'
import { AbstractNotification } from '../common/abstract-notification.js'
+const logger = createLogger()
+
export class StudioEditionFinishedForOwner extends AbstractNotification<MVideoFull> {
private user: MUserDefault
diff --git a/server/core/lib/object-storage/object-storage-helpers.ts b/server/core/lib/object-storage/object-storage-helpers.ts
index 0a0ef1f5f3..16d0ce5b7d 100644
--- a/server/core/lib/object-storage/object-storage-helpers.ts
+++ b/server/core/lib/object-storage/object-storage-helpers.ts
@@ -1,6 +1,5 @@
import { pipelinePromise } from '@server/helpers/core-utils.js'
import { isArray } from '@server/helpers/custom-validators/misc.js'
-import { logger } from '@server/helpers/logger.js'
import { CONFIG } from '@server/initializers/config.js'
import Bluebird from 'bluebird'
import { createReadStream, createWriteStream } from 'fs'
@@ -8,7 +7,7 @@ import { ensureDir } from 'fs-extra/esm'
import { dirname } from 'path'
import { Readable } from 'stream'
import { getClient } from './shared/client.js'
-import { lTags } from './shared/logger.js'
+import { objectStorageLogger as logger } from './shared/logger.js'
import type { _Object, ObjectCannedACL, PutObjectCommandInput, S3Client } from '@aws-sdk/client-s3'
@@ -57,7 +56,7 @@ async function storeObject (options: {
}): Promise<void> {
const { inputPath, objectStorageKey, bucketInfo, isPrivate, contentType } = options
- logger.debug('Uploading file %s to %s%s in bucket %s', inputPath, bucketInfo.PREFIX, objectStorageKey, bucketInfo.BUCKET_NAME, lTags())
+ logger.debug('Uploading file %s to %s%s in bucket %s', inputPath, bucketInfo.PREFIX, objectStorageKey, bucketInfo.BUCKET_NAME)
const fileStream = createReadStream(inputPath)
@@ -73,7 +72,7 @@ async function storeContent (options: {
}): Promise<void> {
const { content, objectStorageKey, bucketInfo, isPrivate, contentType } = options
- logger.debug('Uploading %s content to %s%s in bucket %s', content, bucketInfo.PREFIX, objectStorageKey, bucketInfo.BUCKET_NAME, lTags())
+ logger.debug('Uploading %s content to %s%s in bucket %s', content, bucketInfo.PREFIX, objectStorageKey, bucketInfo.BUCKET_NAME)
return uploadToStorage({ objectStorageKey, content, bucketInfo, isPrivate, contentType })
}
@@ -87,7 +86,7 @@ async function storeStream (options: {
}): Promise<void> {
const { stream, objectStorageKey, bucketInfo, isPrivate, contentType } = options
- logger.debug('Streaming file to %s%s in bucket %s', bucketInfo.PREFIX, objectStorageKey, bucketInfo.BUCKET_NAME, lTags())
+ logger.debug('Streaming file to %s%s in bucket %s', bucketInfo.PREFIX, objectStorageKey, bucketInfo.BUCKET_NAME)
return uploadToStorage({ objectStorageKey, content: stream, bucketInfo, isPrivate, contentType })
}
@@ -106,7 +105,7 @@ async function updateObjectACL (options: {
const key = buildKey(objectStorageKey, bucketInfo)
- logger.debug('Updating ACL file %s in bucket %s', key, bucketInfo.BUCKET_NAME, lTags())
+ logger.debug('Updating ACL file %s in bucket %s', key, bucketInfo.BUCKET_NAME)
const { PutObjectAclCommand } = await import('@aws-sdk/client-s3')
@@ -135,13 +134,13 @@ async function updatePrefixACL (options: {
const { PutObjectAclCommand } = await import('@aws-sdk/client-s3')
- logger.debug('Updating ACL of files in prefix %s in bucket %s', prefix, bucketInfo.BUCKET_NAME, lTags())
+ logger.debug('Updating ACL of files in prefix %s in bucket %s', prefix, bucketInfo.BUCKET_NAME)
return applyOnPrefix({
prefix,
bucketInfo,
commandBuilder: obj => {
- logger.debug('Updating ACL of %s inside prefix %s in bucket %s', obj.Key, prefix, bucketInfo.BUCKET_NAME, lTags())
+ logger.debug('Updating ACL of %s inside prefix %s in bucket %s', obj.Key, prefix, bucketInfo.BUCKET_NAME)
return new PutObjectAclCommand({
Bucket: bucketInfo.BUCKET_NAME,
@@ -161,7 +160,7 @@ function removeObject (objectStorageKey: string, bucketInfo: BucketInfo) {
}
async function removeObjectByFullKey (fullKey: string, bucketInfo: Pick<BucketInfo, 'BUCKET_NAME'>) {
- logger.debug('Removing file %s in bucket %s', fullKey, bucketInfo.BUCKET_NAME, lTags())
+ logger.debug('Removing file %s in bucket %s', fullKey, bucketInfo.BUCKET_NAME)
const { DeleteObjectCommand } = await import('@aws-sdk/client-s3')
@@ -179,7 +178,7 @@ async function removeObjectByFullKey (fullKey: string, bucketInfo: Pick<BucketIn
}
async function removePrefix (prefix: string, bucketInfo: BucketInfo) {
- logger.debug('Removing prefix %s in bucket %s', prefix, bucketInfo.BUCKET_NAME, lTags())
+ logger.debug('Removing prefix %s in bucket %s', prefix, bucketInfo.BUCKET_NAME)
const { DeleteObjectCommand } = await import('@aws-sdk/client-s3')
@@ -187,7 +186,7 @@ async function removePrefix (prefix: string, bucketInfo: BucketInfo) {
prefix,
bucketInfo,
commandBuilder: obj => {
- logger.debug('Removing %s inside prefix %s in bucket %s', obj.Key, prefix, bucketInfo.BUCKET_NAME, lTags())
+ logger.debug('Removing %s inside prefix %s in bucket %s', obj.Key, prefix, bucketInfo.BUCKET_NAME)
return new DeleteObjectCommand({
Bucket: bucketInfo.BUCKET_NAME,
@@ -346,7 +345,7 @@ async function uploadToStorage (options: {
// For more information, see https://docs.aws.amazon.com/AmazonS3/latest/API/API_CompleteMultipartUpload.html
if (!response.Bucket) {
const message = `Error uploading ${objectStorageKey} to bucket ${bucketInfo.BUCKET_NAME}`
- logger.error(message, { response, ...lTags() })
+ logger.error(message, { response })
throw new Error(message)
}
@@ -355,7 +354,7 @@ async function uploadToStorage (options: {
bucketInfo.PREFIX,
objectStorageKey,
bucketInfo.BUCKET_NAME,
- { ...lTags(), responseMetadata: response.$metadata }
+ { responseMetadata: response.$metadata }
)
} catch (err) {
// oxlint-disable-next-line @typescript-eslint/only-throw-error
@@ -391,7 +390,7 @@ async function applyOnPrefix (options: {
if (isArray(listedObjects.Contents) !== true) {
const message = `Cannot apply function on ${commandPrefix} prefix in bucket ${bucketInfo.BUCKET_NAME}: no files listed.`
- logger.error(message, { response: listedObjects, ...lTags() })
+ logger.error(message, { response: listedObjects })
throw new Error(message)
}
diff --git a/server/core/lib/object-storage/proxy.ts b/server/core/lib/object-storage/proxy.ts
index cf40c9ded4..ac23aedc14 100644
--- a/server/core/lib/object-storage/proxy.ts
+++ b/server/core/lib/object-storage/proxy.ts
@@ -1,6 +1,6 @@
import { HttpStatusCode } from '@peertube/peertube-models'
import { buildReinjectVideoFileTokenQuery } from '@server/controllers/shared/m3u8-playlist.js'
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { StreamReplacer } from '@server/helpers/stream-replacer.js'
import { MVideo } from '@server/types/models/index.js'
import express from 'express'
@@ -10,6 +10,8 @@ import { getHLSFileReadStream, getWebVideoFileReadStream } from './videos.js'
import type { GetObjectCommandOutput } from '@aws-sdk/client-s3'
+const logger = createLogger()
+
export async function proxifyWebVideoFile (options: {
req: express.Request
res: express.Response
diff --git a/server/core/lib/object-storage/shared/client.ts b/server/core/lib/object-storage/shared/client.ts
index 3e6093ba72..384c2814cc 100644
--- a/server/core/lib/object-storage/shared/client.ts
+++ b/server/core/lib/object-storage/shared/client.ts
@@ -1,9 +1,8 @@
import type { S3Client } from '@aws-sdk/client-s3'
-import { logger } from '@server/helpers/logger.js'
import { isProxyEnabled } from '@server/helpers/proxy.js'
import { getProxyAgent } from '@server/helpers/requests.js'
import { CONFIG } from '@server/initializers/config.js'
-import { lTags } from './logger.js'
+import { objectStorageLogger as logger } from './logger.js'
let s3ClientPromise: Promise<S3Client>
export function getClient () {
@@ -32,7 +31,7 @@ export function getClient () {
responseChecksumValidation: 'WHEN_REQUIRED'
})
- logger.info('Initialized S3 client %s with region %s.', getEndpoint(), OBJECT_STORAGE.REGION, lTags())
+ logger.info('Initialized S3 client %s with region %s.', getEndpoint(), OBJECT_STORAGE.REGION)
return s3Client
})()
diff --git a/server/core/lib/object-storage/shared/logger.ts b/server/core/lib/object-storage/shared/logger.ts
index 3f201c9475..920f60899f 100644
--- a/server/core/lib/object-storage/shared/logger.ts
+++ b/server/core/lib/object-storage/shared/logger.ts
@@ -1,3 +1,3 @@
-import { loggerTagsFactory } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
-export const lTags = loggerTagsFactory('object-storage')
+export const objectStorageLogger = createLogger('object-storage')
diff --git a/server/core/lib/object-storage/urls.ts b/server/core/lib/object-storage/urls.ts
index 499bb5f5e8..308b2b3e8e 100644
--- a/server/core/lib/object-storage/urls.ts
+++ b/server/core/lib/object-storage/urls.ts
@@ -1,8 +1,7 @@
-import { logger } from '@server/helpers/logger.js'
import { CONFIG } from '@server/initializers/config.js'
import { OBJECT_STORAGE_PROXY_PATHS, WEBSERVER } from '@server/initializers/constants.js'
import { MVideoUUID } from '@server/types/models/index.js'
-import { BucketInfo, buildKey, getEndpoint, lTags } from './shared/index.js'
+import { BucketInfo, buildKey, getEndpoint, objectStorageLogger as logger } from './shared/index.js'
// ---------------------------------------------------------------------------
@@ -55,8 +54,7 @@ function getEndpointParsed () {
logger.error(
`Invalid object storage endpoint URL: ${getEndpoint()}. ` +
`If you enabled object storage, ensure object_storage.endpoint is correctly configured. ` +
- `Otherwise, check that you have correctly moved all your videos to your local filesystem.`,
- lTags()
+ `Otherwise, check that you have correctly moved all your videos to your local filesystem.`
)
return undefined
diff --git a/server/core/lib/object-storage/videos.ts b/server/core/lib/object-storage/videos.ts
index 48f1fb18ad..3b120b3396 100644
--- a/server/core/lib/object-storage/videos.ts
+++ b/server/core/lib/object-storage/videos.ts
@@ -1,4 +1,3 @@
-import { logger } from '@server/helpers/logger.js'
import { CONFIG } from '@server/initializers/config.js'
import { MIMETYPES } from '@server/initializers/constants.js'
import { MVideo, MVideoCaption, MVideoFile, MVideoPrivacy, MVideoUUID } from '@server/types/models/index.js'
@@ -15,9 +14,9 @@ import {
} from './keys.js'
import {
createObjectReadStream,
- lTags,
listKeysOfPrefix,
makeAvailable,
+ objectStorageLogger as logger,
removeObject,
removeObjectByFullKey,
removePrefix,
@@ -168,7 +167,7 @@ export function removeCaptionObjectStorage (videoCaption: MVideoCaption) {
export async function makeHLSFileAvailable (video: MVideoUUID, filename: string, destination: string) {
const key = generateHLSObjectStorageKey(video, filename)
- logger.info('Fetching HLS file %s from object storage to %s.', key, destination, lTags())
+ logger.info('Fetching HLS file %s from object storage to %s.', key, destination)
await makeAvailable({
key,
@@ -176,7 +175,7 @@ export async function makeHLSFileAvailable (video: MVideoUUID, filename: string,
bucketInfo: CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS
})
- logger.debug('Fetched HLS file %s from object storage to %s.', key, destination, lTags())
+ logger.debug('Fetched HLS file %s from object storage to %s.', key, destination)
return destination
}
@@ -184,7 +183,7 @@ export async function makeHLSFileAvailable (video: MVideoUUID, filename: string,
export async function makeWebVideoFileAvailable (filename: string, destination: string) {
const key = generateWebVideoObjectStorageKey(filename)
- logger.info('Fetching Web Video file %s from object storage to %s.', key, destination, lTags())
+ logger.info('Fetching Web Video file %s from object storage to %s.', key, destination)
await makeAvailable({
key,
@@ -198,7 +197,7 @@ export async function makeWebVideoFileAvailable (filename: string, destination:
export async function makeOriginalFileAvailable (keptOriginalFilename: string, destination: string) {
const key = generateOriginalVideoObjectStorageKey(keptOriginalFilename)
- logger.info('Fetching Original Video file %s from object storage to %s.', key, destination, lTags())
+ logger.info('Fetching Original Video file %s from object storage to %s.', key, destination)
await makeAvailable({
key,
@@ -212,7 +211,7 @@ export async function makeOriginalFileAvailable (keptOriginalFilename: string, d
export async function makeCaptionFileAvailable (filename: string, destination: string) {
const key = generateCaptionObjectStorageKey(filename)
- logger.info('Fetching Caption file %s from object storage to %s.', key, destination, lTags())
+ logger.info('Fetching Caption file %s from object storage to %s.', key, destination)
await makeAvailable({
key,
diff --git a/server/core/lib/opentelemetry/metric-helpers/nodejs-observers-builder.ts b/server/core/lib/opentelemetry/metric-helpers/nodejs-observers-builder.ts
index f160384b3c..82136268b0 100644
--- a/server/core/lib/opentelemetry/metric-helpers/nodejs-observers-builder.ts
+++ b/server/core/lib/opentelemetry/metric-helpers/nodejs-observers-builder.ts
@@ -1,10 +1,12 @@
import { Meter, ObservableResult } from '@opentelemetry/api'
import { AggregationType, InstrumentType, ViewOptions } from '@opentelemetry/sdk-metrics'
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { readdir } from 'fs/promises'
import { constants, NodeGCPerformanceDetail, PerformanceObserver } from 'perf_hooks'
import * as process from 'process'
+const logger = createLogger()
+
// Thanks to https://github.com/siimon/prom-client
// We took their logic and adapter it for opentelemetry
// Try to keep consistency with their metric name/description so it's easier to process (grafana dashboard template etc)
diff --git a/server/core/lib/opentelemetry/metrics.ts b/server/core/lib/opentelemetry/metrics.ts
index f7a6db7bb1..d1d8822302 100644
--- a/server/core/lib/opentelemetry/metrics.ts
+++ b/server/core/lib/opentelemetry/metrics.ts
@@ -2,7 +2,7 @@ import { Meter, metrics } from '@opentelemetry/api'
import { PrometheusExporter } from '@opentelemetry/exporter-prometheus'
import { MeterProvider } from '@opentelemetry/sdk-metrics'
import { PlaybackMetricCreate } from '@peertube/peertube-models'
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { CONFIG } from '@server/initializers/config.js'
import { MVideoImmutable } from '@server/types/models/index.js'
import { Application, Request, Response } from 'express'
@@ -19,6 +19,8 @@ import {
} from './metric-helpers/index.js'
import { WorkerThreadsObserversBuilder } from './metric-helpers/worker-threads-observers.js'
+const logger = createLogger()
+
class OpenTelemetryMetrics {
private static instance: OpenTelemetryMetrics
diff --git a/server/core/lib/opentelemetry/tracing.ts b/server/core/lib/opentelemetry/tracing.ts
index 4b04f7ec09..21b200df94 100644
--- a/server/core/lib/opentelemetry/tracing.ts
+++ b/server/core/lib/opentelemetry/tracing.ts
@@ -1,7 +1,9 @@
import type { Span, Tracer } from '@opentelemetry/api'
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { CONFIG } from '@server/initializers/config.js'
+const logger = createLogger()
+
let tracer: Tracer | TrackerMock
async function registerOpentelemetryTracing () {
diff --git a/server/core/lib/peertube-socket.ts b/server/core/lib/peertube-socket.ts
index 932269bb86..2756164ea7 100644
--- a/server/core/lib/peertube-socket.ts
+++ b/server/core/lib/peertube-socket.ts
@@ -6,10 +6,12 @@ import { MVideo, MVideoImmutable } from '@server/types/models/index.js'
import { MRunner } from '@server/types/models/runners/index.js'
import { UserNotificationModelForApi } from '@server/types/models/user/index.js'
import { LiveVideoEventPayload, LiveVideoEventType } from '@peertube/peertube-models'
-import { logger } from '../helpers/logger.js'
+import { createLogger } from '../helpers/logger.js'
import { authenticateRunnerSocket, authenticateSocket } from '../middlewares/index.js'
import { isDevInstance } from '@peertube/peertube-node-utils'
+const logger = createLogger()
+
class PeerTubeSocket {
private static instance: PeerTubeSocket
diff --git a/server/core/lib/plugins/hooks.ts b/server/core/lib/plugins/hooks.ts
index 70aaf47865..6d9701097f 100644
--- a/server/core/lib/plugins/hooks.ts
+++ b/server/core/lib/plugins/hooks.ts
@@ -1,8 +1,10 @@
import Bluebird from 'bluebird'
import { ServerActionHookName, ServerFilterHookName } from '@peertube/peertube-models'
-import { logger } from '../../helpers/logger.js'
+import { createLogger } from '../../helpers/logger.js'
import { PluginManager } from './plugin-manager.js'
+const logger = createLogger()
+
type PromiseFunction <U, T> = (params: U) => Promise<T> | Bluebird<T>
type RawFunction <U, T> = (params: U) => T
diff --git a/server/core/lib/plugins/package-manager.ts b/server/core/lib/plugins/package-manager.ts
index 01afbed97c..413d7afc4f 100644
--- a/server/core/lib/plugins/package-manager.ts
+++ b/server/core/lib/plugins/package-manager.ts
@@ -4,10 +4,12 @@ import { outputJSON, pathExists, remove } from 'fs-extra/esm'
import { readFile, rename, writeFile } from 'fs/promises'
import { join } from 'path'
import { isNpmPluginNameValid } from '../../helpers/custom-validators/plugins.js'
-import { logger } from '../../helpers/logger.js'
+import { createLogger } from '../../helpers/logger.js'
import { CONFIG } from '../../initializers/config.js'
import { getLatestPluginVersion } from './plugin-index.js'
+const logger = createLogger()
+
export async function installNpmPlugin (npmName: string, versionArg?: string) {
// Security check
checkNpmPluginNameOrThrow(npmName)
diff --git a/server/core/lib/plugins/plugin-helpers-builder.ts b/server/core/lib/plugins/plugin-helpers-builder.ts
index b7dfdaab53..eb35038561 100644
--- a/server/core/lib/plugins/plugin-helpers-builder.ts
+++ b/server/core/lib/plugins/plugin-helpers-builder.ts
@@ -1,7 +1,7 @@
import { ffprobePromise } from '@peertube/peertube-ffmpeg'
import { FileStorage, VideoBlacklistCreate } from '@peertube/peertube-models'
import { toCompleteUUID } from '@server/helpers/custom-validators/misc.js'
-import { buildLogger } from '@server/helpers/logger.js'
+import { buildWinstonLogger, createLogger } from '@server/helpers/logger.js'
import { CONFIG } from '@server/initializers/config.js'
import { WEBSERVER } from '@server/initializers/constants.js'
import { sequelizeTypescript } from '@server/initializers/database.js'
@@ -28,6 +28,8 @@ import { ServerConfigManager } from '../server-config-manager.js'
import { blacklistVideo, unblacklistVideo } from '../video-blacklist.js'
import { VideoPathManager } from '../video-path-manager.js'
+const logger = createLogger('plugin')
+
function buildPluginHelpers (httpServer: Server, pluginModel: MPlugin, npmName: string): PeerTubeHelpers {
return {
logger: buildPluginLogger(npmName),
@@ -60,7 +62,7 @@ export {
// ---------------------------------------------------------------------------
function buildPluginLogger (npmName: string) {
- return buildLogger({ labelSuffix: npmName })
+ return buildWinstonLogger({ labelSuffix: npmName })
}
function buildDatabaseHelpers () {
@@ -103,8 +105,10 @@ function buildVideosHelpers (npmName: string) {
const video = await VideoModel.loadFull(options.videoId)
if (!video) return
- const updater = new LocalVideoUpdater({ video, user: null, tags: [ 'plugins', npmName ] })
- await updater.update(options.attributes)
+ await logger.withContext([ npmName, video.uuid ], async () => {
+ const updater = new LocalVideoUpdater({ video, user: null })
+ await updater.update(options.attributes)
+ })
},
ffprobe: (path: string) => {
@@ -217,7 +221,9 @@ function buildModerationHelpers () {
const video = await VideoModel.loadFull(options.videoIdOrUUID)
if (!video) return
- await blacklistVideo(video, options.createOptions)
+ await logger.withContext([ video.uuid ], async () => {
+ await blacklistVideo(video, options.createOptions)
+ })
},
unblacklistVideo: async (options: { videoIdOrUUID: number | string }) => {
diff --git a/server/core/lib/plugins/plugin-index.ts b/server/core/lib/plugins/plugin-index.ts
index 4f00bfe4d5..77cead8f21 100644
--- a/server/core/lib/plugins/plugin-index.ts
+++ b/server/core/lib/plugins/plugin-index.ts
@@ -6,7 +6,7 @@ import {
ResultList
} from '@peertube/peertube-models'
import { sanitizeUrl } from '@server/helpers/core-utils.js'
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { doJSONRequest } from '@server/helpers/requests.js'
import { CONFIG } from '@server/initializers/config.js'
import { PEERTUBE_VERSION } from '@server/initializers/constants.js'
@@ -14,6 +14,8 @@ import { PluginModel } from '@server/models/server/plugin.js'
import { PluginManager } from './plugin-manager.js'
import { isStableOrUnstableVersionValid } from '@server/helpers/custom-validators/misc.js'
+const logger = createLogger()
+
export async function listAvailablePluginsFromIndex (options: PeertubePluginIndexList) {
const { start = 0, count = 20, search, sort = 'npmName', pluginType } = options
diff --git a/server/core/lib/plugins/plugin-manager.ts b/server/core/lib/plugins/plugin-manager.ts
index 7a92eb06f4..faf95c28b8 100644
--- a/server/core/lib/plugins/plugin-manager.ts
+++ b/server/core/lib/plugins/plugin-manager.ts
@@ -20,7 +20,7 @@ import { Server } from 'http'
import { createRequire } from 'module'
import { basename, join } from 'path'
import { isLibraryCodeValid, isPackageJSONValid } from '../../helpers/custom-validators/plugins.js'
-import { logger } from '../../helpers/logger.js'
+import { createLogger } from '../../helpers/logger.js'
import { CONFIG } from '../../initializers/config.js'
import { PLUGIN_GLOBAL_CSS_PATH } from '../../initializers/constants.js'
import { PluginModel } from '../../models/server/plugin.js'
@@ -34,6 +34,8 @@ import { ClientHtml } from '../html/client-html.js'
import { installNpmPlugin, installNpmPluginFromDisk, rebuildNativePlugins, removeNpmPlugin } from './package-manager.js'
import { RegisterHelpers } from './register-helpers.js'
+const logger = createLogger()
+
const require = createRequire(import.meta.url)
export interface RegisteredPlugin {
diff --git a/server/core/lib/plugins/register-helpers.ts b/server/core/lib/plugins/register-helpers.ts
index d386ccf94d..c2c25df911 100644
--- a/server/core/lib/plugins/register-helpers.ts
+++ b/server/core/lib/plugins/register-helpers.ts
@@ -9,7 +9,7 @@ import {
VideoPlaylistPrivacyType,
VideoPrivacyType
} from '@peertube/peertube-models'
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { onExternalUserAuthenticated } from '@server/lib/auth/external-auth.js'
import { VideoConstantManagerFactory } from '@server/lib/plugins/video-constant-manager-factory.js'
import { PluginModel } from '@server/models/server/plugin.js'
@@ -26,6 +26,8 @@ import { Server } from 'http'
import { VideoTranscodingProfilesManager } from '../transcoding/default-transcoding-profiles.js'
import { buildPluginHelpers } from './plugin-helpers-builder.js'
+const logger = createLogger()
+
export class RegisterHelpers {
private readonly transcodingProfiles: {
[npmName: string]: {
diff --git a/server/core/lib/plugins/video-constant-manager-factory.ts b/server/core/lib/plugins/video-constant-manager-factory.ts
index 04c30cf695..a7fea443a2 100644
--- a/server/core/lib/plugins/video-constant-manager-factory.ts
+++ b/server/core/lib/plugins/video-constant-manager-factory.ts
@@ -1,5 +1,5 @@
import { ConstantManager } from '@peertube/peertube-models'
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import {
VIDEO_CATEGORIES,
VIDEO_LANGUAGES,
@@ -8,6 +8,8 @@ import {
VIDEO_PRIVACIES
} from '@server/initializers/constants.js'
+const logger = createLogger()
+
type AlterableVideoConstant = 'language' | 'licence' | 'category' | 'privacy' | 'playlistPrivacy'
type VideoConstant = Record<number | string, string>
diff --git a/server/core/lib/redis.ts b/server/core/lib/redis.ts
index 69df3b77c8..e7f96b16e8 100644
--- a/server/core/lib/redis.ts
+++ b/server/core/lib/redis.ts
@@ -3,7 +3,7 @@ import { exists } from '@server/helpers/custom-validators/misc.js'
import { Redis as IoRedis, RedisOptions } from 'ioredis'
import { readFileSync } from 'node:fs'
import { ConnectionOptions } from 'node:tls'
-import { logger, loggerTagsFactory } from '../helpers/logger.js'
+import { createLogger } from '../helpers/logger.js'
import { generateRandomString } from '../helpers/utils.js'
import { CONFIG } from '../initializers/config.js'
import {
@@ -18,7 +18,7 @@ import {
WEBSERVER
} from '../initializers/constants.js'
-const lTags = loggerTagsFactory('redis')
+const logger = createLogger('redis')
type StatKind = 'views' | 'downloads'
@@ -38,25 +38,25 @@ class Redis {
this.initialized = true
const redisMode = CONFIG.REDIS.SENTINEL.ENABLED ? 'sentinel' : 'standalone'
- logger.info(`Connecting to Redis in "${redisMode}" mode...`, lTags())
+ logger.info(`Connecting to Redis in "${redisMode}" mode...`)
this.client = new IoRedis(Redis.getRedisClientOptions('', { enableAutoPipelining: true }, true))
- this.client.on('error', err => logger.error('Redis failed to connect', { err, ...lTags() }))
+ this.client.on('error', err => logger.error('Redis failed to connect', { err }))
this.client.on('connect', () => {
- logger.info('Connected to redis.', lTags())
+ logger.info('Connected to redis.')
this.connected = true
})
this.client.on('reconnecting', ms => {
- logger.error(`Reconnecting to redis in ${ms}.`, lTags())
+ logger.error(`Reconnecting to redis in ${ms}.`)
})
this.client.on('close', () => {
- logger.error('Connection to redis has closed.', lTags())
+ logger.error('Connection to redis has closed.')
this.connected = false
})
this.client.on('end', () => {
- logger.error('Connection to redis has closed and no more reconnects will be done.', lTags())
+ logger.error('Connection to redis has closed and no more reconnects will be done.')
})
this.prefix = 'redis-' + WEBSERVER.HOST + '-'
@@ -70,7 +70,7 @@ class Redis {
if (logOptions) {
logger.info(
`Using sentinel redis options`,
- { sentinels: CONFIG.REDIS.SENTINEL.SENTINELS, name: CONFIG.REDIS.SENTINEL.MASTER_NAME, ...lTags() }
+ { sentinels: CONFIG.REDIS.SENTINEL.SENTINELS, name: CONFIG.REDIS.SENTINEL.MASTER_NAME }
)
}
@@ -105,7 +105,7 @@ class Redis {
if (logOptions) {
logger.info(
`Using standalone redis options`,
- { db: CONFIG.REDIS.DB, host: CONFIG.REDIS.HOSTNAME, port: CONFIG.REDIS.PORT, path: CONFIG.REDIS.SOCKET, ...lTags() }
+ { db: CONFIG.REDIS.DB, host: CONFIG.REDIS.HOSTNAME, port: CONFIG.REDIS.PORT, path: CONFIG.REDIS.SOCKET }
)
}
@@ -571,7 +571,7 @@ class Redis {
try {
return JSON.parse(value)
} catch (err) {
- logger.warn('Cannot parse Redis key %s.', key, { err, ...lTags() })
+ logger.warn('Cannot parse Redis key %s.', key, { err })
return null
}
}
diff --git a/server/core/lib/redundancy.ts b/server/core/lib/redundancy.ts
index b470373cea..101d60689a 100644
--- a/server/core/lib/redundancy.ts
+++ b/server/core/lib/redundancy.ts
@@ -1,5 +1,5 @@
import { Transaction } from 'sequelize'
-import { logger, loggerTagsFactory } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { CONFIG } from '@server/initializers/config.js'
import { ActorFollowModel } from '@server/models/actor/actor-follow.js'
import { getServerActor } from '@server/models/application/application.js'
@@ -8,7 +8,7 @@ import { Activity } from '@peertube/peertube-models'
import { VideoRedundancyModel } from '../models/redundancy/video-redundancy.js'
import { sendUndoCacheFile } from './activitypub/send/index.js'
-const lTags = loggerTagsFactory('redundancy')
+const logger = createLogger('redundancy')
async function removeVideoRedundancy (videoRedundancy: MVideoRedundancyVideo, t?: Transaction) {
const serverActor = await getServerActor()
@@ -30,7 +30,7 @@ async function removeRedundanciesOfServer (serverId: number) {
async function isRedundancyAccepted (activity: Activity, byActor: MActorSignature) {
const configAcceptFrom = CONFIG.REMOTE_REDUNDANCY.VIDEOS.ACCEPT_FROM
if (configAcceptFrom === 'nobody') {
- logger.info('Do not accept remote redundancy %s due instance accept policy.', activity.id, lTags())
+ logger.info('Do not accept remote redundancy %s due instance accept policy.', activity.id)
return false
}
@@ -41,7 +41,7 @@ async function isRedundancyAccepted (activity: Activity, byActor: MActorSignatur
if (allowed !== true) {
logger.info(
'Do not accept remote redundancy %s because actor %s is not followed by our instance.',
- activity.id, byActor.url, lTags()
+ activity.id, byActor.url
)
return false
}
diff --git a/server/core/lib/runners/job-handlers/abstract-job-handler.ts b/server/core/lib/runners/job-handlers/abstract-job-handler.ts
index 2baffd9942..47ec747fc0 100644
--- a/server/core/lib/runners/job-handlers/abstract-job-handler.ts
+++ b/server/core/lib/runners/job-handlers/abstract-job-handler.ts
@@ -22,7 +22,7 @@ import {
} from '@peertube/peertube-models'
import { saveInTransactionWithRetries } from '@server/helpers/database-utils.js'
import { deleteFileAndCatch } from '@server/helpers/fs.js'
-import { logger, loggerTagsFactory } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { RUNNER_JOBS } from '@server/initializers/constants.js'
import { sequelizeTypescript } from '@server/initializers/database.js'
import { PeerTubeSocket } from '@server/lib/peertube-socket.js'
@@ -31,6 +31,8 @@ import { setAsUpdated } from '@server/models/shared/update.js'
import { MRunnerJob } from '@server/types/models/runners/index.js'
import { Transaction } from 'sequelize'
+const logger = createLogger('runner')
+
type CreateRunnerJobArg =
| {
type: Extract<RunnerJobType, 'vod-web-video-transcoding'>
@@ -69,10 +71,6 @@ type CreateRunnerJobArg =
}
export abstract class AbstractJobHandler<C, UpdatePayload extends RunnerJobUpdatePayload, SuccessPayload extends RunnerJobSuccessPayload> {
- protected readonly lTags = loggerTagsFactory('runner')
-
- // ---------------------------------------------------------------------------
-
abstract create (options: C): Promise<MRunnerJob>
protected async createRunnerJob (
@@ -84,29 +82,31 @@ export abstract class AbstractJobHandler<C, UpdatePayload extends RunnerJobUpdat
): Promise<MRunnerJob> {
const { priority, dependsOnRunnerJob } = options
- logger.debug('Creating runner job', { options, dependsOnRunnerJob, ...this.lTags(options.type) })
+ return logger.withContext([ options.type, options.jobUUID ], async () => {
+ const runnerJob = new RunnerJobModel({
+ ...pick(options, [ 'type', 'payload', 'privatePayload' ]),
- const runnerJob = new RunnerJobModel({
- ...pick(options, [ 'type', 'payload', 'privatePayload' ]),
+ uuid: options.jobUUID,
- uuid: options.jobUUID,
+ state: dependsOnRunnerJob
+ ? RunnerJobState.WAITING_FOR_PARENT_JOB
+ : RunnerJobState.PENDING,
- state: dependsOnRunnerJob
- ? RunnerJobState.WAITING_FOR_PARENT_JOB
- : RunnerJobState.PENDING,
+ dependsOnRunnerJobId: dependsOnRunnerJob?.id,
- dependsOnRunnerJobId: dependsOnRunnerJob?.id,
+ priority
+ })
- priority
- })
+ await saveInTransactionWithRetries(runnerJob, Transaction.ISOLATION_LEVELS.READ_COMMITTED)
- await saveInTransactionWithRetries(runnerJob, Transaction.ISOLATION_LEVELS.READ_COMMITTED)
+ logger.debug('Created runner job', { options, dependsOnRunnerJob })
- if (runnerJob.state === RunnerJobState.PENDING) {
- PeerTubeSocket.Instance.sendAvailableJobsPingToRunners()
- }
+ if (runnerJob.state === RunnerJobState.PENDING) {
+ PeerTubeSocket.Instance.sendAvailableJobsPingToRunners()
+ }
- return runnerJob
+ return runnerJob
+ })
}
// ---------------------------------------------------------------------------
@@ -123,24 +123,26 @@ export abstract class AbstractJobHandler<C, UpdatePayload extends RunnerJobUpdat
}) {
const { runnerJob, progress } = options
- await this.specificUpdate(options)
+ await logger.withContext([ runnerJob.uuid, runnerJob.type ], async () => {
+ await this.specificUpdate(options)
- if (exists(progress)) runnerJob.progress = progress
+ if (exists(progress)) runnerJob.progress = progress
- if (!runnerJob.changed()) {
- // Don't update updatedAt too often
- if (runnerJob.updatedAt.getTime() > Date.now() - 2000) return
+ if (!runnerJob.changed()) {
+ // Don't update updatedAt too often
+ if (runnerJob.updatedAt.getTime() > Date.now() - 2000) return
- try {
- await setAsUpdated({ sequelize: sequelizeTypescript, table: 'runnerJob', id: runnerJob.id })
- } catch (err) {
- logger.warn('Cannot set remote job as updated', { err, ...this.lTags(runnerJob.id, runnerJob.type) })
- }
+ try {
+ await setAsUpdated({ sequelize: sequelizeTypescript, table: 'runnerJob', id: runnerJob.id })
+ } catch (err) {
+ logger.warn('Cannot set remote job as updated', { err })
+ }
- return
- }
+ return
+ }
- await saveInTransactionWithRetries(runnerJob)
+ await saveInTransactionWithRetries(runnerJob)
+ })
}
// ---------------------------------------------------------------------------
@@ -151,32 +153,34 @@ export abstract class AbstractJobHandler<C, UpdatePayload extends RunnerJobUpdat
}) {
const { runnerJob, resultPayload } = options
- runnerJob.state = RunnerJobState.COMPLETING
- await saveInTransactionWithRetries(runnerJob)
+ await logger.withContext([ runnerJob.uuid, runnerJob.type ], async () => {
+ runnerJob.state = RunnerJobState.COMPLETING
+ await saveInTransactionWithRetries(runnerJob)
- try {
- await this.specificComplete(options)
-
- runnerJob.state = RunnerJobState.COMPLETED
- } catch (err) {
- logger.error('Cannot complete runner job', { err, ...this.lTags(runnerJob.id, runnerJob.type) })
+ try {
+ await this.specificComplete(options)
- runnerJob.state = RunnerJobState.ERRORED
- runnerJob.error = err.message
- } finally {
- // specificComplete() moves whatever uploaded file it consumes into permanent storage
- // Remove anything it left behind in tmp directory
- this.cleanupResultPayloadFiles(resultPayload)
- }
+ runnerJob.state = RunnerJobState.COMPLETED
+ } catch (err) {
+ logger.error('Cannot complete runner job', { err })
+
+ runnerJob.state = RunnerJobState.ERRORED
+ runnerJob.error = err.message
+ } finally {
+ // specificComplete() moves whatever uploaded file it consumes into permanent storage
+ // Remove anything it left behind in tmp directory
+ this.cleanupResultPayloadFiles(resultPayload)
+ }
- runnerJob.progress = null
- runnerJob.finishedAt = new Date()
+ runnerJob.progress = null
+ runnerJob.finishedAt = new Date()
- await saveInTransactionWithRetries(runnerJob)
+ await saveInTransactionWithRetries(runnerJob)
- const [ affectedCount ] = await RunnerJobModel.updateDependantJobsOf(runnerJob)
+ const [ affectedCount ] = await RunnerJobModel.updateDependantJobsOf(runnerJob)
- if (affectedCount !== 0) PeerTubeSocket.Instance.sendAvailableJobsPingToRunners()
+ if (affectedCount !== 0) PeerTubeSocket.Instance.sendAvailableJobsPingToRunners()
+ })
}
private cleanupResultPayloadFiles (resultPayload: SuccessPayload) {
@@ -204,22 +208,24 @@ export abstract class AbstractJobHandler<C, UpdatePayload extends RunnerJobUpdat
}) {
const { runnerJob, fromParent } = options
- await this.specificCancel(options)
+ await logger.withContext([ runnerJob.uuid, runnerJob.type ], async () => {
+ await this.specificCancel(options)
- const cancelState = fromParent
- ? RunnerJobState.PARENT_CANCELLED
- : RunnerJobState.CANCELLED
+ const cancelState = fromParent
+ ? RunnerJobState.PARENT_CANCELLED
+ : RunnerJobState.CANCELLED
- runnerJob.setToErrorOrCancel(cancelState)
+ runnerJob.setToErrorOrCancel(cancelState)
- await saveInTransactionWithRetries(runnerJob)
+ await saveInTransactionWithRetries(runnerJob)
- const children = await RunnerJobModel.listChildrenOf(runnerJob)
- for (const child of children) {
- logger.info(`Cancelling child job ${child.uuid} of ${runnerJob.uuid} because of parent cancel`, this.lTags(child.uuid))
+ const children = await RunnerJobModel.listChildrenOf(runnerJob)
+ for (const child of children) {
+ logger.info(`Cancelling child job ${child.uuid} of ${runnerJob.uuid} because of parent cancel`)
- await this.cancel({ runnerJob: child, fromParent: true })
- }
+ await this.cancel({ runnerJob: child, fromParent: true })
+ }
+ })
}
protected abstract specificCancel (options: {
@@ -236,17 +242,19 @@ export abstract class AbstractJobHandler<C, UpdatePayload extends RunnerJobUpdat
}) {
const { runnerJob, abortNotSupportedErrorMessage = 'Job has been aborted but it is not supported by this job type' } = options
- if (this.isAbortSupported() !== true) {
- return this.error({ runnerJob, message: abortNotSupportedErrorMessage })
- }
+ await logger.withContext([ runnerJob.uuid, runnerJob.type ], async () => {
+ if (this.isAbortSupported() !== true) {
+ return this.error({ runnerJob, message: abortNotSupportedErrorMessage })
+ }
- await this.specificAbort(options)
+ await this.specificAbort(options)
- runnerJob.resetToPending()
+ runnerJob.resetToPending()
- await saveInTransactionWithRetries(runnerJob)
+ await saveInTransactionWithRetries(runnerJob)
- PeerTubeSocket.Instance.sendAvailableJobsPingToRunners()
+ PeerTubeSocket.Instance.sendAvailableJobsPingToRunners()
+ })
}
protected setAbortState (runnerJob: MRunnerJob) {
@@ -266,36 +274,38 @@ export abstract class AbstractJobHandler<C, UpdatePayload extends RunnerJobUpdat
}) {
const { runnerJob, message, fromParent } = options
- const errorState = fromParent
- ? RunnerJobState.PARENT_ERRORED
- : RunnerJobState.ERRORED
+ await logger.withContext([ runnerJob.uuid, runnerJob.type ], async () => {
+ const errorState = fromParent
+ ? RunnerJobState.PARENT_ERRORED
+ : RunnerJobState.ERRORED
- const nextState = errorState === RunnerJobState.ERRORED && this.isAbortSupported() && runnerJob.failures < RUNNER_JOBS.MAX_FAILURES
- ? RunnerJobState.PENDING
- : errorState
+ const nextState = errorState === RunnerJobState.ERRORED && this.isAbortSupported() && runnerJob.failures < RUNNER_JOBS.MAX_FAILURES
+ ? RunnerJobState.PENDING
+ : errorState
- await this.specificError({ ...options, nextState })
+ await this.specificError({ ...options, nextState })
- if (nextState === errorState) {
- runnerJob.setToErrorOrCancel(nextState)
- runnerJob.error = message
- } else {
- runnerJob.resetToPending()
- }
+ if (nextState === errorState) {
+ runnerJob.setToErrorOrCancel(nextState)
+ runnerJob.error = message
+ } else {
+ runnerJob.resetToPending()
+ }
- await saveInTransactionWithRetries(runnerJob)
+ await saveInTransactionWithRetries(runnerJob)
- if (runnerJob.state === errorState) {
- const children = await RunnerJobModel.listChildrenOf(runnerJob)
+ if (runnerJob.state === errorState) {
+ const children = await RunnerJobModel.listChildrenOf(runnerJob)
- for (const child of children) {
- logger.info(`Erroring child job ${child.uuid} of ${runnerJob.uuid} because of parent error`, this.lTags(child.uuid))
+ for (const child of children) {
+ logger.info(`Erroring child job ${child.uuid} of ${runnerJob.uuid} because of parent error`)
- await this.error({ runnerJob: child, message: 'Parent error', fromParent: true })
+ await this.error({ runnerJob: child, message: 'Parent error', fromParent: true })
+ }
+ } else {
+ PeerTubeSocket.Instance.sendAvailableJobsPingToRunners()
}
- } else {
- PeerTubeSocket.Instance.sendAvailableJobsPingToRunners()
- }
+ })
}
protected abstract specificError (options: {
diff --git a/server/core/lib/runners/job-handlers/abstract-vod-transcoding-job-handler.ts b/server/core/lib/runners/job-handlers/abstract-vod-transcoding-job-handler.ts
index e350e5c919..49e8fa9295 100644
--- a/server/core/lib/runners/job-handlers/abstract-vod-transcoding-job-handler.ts
+++ b/server/core/lib/runners/job-handlers/abstract-vod-transcoding-job-handler.ts
@@ -1,12 +1,14 @@
import { RunnerJobState, RunnerJobStateType, RunnerJobSuccessPayload, RunnerJobUpdatePayload } from '@peertube/peertube-models'
import { retryTransactionWrapper } from '@server/helpers/database-utils.js'
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { moveToFailedTranscodingState, moveToNextState } from '@server/lib/video-state.js'
import { VideoJobInfoModel } from '@server/models/video/video-job-info.js'
import { MRunnerJob } from '@server/types/models/runners/index.js'
import { AbstractJobHandler } from './abstract-job-handler.js'
import { loadRunnerVideo } from './shared/utils.js'
+const logger = createLogger('vod', 'transcoding')
+
// oxlint-disable-next-line max-len
export abstract class AbstractVODTranscodingJobHandler<C, U extends RunnerJobUpdatePayload, S extends RunnerJobSuccessPayload>
extends AbstractJobHandler<C, U, S>
@@ -33,12 +35,14 @@ export abstract class AbstractVODTranscodingJobHandler<C, U extends RunnerJobUpd
}) {
if (options.nextState !== RunnerJobState.ERRORED) return
- const video = await loadRunnerVideo(options.runnerJob, this.lTags)
+ const video = await loadRunnerVideo(options.runnerJob)
if (!video) return
- await moveToFailedTranscodingState(video)
+ await logger.withContext([ video.uuid ], async () => {
+ await moveToFailedTranscodingState(video)
- await VideoJobInfoModel.decrease(video.uuid, 'pendingTranscode')
+ await VideoJobInfoModel.decrease(video.uuid, 'pendingTranscode')
+ })
}
protected async specificCancel (options: {
@@ -46,20 +50,19 @@ export abstract class AbstractVODTranscodingJobHandler<C, U extends RunnerJobUpd
}) {
const { runnerJob } = options
- const video = await loadRunnerVideo(runnerJob, this.lTags)
+ const video = await loadRunnerVideo(runnerJob)
if (!video) return
- const pending = await VideoJobInfoModel.decrease(video.uuid, 'pendingTranscode')
+ await logger.withContext([ video.uuid ], async () => {
+ const pending = await VideoJobInfoModel.decrease(video.uuid, 'pendingTranscode')
- logger.debug(`Pending transcode decreased to ${pending} after cancel`, this.lTags(video.uuid))
+ logger.debug(`Pending transcode decreased to ${pending} after cancel`)
- if (pending === 0) {
- logger.info(
- `All transcoding jobs of ${video.uuid} have been processed or canceled, moving it to its next state`,
- this.lTags(video.uuid)
- )
+ if (pending === 0) {
+ logger.info(`All transcoding jobs of ${video.uuid} have been processed or canceled, moving it to its next state`)
- await retryTransactionWrapper(() => moveToNextState({ video }))
- }
+ await retryTransactionWrapper(() => moveToNextState({ video }))
+ }
+ })
}
}
diff --git a/server/core/lib/runners/job-handlers/live-rtmp-hls-transcoding-job-handler.ts b/server/core/lib/runners/job-handlers/live-rtmp-hls-transcoding-job-handler.ts
index b9612577a8..11e60f6203 100644
--- a/server/core/lib/runners/job-handlers/live-rtmp-hls-transcoding-job-handler.ts
+++ b/server/core/lib/runners/job-handlers/live-rtmp-hls-transcoding-job-handler.ts
@@ -8,7 +8,7 @@ import {
} from '@peertube/peertube-models'
import { buildUUID } from '@peertube/peertube-node-utils'
import { tryAtomicMove } from '@server/helpers/fs.js'
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { JOB_PRIORITY } from '@server/initializers/constants.js'
import { LiveManager } from '@server/lib/live/index.js'
import { MStreamingPlaylist, MVideo } from '@server/types/models/index.js'
@@ -17,6 +17,8 @@ import { remove } from 'fs-extra/esm'
import { join } from 'path'
import { AbstractJobHandler } from './abstract-job-handler.js'
+const logger = createLogger('live', 'transcoding')
+
type CreateOptions = {
video: MVideo
playlist: MStreamingPlaylist
@@ -39,37 +41,39 @@ type CreateOptions = {
export class LiveRTMPHLSTranscodingJobHandler
extends AbstractJobHandler<CreateOptions, LiveRTMPHLSTranscodingUpdatePayload, LiveRTMPHLSTranscodingSuccess>
{
- async create (options: CreateOptions) {
+ create (options: CreateOptions) {
const { video, rtmpUrl, toTranscode, playlist, segmentDuration, segmentListSize, outputDirectory, sessionId } = options
-
const jobUUID = buildUUID()
- const payload: RunnerJobLiveRTMPHLSTranscodingPayload = {
- input: {
- rtmpUrl
- },
- output: {
- toTranscode,
- segmentListSize,
- segmentDuration
+
+ return logger.withContext([ jobUUID, video.uuid ], async () => {
+ const payload: RunnerJobLiveRTMPHLSTranscodingPayload = {
+ input: {
+ rtmpUrl
+ },
+ output: {
+ toTranscode,
+ segmentListSize,
+ segmentDuration
+ }
}
- }
-
- const privatePayload: RunnerJobLiveRTMPHLSTranscodingPrivatePayload = {
- videoUUID: video.uuid,
- masterPlaylistName: playlist.playlistFilename,
- sessionId,
- outputDirectory
- }
-
- const job = await this.createRunnerJob({
- type: 'live-rtmp-hls-transcoding',
- jobUUID,
- payload,
- privatePayload,
- priority: JOB_PRIORITY.REQUIRED_TRANSCODING
- })
- return job
+ const privatePayload: RunnerJobLiveRTMPHLSTranscodingPrivatePayload = {
+ videoUUID: video.uuid,
+ masterPlaylistName: playlist.playlistFilename,
+ sessionId,
+ outputDirectory
+ }
+
+ const job = await this.createRunnerJob({
+ type: 'live-rtmp-hls-transcoding',
+ jobUUID,
+ payload,
+ privatePayload,
+ priority: JOB_PRIORITY.REQUIRED_TRANSCODING
+ })
+
+ return job
+ })
}
// ---------------------------------------------------------------------------
@@ -84,33 +88,30 @@ export class LiveRTMPHLSTranscodingJobHandler
const outputDirectory = privatePayload.outputDirectory
const videoUUID = privatePayload.videoUUID
- // Always process the chunk first before moving m3u8 that references this chunk
- if (updatePayload.type === 'add-chunk') {
- await tryAtomicMove(
- updatePayload.videoChunkFile as string,
- join(outputDirectory, updatePayload.videoChunkFilename)
- )
- } else if (updatePayload.type === 'remove-chunk') {
- await remove(join(outputDirectory, updatePayload.videoChunkFilename))
- }
-
- if (updatePayload.resolutionPlaylistFile && updatePayload.resolutionPlaylistFilename) {
- await tryAtomicMove(
- updatePayload.resolutionPlaylistFile as string,
- join(outputDirectory, updatePayload.resolutionPlaylistFilename)
- )
- }
-
- if (updatePayload.masterPlaylistFile) {
- await tryAtomicMove(updatePayload.masterPlaylistFile as string, join(outputDirectory, privatePayload.masterPlaylistName))
- }
-
- logger.debug(
- 'Runner live RTMP to HLS job %s for %s updated.',
- runnerJob.uuid,
- videoUUID,
- { updatePayload, ...this.lTags(videoUUID, runnerJob.uuid) }
- )
+ await logger.withContext([ videoUUID ], async () => {
+ // Always process the chunk first before moving m3u8 that references this chunk
+ if (updatePayload.type === 'add-chunk') {
+ await tryAtomicMove(
+ updatePayload.videoChunkFile as string,
+ join(outputDirectory, updatePayload.videoChunkFilename)
+ )
+ } else if (updatePayload.type === 'remove-chunk') {
+ await remove(join(outputDirectory, updatePayload.videoChunkFilename))
+ }
+
+ if (updatePayload.resolutionPlaylistFile && updatePayload.resolutionPlaylistFilename) {
+ await tryAtomicMove(
+ updatePayload.resolutionPlaylistFile as string,
+ join(outputDirectory, updatePayload.resolutionPlaylistFilename)
+ )
+ }
+
+ if (updatePayload.masterPlaylistFile) {
+ await tryAtomicMove(updatePayload.masterPlaylistFile as string, join(outputDirectory, privatePayload.masterPlaylistName))
+ }
+
+ logger.debug('Runner live RTMP to HLS job %s for %s updated.', runnerJob.uuid, videoUUID, { updatePayload })
+ })
}
// ---------------------------------------------------------------------------
@@ -162,18 +163,20 @@ export class LiveRTMPHLSTranscodingJobHandler
const privatePayload = runnerJob.privatePayload as RunnerJobLiveRTMPHLSTranscodingPrivatePayload
const videoUUID = privatePayload.videoUUID
- const errorType = {
- ended: null,
- errored: LiveVideoError.RUNNER_JOB_ERROR,
- cancelled: LiveVideoError.RUNNER_JOB_CANCEL
- }
+ logger.withContext([ videoUUID ], () => {
+ const errorType = {
+ ended: null,
+ errored: LiveVideoError.RUNNER_JOB_ERROR,
+ cancelled: LiveVideoError.RUNNER_JOB_CANCEL
+ }
- LiveManager.Instance.stopSessionOfVideo({
- videoUUID: privatePayload.videoUUID,
- expectedSessionId: privatePayload.sessionId,
- error: errorType[type]
- }).catch(err => logger.error('Cannot stop session of video %s.', videoUUID, { err, ...this.lTags(runnerJob.uuid, videoUUID) }))
+ LiveManager.Instance.stopSessionOfVideo({
+ videoUUID: privatePayload.videoUUID,
+ expectedSessionId: privatePayload.sessionId,
+ error: errorType[type]
+ }).catch(err => logger.error('Cannot stop session of video %s.', videoUUID, { err }))
- logger.info('Runner live RTMP to HLS job %s for video %s %s.', runnerJob.uuid, videoUUID, type, this.lTags(runnerJob.uuid, videoUUID))
+ logger.info('Runner live RTMP to HLS job %s for video %s %s.', runnerJob.uuid, videoUUID, type)
+ })
}
}
diff --git a/server/core/lib/runners/job-handlers/shared/utils.ts b/server/core/lib/runners/job-handlers/shared/utils.ts
index d6ad2f6973..8966a0de99 100644
--- a/server/core/lib/runners/job-handlers/shared/utils.ts
+++ b/server/core/lib/runners/job-handlers/shared/utils.ts
@@ -3,7 +3,7 @@ import {
RunnerJobVODWebVideoTranscodingPrivatePayload,
VideoFileStreamType
} from '@peertube/peertube-models'
-import { logger, LoggerTagsFn } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { onTranscodingEnded } from '@server/lib/transcoding/ended-transcoding.js'
import { onWebVideoFileTranscoding } from '@server/lib/transcoding/web-transcoding.js'
import { VideoModel } from '@server/models/video/video.js'
@@ -11,6 +11,8 @@ import { MVideoFull } from '@server/types/models/index.js'
import { MRunnerJob } from '@server/types/models/runners/index.js'
import { Transaction } from 'sequelize'
+const logger = createLogger()
+
export async function onVODWebVideoOrAudioMergeTranscodingJob (options: {
video: MVideoFull
videoFilePath: string
@@ -28,12 +30,12 @@ export async function onVODWebVideoOrAudioMergeTranscodingJob (options: {
await onTranscodingEnded({ moveVideoToNextState: privatePayload.canMoveVideoState, video })
}
-export async function loadRunnerVideo (runnerJob: MRunnerJob, lTags: LoggerTagsFn, transaction?: Transaction) {
+export async function loadRunnerVideo (runnerJob: MRunnerJob, transaction?: Transaction) {
const videoUUID = runnerJob.privatePayload.videoUUID
const video = await VideoModel.loadFull(videoUUID, transaction)
if (!video) {
- logger.info('Video %s does not exist anymore after runner job.', videoUUID, lTags(videoUUID))
+ logger.info('Video %s does not exist anymore after runner job.', videoUUID)
return undefined
}
diff --git a/server/core/lib/runners/job-handlers/transcription-job-handler.ts b/server/core/lib/runners/job-handlers/transcription-job-handler.ts
index 79965e6cdd..dcf1015eee 100644
--- a/server/core/lib/runners/job-handlers/transcription-job-handler.ts
+++ b/server/core/lib/runners/job-handlers/transcription-job-handler.ts
@@ -7,6 +7,7 @@ import {
TranscriptionSuccess
} from '@peertube/peertube-models'
import { buildUUID } from '@peertube/peertube-node-utils'
+import { createLogger } from '@server/helpers/logger.js'
import { JOB_PRIORITY } from '@server/initializers/constants.js'
import { onTranscriptionEnded } from '@server/lib/video-captions.js'
import { VideoJobInfoModel } from '@server/models/video/video-job-info.js'
@@ -16,6 +17,8 @@ import { generateRunnerTranscodingInputFileUrl } from '../runner-urls.js'
import { AbstractJobHandler } from './abstract-job-handler.js'
import { loadRunnerVideo } from './shared/utils.js'
+const logger = createLogger('transcription')
+
type CreateOptions = {
video: MVideoUUID
}
@@ -67,15 +70,17 @@ export class TranscriptionJobHandler extends AbstractJobHandler<CreateOptions, R
videoUUID: video.uuid
}
- const job = await this.createRunnerJob({
- type: 'video-transcription',
- jobUUID,
- payload,
- privatePayload,
- priority: JOB_PRIORITY.TRANSCRIPTION
- })
+ return logger.withContext([ jobUUID, video.uuid ], async () => {
+ const job = await this.createRunnerJob({
+ type: 'video-transcription',
+ jobUUID,
+ payload,
+ privatePayload,
+ priority: JOB_PRIORITY.TRANSCRIPTION
+ })
- return job
+ return job
+ })
}
// ---------------------------------------------------------------------------
@@ -86,16 +91,17 @@ export class TranscriptionJobHandler extends AbstractJobHandler<CreateOptions, R
}) {
const { runnerJob, resultPayload } = options
- const video = await loadRunnerVideo(runnerJob, this.lTags)
+ const video = await loadRunnerVideo(runnerJob)
if (!video) return
- await VideoJobInfoModel.decrease(options.runnerJob.privatePayload.videoUUID, 'pendingTranscription')
+ await logger.withContext([ video.uuid ], async () => {
+ await VideoJobInfoModel.decrease(options.runnerJob.privatePayload.videoUUID, 'pendingTranscription')
- await onTranscriptionEnded({
- video,
- language: resultPayload.inputLanguage,
- vttPath: resultPayload.vttFile as string,
- lTags: this.lTags().tags
+ await onTranscriptionEnded({
+ video,
+ language: resultPayload.inputLanguage,
+ vttPath: resultPayload.vttFile as string
+ })
})
}
}
diff --git a/server/core/lib/runners/job-handlers/video-storyboard-job-handler.ts b/server/core/lib/runners/job-handlers/video-storyboard-job-handler.ts
index 56d26151c6..e8f596b34a 100644
--- a/server/core/lib/runners/job-handlers/video-storyboard-job-handler.ts
+++ b/server/core/lib/runners/job-handlers/video-storyboard-job-handler.ts
@@ -7,7 +7,7 @@ import {
} from '@peertube/peertube-models'
import { buildUUID } from '@peertube/peertube-node-utils'
import { generateImageFilename, getImageSize } from '@server/helpers/image-utils.js'
-import { logger, loggerTagsFactory } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { CONFIG } from '@server/initializers/config.js'
import { JOB_PRIORITY, STORYBOARD } from '@server/initializers/constants.js'
import { VideoPathManager } from '@server/lib/video-path-manager.js'
@@ -19,7 +19,7 @@ import { buildSpriteSize, buildTotalSprites, findGridSize, insertStoryboardInDat
import { generateRunnerTranscodingInputFileUrl } from '../runner-urls.js'
import { AbstractJobHandler } from './abstract-job-handler.js'
-const lTagsBase = loggerTagsFactory('storyboard', 'runners')
+const logger = createLogger('storyboard')
type CreateOptions = {
videoUUID: string
@@ -28,47 +28,49 @@ type CreateOptions = {
export class VideoStoryboardJobHandler extends AbstractJobHandler<CreateOptions, RunnerJobUpdatePayload, GenerateStoryboardSuccess> {
async create (options: CreateOptions) {
const { videoUUID } = options
- const lTags = lTagsBase(videoUUID)
const jobUUID = buildUUID()
const video = await VideoModel.loadFull(videoUUID)
- const inputFile = video.getMaxQualityFile(VideoFileStream.VIDEO)
-
- return VideoPathManager.Instance.makeAvailableVideoFile(inputFile, async videoPath => {
- const { spriteHeight, spriteWidth } = await buildSpriteSize(videoPath)
-
- const { spriteDuration, totalSprites } = buildTotalSprites(video)
- if (totalSprites === 0) {
- logger.info(`Do not generate remote storyboard job of ${videoUUID} because the video is not long enough`, lTags)
- return
- }
-
- const spritesCount = findGridSize({ toFind: totalSprites, maxEdgeCount: STORYBOARD.SPRITES_MAX_EDGE_COUNT })
-
- const payload: RunnerJobGenerateStoryboardPayload = {
- input: {
- videoFileUrl: generateRunnerTranscodingInputFileUrl({ jobUUID, videoUUID, type: 'video' })
- },
- sprites: {
- size: { height: spriteHeight, width: spriteWidth },
- count: spritesCount,
- duration: spriteDuration
- },
- output: {}
- }
-
- const privatePayload: RunnerJobGenerateStoryboardPrivatePayload = { videoUUID }
-
- const job = await this.createRunnerJob({
- type: 'generate-video-storyboard',
- jobUUID,
- payload,
- privatePayload,
- priority: JOB_PRIORITY.STORYBOARD
- })
- return job
+ return logger.withContext([ jobUUID, video.uuid ], async () => {
+ const inputFile = video.getMaxQualityFile(VideoFileStream.VIDEO)
+
+ return VideoPathManager.Instance.makeAvailableVideoFile(inputFile, async videoPath => {
+ const { spriteHeight, spriteWidth } = await buildSpriteSize(videoPath)
+
+ const { spriteDuration, totalSprites } = buildTotalSprites(video)
+ if (totalSprites === 0) {
+ logger.info(`Do not generate remote storyboard job of ${videoUUID} because the video is not long enough`)
+ return
+ }
+
+ const spritesCount = findGridSize({ toFind: totalSprites, maxEdgeCount: STORYBOARD.SPRITES_MAX_EDGE_COUNT })
+
+ const payload: RunnerJobGenerateStoryboardPayload = {
+ input: {
+ videoFileUrl: generateRunnerTranscodingInputFileUrl({ jobUUID, videoUUID, type: 'video' })
+ },
+ sprites: {
+ size: { height: spriteHeight, width: spriteWidth },
+ count: spritesCount,
+ duration: spriteDuration
+ },
+ output: {}
+ }
+
+ const privatePayload: RunnerJobGenerateStoryboardPrivatePayload = { videoUUID }
+
+ const job = await this.createRunnerJob({
+ type: 'generate-video-storyboard',
+ jobUUID,
+ payload,
+ privatePayload,
+ priority: JOB_PRIORITY.STORYBOARD
+ })
+
+ return job
+ })
})
}
@@ -86,30 +88,31 @@ export class VideoStoryboardJobHandler extends AbstractJobHandler<CreateOptions,
const video = await VideoModel.loadFull(runnerJob.privatePayload.videoUUID)
if (!video) return
- const destinationFilename = generateImageFilename()
- const destinationPath = join(CONFIG.STORAGE.STORYBOARDS_DIR, destinationFilename)
+ await logger.withContext([ video.uuid ], async () => {
+ const destinationFilename = generateImageFilename()
+ const destinationPath = join(CONFIG.STORAGE.STORYBOARDS_DIR, destinationFilename)
- await move(resultPayload.storyboardFile as string, destinationPath)
+ await move(resultPayload.storyboardFile as string, destinationPath)
- const { sprites } = runnerJob.payload as RunnerJobGenerateStoryboardPayload
+ const { sprites } = runnerJob.payload as RunnerJobGenerateStoryboardPayload
- await insertStoryboardInDatabase({
- videoUUID: video.uuid,
- lTags: this.lTags(video.uuid, runnerJob.uuid),
+ await insertStoryboardInDatabase({
+ videoUUID: video.uuid,
- filename: destinationFilename,
- destination: destinationPath,
+ filename: destinationFilename,
+ destination: destinationPath,
- imageSize: await getImageSize(destinationPath),
+ imageSize: await getImageSize(destinationPath),
- spriteHeight: sprites.size.height,
- spriteWidth: sprites.size.width,
- spriteDuration: sprites.duration,
+ spriteHeight: sprites.size.height,
+ spriteWidth: sprites.size.width,
+ spriteDuration: sprites.duration,
- federate: true
- })
+ federate: true
+ })
- logger.info('Runner storyboard job %s for %s ended.', runnerJob.uuid, video.uuid, this.lTags(video.uuid, runnerJob.uuid))
+ logger.info('Runner storyboard job %s for %s ended.', runnerJob.uuid, video.uuid)
+ })
}
protected specificError (_options: { runnerJob: MRunnerJob }) {}
diff --git a/server/core/lib/runners/job-handlers/video-studio-transcoding-job-handler.ts b/server/core/lib/runners/job-handlers/video-studio-transcoding-job-handler.ts
index 16666c46e4..a4144a4e85 100644
--- a/server/core/lib/runners/job-handlers/video-studio-transcoding-job-handler.ts
+++ b/server/core/lib/runners/job-handlers/video-studio-transcoding-job-handler.ts
@@ -12,7 +12,7 @@ import {
isVideoStudioTaskWatermark
} from '@peertube/peertube-models'
import { buildUUID } from '@peertube/peertube-node-utils'
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { sequelizeTypescript } from '@server/initializers/database.js'
import { onVideoStudioEnded, safeCleanupStudioTMPFiles } from '@server/lib/video-studio.js'
import { MVideoWithFile } from '@server/types/models/index.js'
@@ -22,6 +22,8 @@ import { generateRunnerEditionTranscodingVideoInputFileUrl, generateRunnerTransc
import { AbstractJobHandler } from './abstract-job-handler.js'
import { loadRunnerVideo } from './shared/utils.js'
+const logger = createLogger('studio', 'transcoding')
+
type CreateOptions = {
video: MVideoWithFile
tasks: VideoStudioTaskPayload[]
@@ -38,58 +40,60 @@ export class VideoStudioTranscodingJobHandler
const jobUUID = buildUUID()
const { separatedAudioFile } = video.getMaxQualityAudioAndVideoFiles()
- const payload: RunnerJobStudioTranscodingPayload = {
- input: {
- videoFileUrl: generateRunnerTranscodingInputFileUrl({ jobUUID, videoUUID: video.uuid, type: 'video' }),
-
- separatedAudioFileUrl: separatedAudioFile
- ? [ generateRunnerTranscodingInputFileUrl({ jobUUID, videoUUID: video.uuid, type: 'audio' }) ]
- : []
- },
- output: {},
- tasks: tasks.map(t => {
- if (isVideoStudioTaskIntro(t) || isVideoStudioTaskOutro(t)) {
- return {
- ...t,
-
- options: {
- ...t.options,
-
- file: generateRunnerEditionTranscodingVideoInputFileUrl(jobUUID, video.uuid, basename(t.options.file))
+ return logger.withContext([ jobUUID, video.uuid ], async () => {
+ const payload: RunnerJobStudioTranscodingPayload = {
+ input: {
+ videoFileUrl: generateRunnerTranscodingInputFileUrl({ jobUUID, videoUUID: video.uuid, type: 'video' }),
+
+ separatedAudioFileUrl: separatedAudioFile
+ ? [ generateRunnerTranscodingInputFileUrl({ jobUUID, videoUUID: video.uuid, type: 'audio' }) ]
+ : []
+ },
+ output: {},
+ tasks: tasks.map(t => {
+ if (isVideoStudioTaskIntro(t) || isVideoStudioTaskOutro(t)) {
+ return {
+ ...t,
+
+ options: {
+ ...t.options,
+
+ file: generateRunnerEditionTranscodingVideoInputFileUrl(jobUUID, video.uuid, basename(t.options.file))
+ }
}
}
- }
- if (isVideoStudioTaskWatermark(t)) {
- return {
- ...t,
+ if (isVideoStudioTaskWatermark(t)) {
+ return {
+ ...t,
- options: {
- ...t.options,
+ options: {
+ ...t.options,
- file: generateRunnerEditionTranscodingVideoInputFileUrl(jobUUID, video.uuid, basename(t.options.file))
+ file: generateRunnerEditionTranscodingVideoInputFileUrl(jobUUID, video.uuid, basename(t.options.file))
+ }
}
}
- }
- return t
+ return t
+ })
+ }
+
+ const privatePayload: RunnerJobVideoStudioTranscodingPrivatePayload = {
+ videoUUID: video.uuid,
+ originalTasks: tasks
+ }
+
+ const job = await this.createRunnerJob({
+ type: 'video-studio-transcoding',
+ jobUUID,
+ payload,
+ privatePayload,
+ priority
})
- }
- const privatePayload: RunnerJobVideoStudioTranscodingPrivatePayload = {
- videoUUID: video.uuid,
- originalTasks: tasks
- }
-
- const job = await this.createRunnerJob({
- type: 'video-studio-transcoding',
- jobUUID,
- payload,
- privatePayload,
- priority
+ return job
})
-
- return job
}
// ---------------------------------------------------------------------------
@@ -117,22 +121,19 @@ export class VideoStudioTranscodingJobHandler
const { runnerJob, resultPayload } = options
const privatePayload = runnerJob.privatePayload as RunnerJobVideoStudioTranscodingPrivatePayload
- const video = await loadRunnerVideo(runnerJob, this.lTags)
+ const video = await loadRunnerVideo(runnerJob)
if (!video) {
await safeCleanupStudioTMPFiles(privatePayload.originalTasks)
return
}
- const videoFilePath = resultPayload.videoFile as string
+ await logger.withContext([ video.uuid ], async () => {
+ const videoFilePath = resultPayload.videoFile as string
- await onVideoStudioEnded({ video, editionResultPath: videoFilePath, tasks: privatePayload.originalTasks })
+ await onVideoStudioEnded({ video, editionResultPath: videoFilePath, tasks: privatePayload.originalTasks })
- logger.info(
- 'Runner video edition transcoding job %s for %s ended.',
- runnerJob.uuid,
- video.uuid,
- this.lTags(video.uuid, runnerJob.uuid)
- )
+ logger.info('Runner video edition transcoding job %s for %s ended.', runnerJob.uuid, video.uuid)
+ })
}
protected specificError (options: {
@@ -158,13 +159,16 @@ export class VideoStudioTranscodingJobHandler
const { runnerJob } = options
const payload = runnerJob.privatePayload as RunnerJobVideoStudioTranscodingPrivatePayload
- await safeCleanupStudioTMPFiles(payload.originalTasks)
- await sequelizeTypescript.transaction(async transaction => {
- const video = await loadRunnerVideo(options.runnerJob, this.lTags, transaction)
+ const video = await sequelizeTypescript.transaction(async transaction => {
+ const video = await loadRunnerVideo(options.runnerJob, transaction)
if (!video || video.state === VideoState.PUBLISHED) return
await video.setNewStateAndPublishedAt({ newState: VideoState.PUBLISHED, transaction })
+
+ return video
})
+
+ await logger.withContext([ video.uuid ], () => safeCleanupStudioTMPFiles(payload.originalTasks))
}
}
diff --git a/server/core/lib/runners/job-handlers/vod-audio-merge-transcoding-job-handler.ts b/server/core/lib/runners/job-handlers/vod-audio-merge-transcoding-job-handler.ts
index 658284a425..899d36fd8f 100644
--- a/server/core/lib/runners/job-handlers/vod-audio-merge-transcoding-job-handler.ts
+++ b/server/core/lib/runners/job-handlers/vod-audio-merge-transcoding-job-handler.ts
@@ -6,7 +6,7 @@ import {
VODAudioMergeTranscodingSuccess
} from '@peertube/peertube-models'
import { buildUUID } from '@peertube/peertube-node-utils'
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { VideoJobInfoModel } from '@server/models/video/video-job-info.js'
import { MVideo } from '@server/types/models/index.js'
import { MRunnerJob } from '@server/types/models/runners/index.js'
@@ -14,6 +14,8 @@ import { generateRunnerTranscodingInputFileUrl, generateRunnerTranscodingVideoTh
import { AbstractVODTranscodingJobHandler } from './abstract-vod-transcoding-job-handler.js'
import { loadRunnerVideo, onVODWebVideoOrAudioMergeTranscodingJob } from './shared/utils.js'
+const logger = createLogger('vod', 'transcoding')
+
type CreateOptions = {
video: MVideo
resolution: number
@@ -32,35 +34,38 @@ export class VODAudioMergeTranscodingJobHandler
const { video, resolution, fps, priority, dependsOnRunnerJob } = options
const jobUUID = buildUUID()
- const payload: RunnerJobVODAudioMergeTranscodingPayload = {
- input: {
- audioFileUrl: generateRunnerTranscodingInputFileUrl({ jobUUID, videoUUID: video.uuid, type: 'audio' }),
- previewFileUrl: generateRunnerTranscodingVideoThumbnailFileUrl(jobUUID, video.uuid)
- },
- output: {
- resolution,
- fps
+
+ return logger.withContext([ jobUUID, video.uuid ], async () => {
+ const payload: RunnerJobVODAudioMergeTranscodingPayload = {
+ input: {
+ audioFileUrl: generateRunnerTranscodingInputFileUrl({ jobUUID, videoUUID: video.uuid, type: 'audio' }),
+ previewFileUrl: generateRunnerTranscodingVideoThumbnailFileUrl(jobUUID, video.uuid)
+ },
+ output: {
+ resolution,
+ fps
+ }
}
- }
- const privatePayload: RunnerJobVODWebVideoTranscodingPrivatePayload = {
- ...pick(options, [ 'deleteInputFileId', 'canMoveVideoState' ]),
+ const privatePayload: RunnerJobVODWebVideoTranscodingPrivatePayload = {
+ ...pick(options, [ 'deleteInputFileId', 'canMoveVideoState' ]),
- videoUUID: video.uuid
- }
+ videoUUID: video.uuid
+ }
- const job = await this.createRunnerJob({
- type: 'vod-audio-merge-transcoding',
- jobUUID,
- payload,
- privatePayload,
- priority,
- dependsOnRunnerJob
- })
+ const job = await this.createRunnerJob({
+ type: 'vod-audio-merge-transcoding',
+ jobUUID,
+ payload,
+ privatePayload,
+ priority,
+ dependsOnRunnerJob
+ })
- await VideoJobInfoModel.increaseOrCreate(video.uuid, 'pendingTranscode')
+ await VideoJobInfoModel.increaseOrCreate(video.uuid, 'pendingTranscode')
- return job
+ return job
+ })
}
// ---------------------------------------------------------------------------
@@ -72,18 +77,15 @@ export class VODAudioMergeTranscodingJobHandler
const { runnerJob, resultPayload } = options
const privatePayload = runnerJob.privatePayload as RunnerJobVODWebVideoTranscodingPrivatePayload
- const video = await loadRunnerVideo(runnerJob, this.lTags)
+ const video = await loadRunnerVideo(runnerJob)
if (!video) return
- const videoFilePath = resultPayload.videoFile as string
+ await logger.withContext([ video.uuid ], async () => {
+ const videoFilePath = resultPayload.videoFile as string
- await onVODWebVideoOrAudioMergeTranscodingJob({ video, videoFilePath, privatePayload, wasAudioFile: true })
+ await onVODWebVideoOrAudioMergeTranscodingJob({ video, videoFilePath, privatePayload, wasAudioFile: true })
- logger.info(
- 'Runner VOD audio merge transcoding job %s for %s ended.',
- runnerJob.uuid,
- video.uuid,
- this.lTags(video.uuid, runnerJob.uuid)
- )
+ logger.info('Runner VOD audio merge transcoding job %s for %s ended.', runnerJob.uuid, video.uuid)
+ })
}
}
diff --git a/server/core/lib/runners/job-handlers/vod-hls-transcoding-job-handler.ts b/server/core/lib/runners/job-handlers/vod-hls-transcoding-job-handler.ts
index ccd0d8fa6b..75a50d208e 100644
--- a/server/core/lib/runners/job-handlers/vod-hls-transcoding-job-handler.ts
+++ b/server/core/lib/runners/job-handlers/vod-hls-transcoding-job-handler.ts
@@ -8,7 +8,7 @@ import {
VODHLSTranscodingSuccess
} from '@peertube/peertube-models'
import { buildUUID } from '@peertube/peertube-node-utils'
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { CONFIG } from '@server/initializers/config.js'
import { onTranscodingEnded } from '@server/lib/transcoding/ended-transcoding.js'
import { onHLSVideoFileTranscoding } from '@server/lib/transcoding/hls-transcoding.js'
@@ -20,6 +20,8 @@ import { generateRunnerTranscodingInputFileUrl } from '../runner-urls.js'
import { AbstractVODTranscodingJobHandler } from './abstract-vod-transcoding-job-handler.js'
import { hasMissingHLSStreams, loadRunnerVideo } from './shared/utils.js'
+const logger = createLogger('vod', 'transcoding')
+
type CreateOptions = {
video: MVideoWithFile
deleteWebVideoFiles: boolean
@@ -39,52 +41,54 @@ type CreateOptions = {
export class VODHLSTranscodingJobHandler
extends AbstractVODTranscodingJobHandler<CreateOptions, RunnerJobUpdatePayload, VODHLSTranscodingSuccess>
{
- async create (options: CreateOptions) {
+ create (options: CreateOptions) {
const { video, resolution, fps, dependsOnRunnerJob, separatedAudio, priority } = options
const jobUUID = buildUUID()
- const { separatedAudioFile } = video.getMaxQualityAudioAndVideoFiles()
+ return logger.withContext([ jobUUID, video.uuid ], async () => {
+ const { separatedAudioFile } = video.getMaxQualityAudioAndVideoFiles()
+
+ const payload: RunnerJobVODHLSTranscodingPayload = {
+ input: {
+ videoFileUrl: generateRunnerTranscodingInputFileUrl({
+ jobUUID,
+ videoUUID: video.uuid,
+ type: resolution === VideoResolution.H_NOVIDEO
+ ? 'audio'
+ : 'video'
+ }),
+
+ separatedAudioFileUrl: separatedAudioFile
+ ? [ generateRunnerTranscodingInputFileUrl({ jobUUID, videoUUID: video.uuid, type: 'audio' }) ]
+ : []
+ },
+ output: {
+ resolution,
+ fps,
+ separatedAudio
+ }
+ }
- const payload: RunnerJobVODHLSTranscodingPayload = {
- input: {
- videoFileUrl: generateRunnerTranscodingInputFileUrl({
- jobUUID,
- videoUUID: video.uuid,
- type: resolution === VideoResolution.H_NOVIDEO
- ? 'audio'
- : 'video'
- }),
+ const privatePayload: RunnerJobVODHLSTranscodingPrivatePayload = {
+ ...pick(options, [ 'deleteWebVideoFiles', 'inputStreams', 'canMoveVideoState', 'transcodingRequestAt' ]),
- separatedAudioFileUrl: separatedAudioFile
- ? [ generateRunnerTranscodingInputFileUrl({ jobUUID, videoUUID: video.uuid, type: 'audio' }) ]
- : []
- },
- output: {
- resolution,
- fps,
- separatedAudio
+ videoUUID: video.uuid
}
- }
- const privatePayload: RunnerJobVODHLSTranscodingPrivatePayload = {
- ...pick(options, [ 'deleteWebVideoFiles', 'inputStreams', 'canMoveVideoState', 'transcodingRequestAt' ]),
+ const job = await this.createRunnerJob({
+ type: 'vod-hls-transcoding',
+ jobUUID,
+ payload,
+ privatePayload,
+ priority,
+ dependsOnRunnerJob
+ })
- videoUUID: video.uuid
- }
+ await VideoJobInfoModel.increaseOrCreate(video.uuid, 'pendingTranscode')
- const job = await this.createRunnerJob({
- type: 'vod-hls-transcoding',
- jobUUID,
- payload,
- privatePayload,
- priority,
- dependsOnRunnerJob
+ return job
})
-
- await VideoJobInfoModel.increaseOrCreate(video.uuid, 'pendingTranscode')
-
- return job
}
// ---------------------------------------------------------------------------
@@ -96,43 +100,42 @@ export class VODHLSTranscodingJobHandler
const { runnerJob, resultPayload } = options
const privatePayload = runnerJob.privatePayload as RunnerJobVODHLSTranscodingPrivatePayload
- const video = await loadRunnerVideo(runnerJob, this.lTags)
+ const video = await loadRunnerVideo(runnerJob)
if (!video) return
- const videoFilePath = resultPayload.videoFile as string
- const resolutionPlaylistFilePath = resultPayload.resolutionPlaylistFile as string
+ await logger.withContext([ video.uuid ], async () => {
+ const videoFilePath = resultPayload.videoFile as string
+ const resolutionPlaylistFilePath = resultPayload.resolutionPlaylistFile as string
- await onHLSVideoFileTranscoding({
- video,
- m3u8OutputPath: resolutionPlaylistFilePath,
- videoOutputPath: videoFilePath
- })
+ await onHLSVideoFileTranscoding({
+ video,
+ m3u8OutputPath: resolutionPlaylistFilePath,
+ videoOutputPath: videoFilePath
+ })
- // Splitted audio? Wait audio generation before moving the video in its next state
- const missingStream = await hasMissingHLSStreams({
- inputStreams: privatePayload.inputStreams,
- transcodingRequestAt: privatePayload.transcodingRequestAt,
- videoId: video.uuid
- })
+ // Splitted audio? Wait audio generation before moving the video in its next state
+ const missingStream = await hasMissingHLSStreams({
+ inputStreams: privatePayload.inputStreams,
+ transcodingRequestAt: privatePayload.transcodingRequestAt,
+ videoId: video.uuid
+ })
- if (!missingStream && privatePayload.deleteWebVideoFiles === true) {
- const resolutionExceptions = CONFIG.TRANSCODING.ALWAYS_TRANSCODE_PODCAST_OPTIMIZED_AUDIO
- ? [ VideoResolution.H_NOVIDEO ]
- : []
+ if (!missingStream && privatePayload.deleteWebVideoFiles === true) {
+ const resolutionExceptions = CONFIG.TRANSCODING.ALWAYS_TRANSCODE_PODCAST_OPTIMIZED_AUDIO
+ ? [ VideoResolution.H_NOVIDEO ]
+ : []
- logger.info('Removing web video files of %s now we have a HLS version of it.', video.uuid, {
- resolutionExceptions,
- ...this.lTags(video.uuid)
- })
+ logger.info('Removing web video files of %s now we have a HLS version of it.', video.uuid, { resolutionExceptions })
- await removeAllWebVideoFiles(video, { resolutionExceptions })
- }
+ await removeAllWebVideoFiles(video, { resolutionExceptions })
+ }
- await onTranscodingEnded({
- moveVideoToNextState: privatePayload.canMoveVideoState && !missingStream,
- video
- })
+ await onTranscodingEnded({
+ moveVideoToNextState: privatePayload.canMoveVideoState && !missingStream,
+ video
+ })
- logger.info('Runner VOD HLS job %s for %s ended.', runnerJob.uuid, video.uuid, this.lTags(runnerJob.uuid, video.uuid))
+ logger.info('Runner VOD HLS job %s for %s ended.', runnerJob.uuid, video.uuid)
+ })
}
}
diff --git a/server/core/lib/runners/job-handlers/vod-web-video-transcoding-job-handler.ts b/server/core/lib/runners/job-handlers/vod-web-video-transcoding-job-handler.ts
index 30239ec307..2c25b923c3 100644
--- a/server/core/lib/runners/job-handlers/vod-web-video-transcoding-job-handler.ts
+++ b/server/core/lib/runners/job-handlers/vod-web-video-transcoding-job-handler.ts
@@ -7,7 +7,7 @@ import {
VODWebVideoTranscodingSuccess
} from '@peertube/peertube-models'
import { buildUUID } from '@peertube/peertube-node-utils'
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { VideoJobInfoModel } from '@server/models/video/video-job-info.js'
import { MVideoWithFile } from '@server/types/models/index.js'
import { MRunnerJob } from '@server/types/models/runners/index.js'
@@ -15,6 +15,8 @@ import { generateRunnerTranscodingInputFileUrl } from '../runner-urls.js'
import { AbstractVODTranscodingJobHandler } from './abstract-vod-transcoding-job-handler.js'
import { loadRunnerVideo, onVODWebVideoOrAudioMergeTranscodingJob } from './shared/utils.js'
+const logger = createLogger('vod', 'transcoding')
+
type CreateOptions = {
video: MVideoWithFile
resolution: number
@@ -29,50 +31,53 @@ type CreateOptions = {
export class VODWebVideoTranscodingJobHandler
extends AbstractVODTranscodingJobHandler<CreateOptions, RunnerJobUpdatePayload, VODWebVideoTranscodingSuccess>
{
- async create (options: CreateOptions) {
+ create (options: CreateOptions) {
const { video, resolution, fps, priority, dependsOnRunnerJob } = options
const jobUUID = buildUUID()
- const { separatedAudioFile } = video.getMaxQualityAudioAndVideoFiles()
-
- const payload: RunnerJobVODWebVideoTranscodingPayload = {
- input: {
- videoFileUrl: generateRunnerTranscodingInputFileUrl({
- jobUUID,
- videoUUID: video.uuid,
- type: resolution === VideoResolution.H_NOVIDEO
- ? 'audio'
- : 'video'
- }),
-
- separatedAudioFileUrl: separatedAudioFile
- ? [ generateRunnerTranscodingInputFileUrl({ jobUUID, videoUUID: video.uuid, type: 'audio' }) ]
- : []
- },
- output: {
- resolution,
- fps
+
+ return logger.withContext([ jobUUID, video.uuid ], async () => {
+ const { separatedAudioFile } = video.getMaxQualityAudioAndVideoFiles()
+
+ const payload: RunnerJobVODWebVideoTranscodingPayload = {
+ input: {
+ videoFileUrl: generateRunnerTranscodingInputFileUrl({
+ jobUUID,
+ videoUUID: video.uuid,
+ type: resolution === VideoResolution.H_NOVIDEO
+ ? 'audio'
+ : 'video'
+ }),
+
+ separatedAudioFileUrl: separatedAudioFile
+ ? [ generateRunnerTranscodingInputFileUrl({ jobUUID, videoUUID: video.uuid, type: 'audio' }) ]
+ : []
+ },
+ output: {
+ resolution,
+ fps
+ }
}
- }
- const privatePayload: RunnerJobVODWebVideoTranscodingPrivatePayload = {
- ...pick(options, [ 'deleteInputFileId', 'canMoveVideoState' ]),
+ const privatePayload: RunnerJobVODWebVideoTranscodingPrivatePayload = {
+ ...pick(options, [ 'deleteInputFileId', 'canMoveVideoState' ]),
- videoUUID: video.uuid
- }
+ videoUUID: video.uuid
+ }
- const job = await this.createRunnerJob({
- type: 'vod-web-video-transcoding',
- jobUUID,
- payload,
- privatePayload,
- dependsOnRunnerJob,
- priority
- })
+ const job = await this.createRunnerJob({
+ type: 'vod-web-video-transcoding',
+ jobUUID,
+ payload,
+ privatePayload,
+ dependsOnRunnerJob,
+ priority
+ })
- await VideoJobInfoModel.increaseOrCreate(video.uuid, 'pendingTranscode')
+ await VideoJobInfoModel.increaseOrCreate(video.uuid, 'pendingTranscode')
- return job
+ return job
+ })
}
// ---------------------------------------------------------------------------
@@ -84,18 +89,15 @@ export class VODWebVideoTranscodingJobHandler
const { runnerJob, resultPayload } = options
const privatePayload = runnerJob.privatePayload as RunnerJobVODWebVideoTranscodingPrivatePayload
- const video = await loadRunnerVideo(runnerJob, this.lTags)
+ const video = await loadRunnerVideo(runnerJob)
if (!video) return
- const videoFilePath = resultPayload.videoFile as string
+ await logger.withContext([ video.uuid ], async () => {
+ const videoFilePath = resultPayload.videoFile as string
- await onVODWebVideoOrAudioMergeTranscodingJob({ video, videoFilePath, privatePayload, wasAudioFile: false })
+ await onVODWebVideoOrAudioMergeTranscodingJob({ video, videoFilePath, privatePayload, wasAudioFile: false })
- logger.info(
- 'Runner VOD web video transcoding job %s for %s ended.',
- runnerJob.uuid,
- video.uuid,
- this.lTags(video.uuid, runnerJob.uuid)
- )
+ logger.info('Runner VOD web video transcoding job %s for %s ended.', runnerJob.uuid, video.uuid)
+ })
}
}
diff --git a/server/core/lib/runners/runner.ts b/server/core/lib/runners/runner.ts
index b978d806de..ed0de075b5 100644
--- a/server/core/lib/runners/runner.ts
+++ b/server/core/lib/runners/runner.ts
@@ -1,11 +1,11 @@
import { RunnerJobState, RunnerJobStateType } from '@peertube/peertube-models'
import { runInReadCommittedTransaction } from '@server/helpers/database-utils.js'
-import { logger, loggerTagsFactory } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { RUNNER_JOBS } from '@server/initializers/constants.js'
import { MRunner, MRunnerJob } from '@server/types/models/runners/index.js'
import express from 'express'
-const lTags = loggerTagsFactory('runner')
+const logger = createLogger('runner')
const updatingRunner = new Set<number>()
@@ -21,11 +21,11 @@ export function updateLastRunnerContact (req: express.Request, runner: MRunner)
runner.lastContact = now
runner.ip = req.ip
- logger.debug('Updating last runner contact for %s', runner.name, lTags(runner.name))
+ logger.debug('Updating last runner contact for %s', runner.name)
runInReadCommittedTransaction(async transaction => {
return runner.save({ transaction })
- }).catch(err => logger.error('Cannot update last runner contact for %s', runner.name, { err, ...lTags(runner.name) }))
+ }).catch(err => logger.error('Cannot update last runner contact for %s', runner.name, { err }))
.finally(() => updatingRunner.delete(runner.id))
}
diff --git a/server/core/lib/schedulers/abstract-scheduler.ts b/server/core/lib/schedulers/abstract-scheduler.ts
index 2a857357a1..bf92da46ee 100644
--- a/server/core/lib/schedulers/abstract-scheduler.ts
+++ b/server/core/lib/schedulers/abstract-scheduler.ts
@@ -1,8 +1,8 @@
import Bluebird from 'bluebird'
import { randomInt } from 'node:crypto'
-import { logger, loggerTagsFactory } from '../../helpers/logger.js'
+import { createLogger } from '../../helpers/logger.js'
-const lTags = loggerTagsFactory('schedulers')
+const logger = createLogger('schedulers')
export abstract class AbstractScheduler {
protected abstract schedulerIntervalMs: number
@@ -61,7 +61,7 @@ export abstract class AbstractScheduler {
try {
await this.internalExecute()
} catch (err) {
- logger.error('Cannot execute ' + this.constructor.name + ' scheduler.', { err, ...lTags() })
+ logger.error('Cannot execute ' + this.constructor.name + ' scheduler.', { err })
} finally {
this.isRunning = false
}
diff --git a/server/core/lib/schedulers/actor-follow-scheduler.ts b/server/core/lib/schedulers/actor-follow-scheduler.ts
index 25a6c538e8..46b96886ae 100644
--- a/server/core/lib/schedulers/actor-follow-scheduler.ts
+++ b/server/core/lib/schedulers/actor-follow-scheduler.ts
@@ -1,13 +1,13 @@
import { isProdInstance, isTestOrDevInstance } from '@peertube/peertube-node-utils'
import { sendFollow } from '@server/lib/activitypub/send/send-follow.js'
import { setAsUpdated } from '@server/models/shared/update.js'
-import { logger, loggerTagsFactory } from '../../helpers/logger.js'
+import { createLogger } from '../../helpers/logger.js'
import { ACTOR_FOLLOW_SCORE, SCHEDULER_INTERVALS_MS } from '../../initializers/constants.js'
import { ActorFollowModel } from '../../models/actor/actor-follow.js'
import { ActorFollowHealthCache } from '../actor-follow-health-cache.js'
import { AbstractScheduler } from './abstract-scheduler.js'
-const lTags = loggerTagsFactory('schedulers')
+const logger = createLogger('schedulers')
const FOLLOW_RESEND_STALE_MS = 1000 * 60 * 60 * 24 * 7 // 7 days
const FOLLOW_RESEND_BATCH_SIZE = 100
@@ -24,7 +24,7 @@ export class ActorFollowScheduler extends AbstractScheduler {
protected async internalExecute () {
// Run too often in test/dev instances
if (isProdInstance()) {
- logger.info('Processing actor follows scheduler.', lTags())
+ logger.info('Processing actor follows scheduler.')
}
await this.processPendingScores()
@@ -62,12 +62,12 @@ export class ActorFollowScheduler extends AbstractScheduler {
}
private async removeBadActorFollows () {
- if (!isTestOrDevInstance()) logger.info('Removing bad actor follows (scheduler).', lTags())
+ if (!isTestOrDevInstance()) logger.info('Removing bad actor follows (scheduler).')
try {
await ActorFollowModel.removeBadActorFollows()
} catch (err) {
- logger.error('Error in bad actor follows scheduler.', { err, ...lTags() })
+ logger.error('Error in bad actor follows scheduler.', { err })
}
}
@@ -89,10 +89,10 @@ export class ActorFollowScheduler extends AbstractScheduler {
}
if (!isTestOrDevInstance()) {
- logger.info('Queued %d stale actor follows for resend.', actorFollows.length, lTags())
+ logger.info('Queued %d stale actor follows for resend.', actorFollows.length)
}
} catch (err) {
- logger.error('Error in stale actor follow resend scheduler.', { err, ...lTags() })
+ logger.error('Error in stale actor follow resend scheduler.', { err })
}
}
diff --git a/server/core/lib/schedulers/auto-follow-index-instances.ts b/server/core/lib/schedulers/auto-follow-index-instances.ts
index c8d982b903..e7079dc81b 100644
--- a/server/core/lib/schedulers/auto-follow-index-instances.ts
+++ b/server/core/lib/schedulers/auto-follow-index-instances.ts
@@ -3,12 +3,12 @@ import { JobQueue } from '@server/lib/job-queue/index.js'
import { ActorFollowModel } from '@server/models/actor/actor-follow.js'
import { getServerActor } from '@server/models/application/application.js'
import chunk from 'lodash-es/chunk.js'
-import { logger, loggerTagsFactory } from '../../helpers/logger.js'
+import { createLogger } from '../../helpers/logger.js'
import { CONFIG } from '../../initializers/config.js'
import { SCHEDULER_INTERVALS_MS, SERVER_ACTOR_NAME } from '../../initializers/constants.js'
import { AbstractScheduler } from './abstract-scheduler.js'
-const lTags = loggerTagsFactory('schedulers')
+const logger = createLogger('schedulers')
export class AutoFollowIndexInstances extends AbstractScheduler {
private static instance: AbstractScheduler
@@ -30,7 +30,7 @@ export class AutoFollowIndexInstances extends AbstractScheduler {
const indexUrl = CONFIG.FOLLOWINGS.INSTANCE.AUTO_FOLLOW_INDEX.INDEX_URL
- logger.info(`Auto follow instances of index ${indexUrl}`, lTags())
+ logger.info(`Auto follow instances of index ${indexUrl}`)
try {
const serverActor = await getServerActor()
@@ -42,7 +42,7 @@ export class AutoFollowIndexInstances extends AbstractScheduler {
const { body } = await doJSONRequest<any>(indexUrl, { searchParams, preventSSRF: false })
if (!body.data || Array.isArray(body.data) === false) {
- logger.error(`Cannot auto follow instances of index ${indexUrl}. Please check the auto follow URL.`, { body, ...lTags() })
+ logger.error(`Cannot auto follow instances of index ${indexUrl}. Please check the auto follow URL.`, { body })
return
}
@@ -64,7 +64,7 @@ export class AutoFollowIndexInstances extends AbstractScheduler {
}
}
} catch (err) {
- logger.error(`Cannot auto follow hosts of index ${indexUrl}.`, { err, ...lTags() })
+ logger.error(`Cannot auto follow hosts of index ${indexUrl}.`, { err })
}
}
diff --git a/server/core/lib/schedulers/blocklist-subscriptions-scheduler.ts b/server/core/lib/schedulers/blocklist-subscriptions-scheduler.ts
index 2ce6d3d9b5..861af0a01c 100644
--- a/server/core/lib/schedulers/blocklist-subscriptions-scheduler.ts
+++ b/server/core/lib/schedulers/blocklist-subscriptions-scheduler.ts
@@ -1,6 +1,6 @@
import { AutoMuteAction, AutoMuteList, StreamSyncState } from '@peertube/peertube-models'
import { handleToNameAndHost } from '@server/helpers/actors.js'
-import { logger, loggerTagsFactory } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { SCHEDULER_INTERVALS_MS } from '@server/initializers/constants.js'
import { fetchAndValidateAutoMuteList } from '@server/lib/blocklist-subscriptions.js'
import {
@@ -19,7 +19,7 @@ import { MBlocklistSubscription } from '@server/types/models/index.js'
import { Notifier } from '../notifier/notifier.js'
import { AbstractScheduler } from './abstract-scheduler.js'
-const lTags = loggerTagsFactory('schedulers')
+const logger = createLogger('schedulers')
export class BlocklistSubscriptionsScheduler extends AbstractScheduler {
private static instance: AbstractScheduler
@@ -44,12 +44,11 @@ export class BlocklistSubscriptionsScheduler extends AbstractScheduler {
.catch(err =>
logger.error('Cannot update blocklist subscription state after failed synchronization.', {
err,
- url: subscription.url,
- ...lTags()
+ url: subscription.url
})
)
- logger.error('Cannot synchronize blocklist subscription.', { err, url: subscription.url, ...lTags() })
+ logger.error('Cannot synchronize blocklist subscription.', { err, url: subscription.url })
}
}
}
@@ -60,7 +59,7 @@ export class BlocklistSubscriptionsScheduler extends AbstractScheduler {
}) {
const { subscription, serverAccountId } = options
- logger.info(`Synchronizing blocklist subscription "${subscription.name}" (${subscription.url}).`, lTags())
+ logger.info(`Synchronizing blocklist subscription "${subscription.name}" (${subscription.url}).`)
await subscription.update({ state: StreamSyncState.PROCESSING })
@@ -69,7 +68,6 @@ export class BlocklistSubscriptionsScheduler extends AbstractScheduler {
const body: AutoMuteList = await fetchAndValidateAutoMuteList(subscription.url, subscription.lastActionCreatedAt)
logger.debug('Fetched blocklist subscription data.', {
- ...lTags(),
subscriptionUrl: subscription.url,
actionsCount: body.actions.length
})
diff --git a/server/core/lib/schedulers/geo-ip-update-scheduler.ts b/server/core/lib/schedulers/geo-ip-update-scheduler.ts
index f55715f901..93cc9a3b0e 100644
--- a/server/core/lib/schedulers/geo-ip-update-scheduler.ts
+++ b/server/core/lib/schedulers/geo-ip-update-scheduler.ts
@@ -1,9 +1,9 @@
import { GeoIP } from '@server/helpers/geo-ip.js'
-import { logger, loggerTagsFactory } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { SCHEDULER_INTERVALS_MS } from '../../initializers/constants.js'
import { AbstractScheduler } from './abstract-scheduler.js'
-const lTags = loggerTagsFactory('schedulers')
+const logger = createLogger('schedulers')
export class GeoIPUpdateScheduler extends AbstractScheduler {
private static instance: AbstractScheduler
@@ -15,7 +15,7 @@ export class GeoIPUpdateScheduler extends AbstractScheduler {
}
protected internalExecute () {
- logger.info('Running GeoIP update scheduler', lTags())
+ logger.info('Running GeoIP update scheduler')
return GeoIP.Instance.updateDatabases()
}
diff --git a/server/core/lib/schedulers/peertube-version-check-scheduler.ts b/server/core/lib/schedulers/peertube-version-check-scheduler.ts
index 5f2b4b8ce5..76ec729835 100644
--- a/server/core/lib/schedulers/peertube-version-check-scheduler.ts
+++ b/server/core/lib/schedulers/peertube-version-check-scheduler.ts
@@ -2,13 +2,13 @@ import { doJSONRequest } from '@server/helpers/requests.js'
import { ApplicationModel } from '@server/models/application/application.js'
import { compareSemVer } from '@peertube/peertube-core-utils'
import { JoinPeerTubeVersions } from '@peertube/peertube-models'
-import { logger, loggerTagsFactory } from '../../helpers/logger.js'
+import { createLogger } from '../../helpers/logger.js'
import { CONFIG } from '../../initializers/config.js'
import { PEERTUBE_VERSION, SCHEDULER_INTERVALS_MS } from '../../initializers/constants.js'
import { Notifier } from '../notifier/index.js'
import { AbstractScheduler } from './abstract-scheduler.js'
-const lTags = loggerTagsFactory('schedulers')
+const logger = createLogger('schedulers')
export class PeerTubeVersionCheckScheduler extends AbstractScheduler {
private static instance: AbstractScheduler
@@ -26,12 +26,12 @@ export class PeerTubeVersionCheckScheduler extends AbstractScheduler {
private async checkLatestVersion () {
if (CONFIG.PEERTUBE.CHECK_LATEST_VERSION.ENABLED === false) return
- logger.info('Checking latest PeerTube version.', lTags())
+ logger.info('Checking latest PeerTube version.')
const { body } = await doJSONRequest<JoinPeerTubeVersions>(CONFIG.PEERTUBE.CHECK_LATEST_VERSION.URL, { preventSSRF: false })
if (!body?.peertube?.latestVersion) {
- logger.warn('Cannot check latest PeerTube version: body is invalid.', { body, ...lTags() })
+ logger.warn('Cannot check latest PeerTube version: body is invalid.', { body })
return
}
diff --git a/server/core/lib/schedulers/plugins-check-scheduler.ts b/server/core/lib/schedulers/plugins-check-scheduler.ts
index 7513a0e4b8..0c72b2d0ac 100644
--- a/server/core/lib/schedulers/plugins-check-scheduler.ts
+++ b/server/core/lib/schedulers/plugins-check-scheduler.ts
@@ -1,6 +1,6 @@
import { compareSemVer } from '@peertube/peertube-core-utils'
import chunk from 'lodash-es/chunk.js'
-import { logger, loggerTagsFactory } from '../../helpers/logger.js'
+import { createLogger } from '../../helpers/logger.js'
import { CONFIG } from '../../initializers/config.js'
import { SCHEDULER_INTERVALS_MS } from '../../initializers/constants.js'
import { PluginModel } from '../../models/server/plugin.js'
@@ -8,7 +8,7 @@ import { Notifier } from '../notifier/index.js'
import { getLatestPluginsVersion } from '../plugins/plugin-index.js'
import { AbstractScheduler } from './abstract-scheduler.js'
-const lTags = loggerTagsFactory('schedulers')
+const logger = createLogger('schedulers')
export class PluginsCheckScheduler extends AbstractScheduler {
private static instance: AbstractScheduler
@@ -26,7 +26,7 @@ export class PluginsCheckScheduler extends AbstractScheduler {
private async checkLatestPluginsVersion () {
if (CONFIG.PLUGINS.INDEX.ENABLED === false) return
- logger.info('Checking latest plugins version.', lTags())
+ logger.info('Checking latest plugins version.')
const plugins = await PluginModel.listInstalled()
@@ -60,11 +60,11 @@ export class PluginsCheckScheduler extends AbstractScheduler {
Notifier.Instance.notifyOfNewPluginVersion(plugin)
}
- logger.info(`Plugin ${result.npmName} has a new latest version ${plugin.latestVersion}`, lTags())
+ logger.info(`Plugin ${result.npmName} has a new latest version ${plugin.latestVersion}`)
}
}
} catch (err) {
- logger.error('Cannot get latest plugins version.', { npmNames, err, ...lTags() })
+ logger.error('Cannot get latest plugins version.', { npmNames, err })
}
}
}
diff --git a/server/core/lib/schedulers/remove-dangling-resumable-uploads-scheduler.ts b/server/core/lib/schedulers/remove-dangling-resumable-uploads-scheduler.ts
index b7a113dcd4..e221e800a1 100644
--- a/server/core/lib/schedulers/remove-dangling-resumable-uploads-scheduler.ts
+++ b/server/core/lib/schedulers/remove-dangling-resumable-uploads-scheduler.ts
@@ -1,9 +1,9 @@
-import { logger, loggerTagsFactory } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { SCHEDULER_INTERVALS_MS } from '@server/initializers/constants.js'
import { uploadx } from '../uploadx.js'
import { AbstractScheduler } from './abstract-scheduler.js'
-const lTags = loggerTagsFactory('schedulers', 'resumable-upload', 'cleaner')
+const logger = createLogger('schedulers', 'resumable-upload', 'cleaner')
export class RemoveDanglingResumableUploadsScheduler extends AbstractScheduler {
private static instance: AbstractScheduler
@@ -18,7 +18,7 @@ export class RemoveDanglingResumableUploadsScheduler extends AbstractScheduler {
}
protected async internalExecute () {
- logger.info('Removing dangling resumable uploads', lTags())
+ logger.info('Removing dangling resumable uploads')
const now = new Date().getTime()
@@ -26,7 +26,7 @@ export class RemoveDanglingResumableUploadsScheduler extends AbstractScheduler {
// Remove files that were not updated since the last execution
await uploadx.storage.purge(now - this.lastExecutionTimeMs)
} catch (error) {
- logger.error('Failed to handle file during resumable video upload folder cleanup', { error, ...lTags() })
+ logger.error('Failed to handle file during resumable video upload folder cleanup', { error })
} finally {
this.lastExecutionTimeMs = now
}
diff --git a/server/core/lib/schedulers/remove-expired-user-exports-scheduler.ts b/server/core/lib/schedulers/remove-expired-user-exports-scheduler.ts
index 3501566687..76de7e3fce 100644
--- a/server/core/lib/schedulers/remove-expired-user-exports-scheduler.ts
+++ b/server/core/lib/schedulers/remove-expired-user-exports-scheduler.ts
@@ -1,10 +1,10 @@
import { UserExportModel } from '@server/models/user/user-export.js'
-import { logger, loggerTagsFactory } from '../../helpers/logger.js'
+import { createLogger } from '../../helpers/logger.js'
import { CONFIG } from '../../initializers/config.js'
import { SCHEDULER_INTERVALS_MS } from '../../initializers/constants.js'
import { AbstractScheduler } from './abstract-scheduler.js'
-const lTags = loggerTagsFactory('schedulers')
+const logger = createLogger('schedulers')
export class RemoveExpiredUserExportsScheduler extends AbstractScheduler {
private static instance: AbstractScheduler
@@ -16,12 +16,12 @@ export class RemoveExpiredUserExportsScheduler extends AbstractScheduler {
}
protected async internalExecute () {
- logger.info('Running expired user exports checker.', lTags())
+ logger.info('Running expired user exports checker.')
const expired = await UserExportModel.listExpired(CONFIG.EXPORT.USERS.EXPORT_EXPIRATION)
for (const userExport of expired) {
- logger.info(`Removing expired user exports ${userExport.filename}`, lTags())
+ logger.info(`Removing expired user exports ${userExport.filename}`)
await userExport.destroy()
}
diff --git a/server/core/lib/schedulers/remove-old-history-scheduler.ts b/server/core/lib/schedulers/remove-old-history-scheduler.ts
index 7f547503e8..944282cd03 100644
--- a/server/core/lib/schedulers/remove-old-history-scheduler.ts
+++ b/server/core/lib/schedulers/remove-old-history-scheduler.ts
@@ -1,10 +1,10 @@
-import { logger, loggerTagsFactory } from '../../helpers/logger.js'
+import { createLogger } from '../../helpers/logger.js'
import { CONFIG } from '../../initializers/config.js'
import { SCHEDULER_INTERVALS_MS } from '../../initializers/constants.js'
import { UserVideoHistoryModel } from '../../models/user/user-video-history.js'
import { AbstractScheduler } from './abstract-scheduler.js'
-const lTags = loggerTagsFactory('schedulers')
+const logger = createLogger('schedulers')
export class RemoveOldHistoryScheduler extends AbstractScheduler {
private static instance: AbstractScheduler
@@ -18,7 +18,7 @@ export class RemoveOldHistoryScheduler extends AbstractScheduler {
protected internalExecute () {
if (CONFIG.HISTORY.VIDEOS.MAX_AGE === -1) return
- logger.info('Removing old videos history.', lTags())
+ logger.info('Removing old videos history.')
const now = new Date()
const beforeDate = new Date(now.getTime() - CONFIG.HISTORY.VIDEOS.MAX_AGE).toISOString()
diff --git a/server/core/lib/schedulers/remove-old-stats-scheduler.ts b/server/core/lib/schedulers/remove-old-stats-scheduler.ts
index bef17211e6..2e7e266bc2 100644
--- a/server/core/lib/schedulers/remove-old-stats-scheduler.ts
+++ b/server/core/lib/schedulers/remove-old-stats-scheduler.ts
@@ -1,11 +1,11 @@
import { LocalVideoViewerModel } from '@server/models/stat/local-video-viewer.js'
import { VideoStatModel } from '@server/models/stat/video-stat.js'
-import { logger, loggerTagsFactory } from '../../helpers/logger.js'
+import { createLogger } from '../../helpers/logger.js'
import { CONFIG } from '../../initializers/config.js'
import { SCHEDULER_INTERVALS_MS } from '../../initializers/constants.js'
import { AbstractScheduler } from './abstract-scheduler.js'
-const lTags = loggerTagsFactory('schedulers')
+const logger = createLogger('schedulers')
export class RemoveOldStatsScheduler extends AbstractScheduler {
private static instance: AbstractScheduler
@@ -24,7 +24,7 @@ export class RemoveOldStatsScheduler extends AbstractScheduler {
private removeRemoteViews () {
if (CONFIG.VIEWS.VIDEOS.REMOTE.MAX_AGE <= 0) return
- logger.info('Removing old stats from remote videos.', lTags())
+ logger.info('Removing old stats from remote videos.')
const now = new Date()
const beforeDate = new Date(now.getTime() - CONFIG.VIEWS.VIDEOS.REMOTE.MAX_AGE).toISOString()
@@ -35,7 +35,7 @@ export class RemoveOldStatsScheduler extends AbstractScheduler {
private async removeLocalViews () {
if (CONFIG.VIEWS.VIDEOS.LOCAL.MAX_AGE <= 0) return
- logger.info('Removing old stats from local videos.', lTags())
+ logger.info('Removing old stats from local videos.')
const now = new Date()
const beforeDate = new Date(now.getTime() - CONFIG.VIEWS.VIDEOS.LOCAL.MAX_AGE).toISOString()
diff --git a/server/core/lib/schedulers/remove-old-user-login-devices-scheduler.ts b/server/core/lib/schedulers/remove-old-user-login-devices-scheduler.ts
index 9b5e7efb74..d03475c05c 100644
--- a/server/core/lib/schedulers/remove-old-user-login-devices-scheduler.ts
+++ b/server/core/lib/schedulers/remove-old-user-login-devices-scheduler.ts
@@ -1,9 +1,9 @@
-import { logger, loggerTagsFactory } from '../../helpers/logger.js'
+import { createLogger } from '../../helpers/logger.js'
import { SCHEDULER_INTERVALS_MS, USER_LOGIN_DEVICE_MAX_AGE } from '../../initializers/constants.js'
import { UserLoginDeviceModel } from '../../models/user/user-login-device.js'
import { AbstractScheduler } from './abstract-scheduler.js'
-const lTags = loggerTagsFactory('schedulers')
+const logger = createLogger('schedulers')
export class RemoveOldUserLoginDevicesScheduler extends AbstractScheduler {
private static instance: AbstractScheduler
@@ -15,7 +15,7 @@ export class RemoveOldUserLoginDevicesScheduler extends AbstractScheduler {
}
protected internalExecute () {
- logger.info('Removing old user login devices.', lTags())
+ logger.info('Removing old user login devices.')
const now = new Date()
const beforeDate = new Date(now.getTime() - USER_LOGIN_DEVICE_MAX_AGE).toISOString()
diff --git a/server/core/lib/schedulers/runner-job-watch-dog-scheduler.ts b/server/core/lib/schedulers/runner-job-watch-dog-scheduler.ts
index 0c36ecdedf..3f0925c974 100644
--- a/server/core/lib/schedulers/runner-job-watch-dog-scheduler.ts
+++ b/server/core/lib/schedulers/runner-job-watch-dog-scheduler.ts
@@ -1,11 +1,11 @@
import { CONFIG } from '@server/initializers/config.js'
import { RunnerJobModel } from '@server/models/runner/runner-job.js'
-import { logger, loggerTagsFactory } from '../../helpers/logger.js'
+import { createLogger } from '../../helpers/logger.js'
import { SCHEDULER_INTERVALS_MS } from '../../initializers/constants.js'
import { getRunnerJobHandlerClass } from '../runners/index.js'
import { AbstractScheduler } from './abstract-scheduler.js'
-const lTags = loggerTagsFactory('schedulers', 'runner')
+const logger = createLogger('schedulers', 'runner')
export class RunnerJobWatchDogScheduler extends AbstractScheduler {
private static instance: AbstractScheduler
@@ -38,13 +38,15 @@ export class RunnerJobWatchDogScheduler extends AbstractScheduler {
})
for (const stalled of [ ...vodStalledJobs, ...liveStalledJobs, ...transcriptionStalledJobs, ...studioStalledJobs ]) {
- logger.info('Abort stalled runner job %s (%s)', stalled.uuid, stalled.type, lTags(stalled.uuid, stalled.type))
+ await logger.withContext([ stalled.uuid, stalled.type ], async () => {
+ logger.info('Abort stalled runner job %s (%s)', stalled.uuid, stalled.type)
- const Handler = getRunnerJobHandlerClass(stalled)
+ const Handler = getRunnerJobHandlerClass(stalled)
- await new Handler().abort({
- runnerJob: stalled,
- abortNotSupportedErrorMessage: 'Stalled runner job'
+ await new Handler().abort({
+ runnerJob: stalled,
+ abortNotSupportedErrorMessage: 'Stalled runner job'
+ })
})
}
}
diff --git a/server/core/lib/schedulers/update-token-session-scheduler.ts b/server/core/lib/schedulers/update-token-session-scheduler.ts
index e488a9a5b2..ed29726f72 100644
--- a/server/core/lib/schedulers/update-token-session-scheduler.ts
+++ b/server/core/lib/schedulers/update-token-session-scheduler.ts
@@ -1,10 +1,10 @@
-import { logger, loggerTagsFactory } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { OAuthTokenModel } from '@server/models/oauth/oauth-token.js'
import { SCHEDULER_INTERVALS_MS } from '../../initializers/constants.js'
import { AbstractScheduler } from './abstract-scheduler.js'
import { isProdInstance } from '@peertube/peertube-node-utils'
-const lTags = loggerTagsFactory('schedulers')
+const logger = createLogger('schedulers')
type UpdatePayload = {
lastActivityDate: Date
@@ -29,7 +29,7 @@ export class UpdateTokenSessionScheduler extends AbstractScheduler {
protected async internalExecute () {
// Log only on production instances to reduce noise on development/test instances
- if (isProdInstance()) logger.debug('Running update token session scheduler', lTags())
+ if (isProdInstance()) logger.debug('Running update token session scheduler')
const entriesToUpdate = this.toUpdate.entries()
this.toUpdate = new Map()
diff --git a/server/core/lib/schedulers/update-videos-scheduler.ts b/server/core/lib/schedulers/update-videos-scheduler.ts
index e1e061e509..93e3e3bc9b 100644
--- a/server/core/lib/schedulers/update-videos-scheduler.ts
+++ b/server/core/lib/schedulers/update-videos-scheduler.ts
@@ -1,14 +1,14 @@
import { VideoPrivacy, VideoPrivacyType, VideoState } from '@peertube/peertube-models'
import { VideoModel } from '@server/models/video/video.js'
import { MScheduleVideoUpdate } from '@server/types/models/index.js'
-import { logger, loggerTagsFactory } from '../../helpers/logger.js'
+import { createLogger } from '../../helpers/logger.js'
import { SCHEDULER_INTERVALS_MS } from '../../initializers/constants.js'
import { ScheduleVideoUpdateModel } from '../../models/video/schedule-video-update.js'
import { LocalVideoUpdater } from '../local-video-updater.js'
import { Notifier } from '../notifier/index.js'
import { AbstractScheduler } from './abstract-scheduler.js'
-const lTags = loggerTagsFactory('schedulers', 'update-videos')
+const logger = createLogger('schedulers', 'update-videos')
export class UpdateVideosScheduler extends AbstractScheduler {
private static instance: AbstractScheduler
@@ -24,7 +24,7 @@ export class UpdateVideosScheduler extends AbstractScheduler {
}
private async updateVideos () {
- logger.debug('Running update videos scheduler', lTags())
+ logger.debug('Running update videos scheduler')
if (!await ScheduleVideoUpdateModel.areVideosToUpdate()) return undefined
@@ -34,13 +34,15 @@ export class UpdateVideosScheduler extends AbstractScheduler {
const videoOnly = await VideoModel.load(schedule.videoId)
if (!videoOnly) continue
- try {
- const { video, published } = await this.updateAVideo(schedule)
+ await logger.withContext([ videoOnly.uuid ], async () => {
+ try {
+ const { video, published } = await this.updateAVideo(schedule)
- if (published) Notifier.Instance.notifyOnVideoPublishedAfterScheduledUpdate(video)
- } catch (err) {
- logger.error('Cannot update video ' + videoOnly.uuid, { err, ...lTags(videoOnly.uuid) })
- }
+ if (published) Notifier.Instance.notifyOnVideoPublishedAfterScheduledUpdate(video)
+ } catch (err) {
+ logger.error('Cannot update video ' + videoOnly.uuid, { err })
+ }
+ })
}
}
@@ -51,12 +53,12 @@ export class UpdateVideosScheduler extends AbstractScheduler {
let video = await VideoModel.loadFull(schedule.videoId)
if (video.state === VideoState.TO_TRANSCODE) return { video, published: false }
- logger.info('Executing scheduled video update on ' + video.uuid, lTags(video.uuid))
+ logger.info('Executing scheduled video update on ' + video.uuid)
if (schedule.privacy) {
oldPrivacy = video.privacy
- const updater = new LocalVideoUpdater({ user: null, tags: lTags().tags, video })
+ const updater = new LocalVideoUpdater({ user: null, video })
video = await updater.update({ privacy: schedule.privacy })
diff --git a/server/core/lib/schedulers/video-channel-sync-latest-scheduler.ts b/server/core/lib/schedulers/video-channel-sync-latest-scheduler.ts
index 3972215a4c..a396903396 100644
--- a/server/core/lib/schedulers/video-channel-sync-latest-scheduler.ts
+++ b/server/core/lib/schedulers/video-channel-sync-latest-scheduler.ts
@@ -1,4 +1,4 @@
-import { logger, loggerTagsFactory } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { CONFIG } from '@server/initializers/config.js'
import { VideoChannelSyncModel } from '@server/models/video/video-channel-sync.js'
import { VideoChannelModel } from '@server/models/video/video-channel.js'
@@ -7,7 +7,7 @@ import { SCHEDULER_INTERVALS_MS } from '../../initializers/constants.js'
import { synchronizeChannel } from '../sync-channel.js'
import { AbstractScheduler } from './abstract-scheduler.js'
-const lTags = loggerTagsFactory('schedulers', 'channel-synchronization')
+const logger = createLogger('schedulers', 'channel-synchronization')
export class VideoChannelSyncLatestScheduler extends AbstractScheduler {
private static instance: AbstractScheduler
@@ -19,11 +19,11 @@ export class VideoChannelSyncLatestScheduler extends AbstractScheduler {
protected async internalExecute () {
if (!CONFIG.IMPORT.VIDEO_CHANNEL_SYNCHRONIZATION.ENABLED) {
- logger.debug('Discard channels synchronization as the feature is disabled', lTags())
+ logger.debug('Discard channels synchronization as the feature is disabled')
return
}
- logger.info('Checking channels to synchronize', lTags())
+ logger.info('Checking channels to synchronize')
const channelSyncs = await VideoChannelSyncModel.listSyncs()
@@ -33,8 +33,7 @@ export class VideoChannelSyncLatestScheduler extends AbstractScheduler {
// A previous full run got interrupted: retry where we stopped to not miss videos
if (sync.fullSyncCutoffAt) {
logger.info(
- `Channel sync ${sync.id} has an unfinished full sync (cutoff ${sync.fullSyncCutoffAt.toISOString()}), continuing it`,
- lTags()
+ `Channel sync ${sync.id} has an unfinished full sync (cutoff ${sync.fullSyncCutoffAt.toISOString()}), continuing it`
)
await synchronizeChannel({
diff --git a/server/core/lib/schedulers/video-stats-buffer-scheduler.ts b/server/core/lib/schedulers/video-stats-buffer-scheduler.ts
index 0f27a8cd10..c65e8db0e1 100644
--- a/server/core/lib/schedulers/video-stats-buffer-scheduler.ts
+++ b/server/core/lib/schedulers/video-stats-buffer-scheduler.ts
@@ -1,11 +1,11 @@
-import { logger, loggerTagsFactory } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { VideoModel } from '@server/models/video/video.js'
import { SCHEDULER_INTERVALS_MS } from '../../initializers/constants.js'
import { scheduleVideoFederation } from '../activitypub/videos/index.js'
import { Redis } from '../redis.js'
import { AbstractScheduler } from './abstract-scheduler.js'
-const lTags = loggerTagsFactory('schedulers', 'stats')
+const logger = createLogger('schedulers', 'stats')
/**
* Increment video counters in the database with the pending values stored in Redis, and send video updates if needed
@@ -21,7 +21,7 @@ export class VideoStatsBufferScheduler extends AbstractScheduler {
}
protected async internalExecute () {
- logger.debug(`Running video stats buffer scheduler`, lTags())
+ logger.debug(`Running video stats buffer scheduler`)
const videoIds = await Redis.Instance.listLocalVideosWithStats()
if (videoIds.length === 0) return
@@ -37,27 +37,29 @@ export class VideoStatsBufferScheduler extends AbstractScheduler {
const video = await VideoModel.load(videoId)
if (!video) {
- logger.debug(`Video ${videoId} does not exist anymore, skipping videos stats addition.`, lTags())
+ logger.debug(`Video ${videoId} does not exist anymore, skipping videos stats addition.`)
continue
}
- logger.info(`Processing local video ${video.uuid} stats buffer.`, lTags(video.uuid))
+ await logger.withContext([ video.uuid ], async () => {
+ logger.info(`Processing local video ${video.uuid} stats buffer.`)
- // If this is a remote video, the origin instance will send us an update
- if (views) {
- video.views += views
- await VideoModel.incrementStats('views', videoId, views)
- }
+ // If this is a remote video, the origin instance will send us an update
+ if (views) {
+ video.views += views
+ await VideoModel.incrementStats('views', videoId, views)
+ }
- if (downloads) {
- video.downloads += downloads
- await VideoModel.incrementStats('downloads', videoId, downloads)
- }
+ if (downloads) {
+ video.downloads += downloads
+ await VideoModel.incrementStats('downloads', videoId, downloads)
+ }
- // Send video update
- scheduleVideoFederation({ video })
+ // Send video update
+ scheduleVideoFederation({ video })
+ })
} catch (err) {
- logger.error(`Cannot process local video stats buffer of video ${videoId}.`, { err, ...lTags() })
+ logger.error(`Cannot process local video stats buffer of video ${videoId}.`, { err })
}
}
}
diff --git a/server/core/lib/schedulers/videos-redundancy-scheduler.ts b/server/core/lib/schedulers/videos-redundancy-scheduler.ts
index 368f334170..d0d3c8aa79 100644
--- a/server/core/lib/schedulers/videos-redundancy-scheduler.ts
+++ b/server/core/lib/schedulers/videos-redundancy-scheduler.ts
@@ -10,7 +10,7 @@ import {
MVideoWithAllFiles
} from '@server/types/models/index.js'
import { join } from 'path'
-import { logger, loggerTagsFactory } from '../../helpers/logger.js'
+import { createLogger } from '../../helpers/logger.js'
import { CONFIG } from '../../initializers/config.js'
import { DIRECTORIES, REDUNDANCY, VIDEO_IMPORT_TIMEOUT } from '../../initializers/constants.js'
import { VideoRedundancyModel } from '../../models/redundancy/video-redundancy.js'
@@ -22,7 +22,7 @@ import { removeVideoRedundancy } from '../redundancy.js'
import { generateHLSRedundancyUrl } from '../video-urls.js'
import { AbstractScheduler } from './abstract-scheduler.js'
-const lTags = loggerTagsFactory('schedulers', 'redundancy')
+const logger = createLogger('schedulers', 'redundancy')
type CandidateToDuplicate = {
redundancy: VideosRedundancyStrategy
@@ -43,7 +43,7 @@ export class VideosRedundancyScheduler extends AbstractScheduler {
const videoToDuplicate = await VideoModel.loadWithFiles(videoId)
if (!videoToDuplicate) {
- logger.warn('Video to manually duplicate %d does not exist anymore.', videoId, lTags())
+ logger.warn('Video to manually duplicate %d does not exist anymore.', videoId)
return
}
@@ -56,7 +56,7 @@ export class VideosRedundancyScheduler extends AbstractScheduler {
protected async internalExecute () {
for (const redundancyConfig of CONFIG.REDUNDANCY.VIDEOS.STRATEGIES) {
- logger.info('Running redundancy scheduler for strategy %s.', redundancyConfig.strategy, lTags())
+ logger.info('Running redundancy scheduler for strategy %s.', redundancyConfig.strategy)
try {
const videoToDuplicate = await this.findVideoToDuplicate(redundancyConfig)
@@ -68,23 +68,20 @@ export class VideosRedundancyScheduler extends AbstractScheduler {
streamingPlaylists: videoToDuplicate.VideoStreamingPlaylists
}
- await this.purgeCacheIfNeeded(candidateToDuplicate)
+ await logger.withContext([ videoToDuplicate.uuid ], async () => {
+ await this.purgeCacheIfNeeded(candidateToDuplicate)
- if (await this.isTooHeavy(candidateToDuplicate)) {
- logger.info('Video %s is too big for our cache, skipping.', videoToDuplicate.url, lTags(videoToDuplicate.uuid))
- continue
- }
+ if (await this.isTooHeavy(candidateToDuplicate)) {
+ logger.info('Video %s is too big for our cache, skipping.', videoToDuplicate.url)
+ return
+ }
- logger.info(
- 'Will duplicate video %s in redundancy scheduler "%s".',
- videoToDuplicate.url,
- redundancyConfig.strategy,
- lTags(videoToDuplicate.uuid)
- )
+ logger.info('Will duplicate video %s in redundancy scheduler "%s".', videoToDuplicate.url, redundancyConfig.strategy)
- await this.createVideoRedundancies(candidateToDuplicate)
+ await this.createVideoRedundancies(candidateToDuplicate)
+ })
} catch (err) {
- logger.error('Cannot run videos redundancy %s.', redundancyConfig.strategy, { err, ...lTags() })
+ logger.error('Cannot run videos redundancy %s.', redundancyConfig.strategy, { err })
}
}
@@ -101,39 +98,43 @@ export class VideosRedundancyScheduler extends AbstractScheduler {
const expired = await VideoRedundancyModel.listLocalExpired()
for (const redundancyModel of expired) {
- try {
- const redundancyConfig = CONFIG.REDUNDANCY.VIDEOS.STRATEGIES.find(s => s.strategy === redundancyModel.strategy)
-
- // If the admin disabled the redundancy, remove this redundancy instead of extending it
- if (!redundancyConfig) {
- logger.info(
- 'Destroying redundancy %s because the redundancy %s does not exist anymore.',
- redundancyModel.url,
- redundancyModel.strategy
+ await logger.withContext([ redundancyModel.getVideoUUID() ], async () => {
+ try {
+ const redundancyConfig = CONFIG.REDUNDANCY.VIDEOS.STRATEGIES.find(s => s.strategy === redundancyModel.strategy)
+
+ // If the admin disabled the redundancy, remove this redundancy instead of extending it
+ if (!redundancyConfig) {
+ logger.info(
+ 'Destroying redundancy %s because the redundancy %s does not exist anymore.',
+ redundancyModel.url,
+ redundancyModel.strategy
+ )
+
+ await removeVideoRedundancy(redundancyModel)
+ return
+ }
+
+ const { totalUsed } = await VideoRedundancyModel.getStats(redundancyConfig.strategy)
+
+ // If the admin decreased the cache size, remove this redundancy instead of extending it
+ if (totalUsed > redundancyConfig.size) {
+ logger.info('Destroying redundancy %s because the cache size %s is too heavy.', redundancyModel.url, redundancyModel.strategy)
+
+ await removeVideoRedundancy(redundancyModel)
+ return
+ }
+
+ await this.extendsRedundancy(redundancyModel)
+ } catch (err) {
+ logger.error(
+ 'Cannot extend or remove expiration of %s video from our redundancy system.',
+ this.buildEntryLogId(redundancyModel),
+ {
+ err
+ }
)
-
- await removeVideoRedundancy(redundancyModel)
- continue
- }
-
- const { totalUsed } = await VideoRedundancyModel.getStats(redundancyConfig.strategy)
-
- // If the admin decreased the cache size, remove this redundancy instead of extending it
- if (totalUsed > redundancyConfig.size) {
- logger.info('Destroying redundancy %s because the cache size %s is too heavy.', redundancyModel.url, redundancyModel.strategy)
-
- await removeVideoRedundancy(redundancyModel)
- continue
}
-
- await this.extendsRedundancy(redundancyModel)
- } catch (err) {
- logger.error(
- 'Cannot extend or remove expiration of %s video from our redundancy system.',
- this.buildEntryLogId(redundancyModel),
- { err, ...lTags(redundancyModel.getVideoUUID()) }
- )
- }
+ })
}
}
@@ -152,15 +153,13 @@ export class VideosRedundancyScheduler extends AbstractScheduler {
const expired = await VideoRedundancyModel.listRemoteExpired()
for (const redundancyModel of expired) {
- try {
- await removeVideoRedundancy(redundancyModel)
- } catch (err) {
- logger.error(
- 'Cannot remove redundancy %s from our redundancy system.',
- this.buildEntryLogId(redundancyModel),
- lTags(redundancyModel.getVideoUUID())
- )
- }
+ await logger.withContext([ redundancyModel.getVideoUUID() ], async () => {
+ try {
+ await removeVideoRedundancy(redundancyModel)
+ } catch (err) {
+ logger.error('Cannot remove redundancy %s from our redundancy system.', this.buildEntryLogId(redundancyModel))
+ }
+ })
}
}
@@ -183,7 +182,7 @@ export class VideosRedundancyScheduler extends AbstractScheduler {
const video = await this.loadAndRefreshVideo(data.video.url)
if (!video) {
- logger.info('Video %s we want to duplicate does not existing anymore, skipping.', data.video.url, lTags(data.video.uuid))
+ logger.info('Video %s we want to duplicate does not existing anymore, skipping.', data.video.url)
return
}
@@ -217,7 +216,7 @@ export class VideosRedundancyScheduler extends AbstractScheduler {
const playlist = Object.assign(playlistArg, { Video: video })
const serverActor = await getServerActor()
- logger.info('Duplicating %s streaming playlist in videos redundancy with "%s" strategy.', video.url, strategy, lTags(video.uuid))
+ logger.info('Duplicating %s streaming playlist in videos redundancy with "%s" strategy.', video.url, strategy)
const destDirectory = join(DIRECTORIES.HLS_REDUNDANCY, video.uuid)
const masterPlaylistUrl = playlist.getMasterPlaylistUrl(video)
@@ -239,11 +238,11 @@ export class VideosRedundancyScheduler extends AbstractScheduler {
await sendCreateCacheFile(serverActor, video, createdModel)
- logger.info('Duplicated playlist %s -> %s.', masterPlaylistUrl, createdModel.url, lTags(video.uuid))
+ logger.info('Duplicated playlist %s -> %s.', masterPlaylistUrl, createdModel.url)
}
private async extendsExpirationOf (redundancy: MVideoRedundancyVideo, expiresAfterMs: number) {
- logger.info('Extending expiration of %s.', redundancy.url, lTags(redundancy.getVideoUUID()))
+ logger.info('Extending expiration of %s.', redundancy.url)
const serverActor = await getServerActor()
@@ -275,7 +274,7 @@ export class VideosRedundancyScheduler extends AbstractScheduler {
const videoSize = this.getTotalFileSizes(candidateToDuplicate.streamingPlaylists)
const willUse = alreadyUsed + videoSize
- logger.debug('Checking candidate size.', { maxSize, alreadyUsed, videoSize, willUse, ...lTags(candidateToDuplicate.video.uuid) })
+ logger.debug('Checking candidate size.', { maxSize, alreadyUsed, videoSize, willUse })
return willUse > maxSize
}
diff --git a/server/core/lib/schedulers/watched-words-subscriptions-scheduler.ts b/server/core/lib/schedulers/watched-words-subscriptions-scheduler.ts
index 504e6908ee..bcbde563f2 100644
--- a/server/core/lib/schedulers/watched-words-subscriptions-scheduler.ts
+++ b/server/core/lib/schedulers/watched-words-subscriptions-scheduler.ts
@@ -4,7 +4,7 @@ import {
WatchedWordsSubscriptionAction,
WatchedWordsSubscriptionActions
} from '@peertube/peertube-models'
-import { logger, loggerTagsFactory } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { CONSTRAINTS_FIELDS, SCHEDULER_INTERVALS_MS } from '@server/initializers/constants.js'
import { sequelizeTypescript } from '@server/initializers/database.js'
import { fetchAndValidateWatchedWordsSubscriptionActions } from '@server/lib/watched-words-subscriptions.js'
@@ -14,7 +14,7 @@ import { MWatchedWordsSubscription } from '@server/types/models/index.js'
import { createRebuildAutomaticTagsJob } from '../automatic-tags/automatic-tags.js'
import { AbstractScheduler } from './abstract-scheduler.js'
-const lTags = loggerTagsFactory('schedulers')
+const logger = createLogger('schedulers')
export class WatchedWordsSubscriptionsScheduler extends AbstractScheduler {
private static instance: AbstractScheduler
@@ -38,15 +38,14 @@ export class WatchedWordsSubscriptionsScheduler extends AbstractScheduler {
logger.error('Cannot synchronize watched words subscription.', {
err,
url: subscription.url,
- subscriptionId: subscription.id,
- ...lTags()
+ subscriptionId: subscription.id
})
}
}
}
private async syncSubscription (subscription: MWatchedWordsSubscription) {
- logger.info(`Synchronizing watched words subscription "${subscription.name}" (${subscription.url}).`, lTags())
+ logger.info(`Synchronizing watched words subscription "${subscription.name}" (${subscription.url}).`)
await subscription.update({ state: StreamSyncState.PROCESSING })
@@ -109,8 +108,7 @@ export class WatchedWordsSubscriptionsScheduler extends AbstractScheduler {
accountId: subscription.accountId,
subscriptionId: subscription.id,
listName,
- existingListId: existing.id,
- ...lTags()
+ existingListId: existing.id
}
)
return StreamSyncState.FAILED
@@ -156,8 +154,7 @@ export class WatchedWordsSubscriptionsScheduler extends AbstractScheduler {
subscriptionId: subscription.id,
listName,
maxItems: CONSTRAINTS_FIELDS.WATCHED_WORDS.WORDS.max,
- itemsToStore: wordsSet.size,
- ...lTags()
+ itemsToStore: wordsSet.size
})
return StreamSyncState.FAILED
diff --git a/server/core/lib/schedulers/youtube-dl-update-scheduler.ts b/server/core/lib/schedulers/youtube-dl-update-scheduler.ts
index 30a21ceffe..ead14e4962 100644
--- a/server/core/lib/schedulers/youtube-dl-update-scheduler.ts
+++ b/server/core/lib/schedulers/youtube-dl-update-scheduler.ts
@@ -1,9 +1,9 @@
-import { logger, loggerTagsFactory } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { YoutubeDLCLI } from '@server/helpers/youtube-dl/index.js'
import { SCHEDULER_INTERVALS_MS } from '../../initializers/constants.js'
import { AbstractScheduler } from './abstract-scheduler.js'
-const lTags = loggerTagsFactory('schedulers', 'youtube-dl')
+const logger = createLogger('schedulers', 'youtube-dl')
export class YoutubeDlUpdateScheduler extends AbstractScheduler {
private static instance: AbstractScheduler
@@ -15,7 +15,7 @@ export class YoutubeDlUpdateScheduler extends AbstractScheduler {
}
protected internalExecute () {
- logger.info('Running youtube-dl updated scheduler', lTags())
+ logger.info('Running youtube-dl updated scheduler')
return YoutubeDLCLI.updateYoutubeDLBinary()
}
diff --git a/server/core/lib/stats/shared/video-stats.ts b/server/core/lib/stats/shared/video-stats.ts
index 0d47d65504..1ccb5d5072 100644
--- a/server/core/lib/stats/shared/video-stats.ts
+++ b/server/core/lib/stats/shared/video-stats.ts
@@ -1,5 +1,5 @@
import { buildUUID } from '@peertube/peertube-node-utils'
-import { logger, loggerTagsFactory } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { CONFIG } from '@server/initializers/config.js'
import { REMOTE_DOWNLOADS, REMOTE_VIEWS, VIEW_LIFETIME } from '@server/initializers/constants.js'
import { sendDownload } from '@server/lib/activitypub/send/send-download.js'
@@ -10,7 +10,7 @@ import { MVideo, MVideoImmutable } from '@server/types/models/index.js'
import { LRUCache } from 'lru-cache'
import { Redis } from '../../redis.js'
-const lTags = loggerTagsFactory('views')
+const logger = createLogger('views')
export class VideoStats {
private readonly viewsCache = new LRUCache<string, boolean>({
@@ -45,7 +45,7 @@ export class VideoStats {
}) {
const { video, sessionId, watchTime } = options
- logger.debug('Adding local view to video %s.', video.uuid, { watchTime, ...lTags(video.uuid) })
+ logger.debug('Adding local view to video %s.', video.uuid, { watchTime })
if (!await this.hasEnoughWatchTime(video, watchTime)) return false
@@ -67,11 +67,11 @@ export class VideoStats {
}) {
const { video, viewerId } = options
- logger.debug('Adding remote view to video %s.', video.uuid, { viewerId, ...lTags(video.uuid) })
+ logger.debug('Adding remote view to video %s.', video.uuid, { viewerId })
if (viewerId) {
if (this.remoteViewsCache.has(viewerId)) {
- logger.debug('Ignoring already processed remote view %s.', viewerId, lTags(video.uuid))
+ logger.debug('Ignoring already processed remote view %s.', viewerId)
return false
}
@@ -132,7 +132,7 @@ export class VideoStats {
}) {
const { video } = options
- logger.debug('Adding local download to video %s.', video.uuid, { ...lTags(video.uuid) })
+ logger.debug('Adding local download to video %s.', video.uuid)
await this.addDownload(video)
@@ -148,10 +148,10 @@ export class VideoStats {
}) {
const { video, downloadId, byActorUrl } = options
- logger.debug('Adding remote download to video %s.', video.uuid, { downloadId, ...lTags(video.uuid) })
+ logger.debug('Adding remote download to video %s.', video.uuid, { downloadId })
if (this.remoteDownloadsCache.has(downloadId)) {
- logger.debug('Ignoring already processed remote download %s.', downloadId, lTags(video.uuid))
+ logger.debug('Ignoring already processed remote download %s.', downloadId)
return false
}
@@ -163,7 +163,7 @@ export class VideoStats {
this.remoteDownloadsPerHostCache.set(rateLimitKey, hostDownloads, { noUpdateTTL: true })
if (hostDownloads > REMOTE_DOWNLOADS.MAX_PER_HOST_PER_VIDEO) {
- logger.warn('Too many remote downloads of video %s sent by %s, ignoring.', video.uuid, byActorUrl, lTags(video.uuid))
+ logger.warn('Too many remote downloads of video %s sent by %s, ignoring.', video.uuid, byActorUrl)
return false
}
diff --git a/server/core/lib/stats/shared/video-viewer-counters.ts b/server/core/lib/stats/shared/video-viewer-counters.ts
index 66cd28d0b6..3bd15fe5da 100644
--- a/server/core/lib/stats/shared/video-viewer-counters.ts
+++ b/server/core/lib/stats/shared/video-viewer-counters.ts
@@ -1,6 +1,6 @@
import { isTestOrDevInstance } from '@peertube/peertube-node-utils'
import { exists } from '@server/helpers/custom-validators/misc.js'
-import { logger, loggerTagsFactory } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { VIEW_LIFETIME } from '@server/initializers/constants.js'
import { sendView } from '@server/lib/activitypub/send/send-view.js'
import { canVideoBeFederated } from '@server/lib/activitypub/videos/federate.js'
@@ -9,7 +9,7 @@ import { getServerActor } from '@server/models/application/application.js'
import { VideoModel } from '@server/models/video/video.js'
import { MVideo, MVideoImmutable } from '@server/types/models/index.js'
-const lTags = loggerTagsFactory('views')
+const logger = createLogger('views')
export type ViewerScope = 'local' | 'remote'
export type VideoScope = 'local' | 'remote'
@@ -42,7 +42,7 @@ export class VideoViewerCounters {
}) {
const { video, sessionId } = options
- logger.debug('Adding local viewer to video viewers counter %s.', video.uuid, { ...lTags(video.uuid) })
+ logger.debug('Adding local viewer to video viewers counter %s.', video.uuid)
const viewerId = sessionId + '-' + video.uuid
const viewer = this.idToViewer.get(viewerId)
@@ -67,7 +67,7 @@ export class VideoViewerCounters {
}) {
const { video, viewerExpires, viewerId } = options
- logger.debug('Adding remote viewer to local video %s.', video.uuid, { viewerId, viewerExpires, ...lTags(video.uuid) })
+ logger.debug('Adding remote viewer to local video %s.', video.uuid, { viewerId, viewerExpires })
const viewer = this.idToViewer.get(viewerId)
if (viewer) {
@@ -89,11 +89,7 @@ export class VideoViewerCounters {
}) {
const { video, viewerExpires, viewerId, viewerResultCounter } = options
- logger.debug(
- 'Adding remote viewer to remote video %s.',
- video.uuid,
- { viewerId, viewerResultCounter, viewerExpires, ...lTags(video.uuid) }
- )
+ logger.debug('Adding remote viewer to remote video %s.', video.uuid, { viewerId, viewerResultCounter, viewerExpires })
this.addViewerToVideo({
video,
@@ -180,7 +176,7 @@ export class VideoViewerCounters {
this.processingViewerCounters = true
if (!isTestOrDevInstance()) {
- logger.debug('Updating video viewer counters.', lTags())
+ logger.debug('Updating video viewer counters.')
}
try {
@@ -216,7 +212,7 @@ export class VideoViewerCounters {
}
}
} catch (err) {
- logger.error('Error in video viewer counters scheduler.', { err, ...lTags() })
+ logger.error('Error in video viewer counters scheduler.', { err })
}
this.processingViewerCounters = false
@@ -226,7 +222,7 @@ export class VideoViewerCounters {
const totalViewers = this.getTotalViewersOf(video)
PeerTubeSocket.Instance.sendVideoViewsUpdate(video, totalViewers)
- logger.debug('Video viewers update for %s is %d.', video.url, totalViewers, lTags())
+ logger.debug('Video viewers update for %s is %d.', video.url, totalViewers)
}
private async federateViewerIfNeeded (video: MVideoImmutable, viewer: Viewer) {
diff --git a/server/core/lib/stats/shared/video-viewer-stats.ts b/server/core/lib/stats/shared/video-viewer-stats.ts
index b37df1845f..b9a8e86de1 100644
--- a/server/core/lib/stats/shared/video-viewer-stats.ts
+++ b/server/core/lib/stats/shared/video-viewer-stats.ts
@@ -1,7 +1,7 @@
import { VideoViewEvent } from '@peertube/peertube-models'
import { isTestOrDevInstance } from '@peertube/peertube-node-utils'
import { GeoIP } from '@server/helpers/geo-ip.js'
-import { logger, loggerTagsFactory } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { MAX_LOCAL_VIEWER_WATCH_SECTIONS, VIEWER_SYNC_REDIS, VIEW_LIFETIME } from '@server/initializers/constants.js'
import { sequelizeTypescript } from '@server/initializers/database.js'
import { sendCreateWatchAction } from '@server/lib/activitypub/send/index.js'
@@ -13,7 +13,7 @@ import { VideoModel } from '@server/models/video/video.js'
import { MVideo, MVideoImmutable } from '@server/types/models/index.js'
import { Transaction } from 'sequelize'
-const lTags = loggerTagsFactory('views')
+const logger = createLogger('views')
type LocalViewerStats = {
firstUpdated: number // Date.getTime()
@@ -61,21 +61,28 @@ export class VideoViewerStats {
}) {
const { video, ip, viewEvent, currentTime, sessionId, client, operatingSystem, device } = options
- logger.debug(
- 'Adding local viewer to video stats %s.',
- video.uuid,
- { currentTime, viewEvent, sessionId, client, operatingSystem, device, ...lTags(video.uuid) }
- )
+ logger.debug('Adding local viewer to video stats %s.', video.uuid, {
+ currentTime,
+ viewEvent,
+ sessionId,
+ client,
+ operatingSystem,
+ device
+ })
const nowMs = new Date().getTime()
let stats: LocalViewerStats = await this.getLocalVideoViewer({ sessionId, videoId: video.id })
if (stats && stats.watchSections.length >= MAX_LOCAL_VIEWER_WATCH_SECTIONS) {
- logger.warn(
- 'Too much watch section to store for a viewer, skipping this one',
- { currentTime, viewEvent, sessionId, client, operatingSystem, device, ...lTags(video.uuid) }
- )
+ logger.warn('Too much watch section to store for a viewer, skipping this one', {
+ currentTime,
+ viewEvent,
+ sessionId,
+ client,
+ operatingSystem,
+ device
+ })
return
}
@@ -125,7 +132,7 @@ export class VideoViewerStats {
stats.watchTime = this.buildWatchTimeFromSections(stats.watchSections)
- logger.debug('Set local video viewer stats for video %s.', video.uuid, { stats, ...lTags(video.uuid) })
+ logger.debug('Set local video viewer stats for video %s.', video.uuid, { stats })
this.setLocalVideoViewer(sessionId, video.id, stats)
}
@@ -144,7 +151,7 @@ export class VideoViewerStats {
if (this.processingViewersStats) return
this.processingViewersStats = true
- if (!isTestOrDevInstance()) logger.info('Processing viewer statistics.', lTags())
+ if (!isTestOrDevInstance()) logger.info('Processing viewer statistics.')
const now = new Date().getTime()
@@ -157,11 +164,11 @@ export class VideoViewerStats {
const stats: LocalViewerStats = await this.getLocalVideoViewerByKey(key)
if (!stats) {
- logger.warn('Cannot read viewer stats for Redis key %s, removing invalid entry.', key, lTags())
+ logger.warn('Cannot read viewer stats for Redis key %s, removing invalid entry.', key)
try {
await this.deleteLocalVideoViewersKeys(key)
} catch (err) {
- logger.error('Cannot delete invalid viewer stats for Redis key %s.', key, { err, ...lTags() })
+ logger.error('Cannot delete invalid viewer stats for Redis key %s.', key, { err })
}
continue
}
@@ -185,11 +192,11 @@ export class VideoViewerStats {
await this.deleteLocalVideoViewersKeys(key)
} catch (err) {
- logger.error('Cannot process viewer stats for Redis key %s.', key, { err, stats, ...lTags() })
+ logger.error('Cannot process viewer stats for Redis key %s.', key, { err, stats })
}
}
} catch (err) {
- logger.error('Error in video save viewers stats scheduler.', { err, ...lTags() })
+ logger.error('Error in video save viewers stats scheduler.', { err })
}
this.processingViewersStats = false
diff --git a/server/core/lib/stats/video-stats-manager.ts b/server/core/lib/stats/video-stats-manager.ts
index c607711c6c..406a55edcb 100644
--- a/server/core/lib/stats/video-stats-manager.ts
+++ b/server/core/lib/stats/video-stats-manager.ts
@@ -1,10 +1,12 @@
import { VideoViewEvent } from '@peertube/peertube-models'
import { sha256 } from '@peertube/peertube-node-utils'
-import { logger, loggerTagsFactory } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { CONFIG } from '@server/initializers/config.js'
import { MVideo, MVideoImmutable } from '@server/types/models/index.js'
import { VideoScope, VideoStats, VideoViewerCounters, VideoViewerStats, ViewerScope } from './shared/index.js'
+const logger = createLogger('stats')
+
/**
* If processing a local view:
* - We update viewer information (segments watched, watch time etc)
@@ -22,8 +24,6 @@ import { VideoScope, VideoStats, VideoViewerCounters, VideoViewerStats, ViewerSc
* Viewers statistics are sent to origin instance using the `WatchAction` ActivityPub object
*/
-const lTags = loggerTagsFactory('stats')
-
export class VideoStatsManager {
private static instance: VideoStatsManager
@@ -57,7 +57,7 @@ export class VideoStatsManager {
sessionId = sha256(CONFIG.SECRETS + '-' + ip)
}
- logger.debug(`Processing local view for ${video.url}, ip ${ip} and session id ${sessionId}.`, lTags())
+ logger.debug(`Processing local view for ${video.url}, ip ${ip} and session id ${sessionId}.`)
await this.videoViewerStats.addLocalViewer({ video, ip, sessionId, viewEvent, currentTime, client, operatingSystem, device })
@@ -80,7 +80,7 @@ export class VideoStatsManager {
}) {
const { video, viewerId, viewerExpires, viewerResultCounter } = options
- logger.debug('Processing remote view for %s.', video.url, { viewerExpires, viewerId, ...lTags() })
+ logger.debug('Processing remote view for %s.', video.url, { viewerExpires, viewerId })
// Viewer
if (viewerExpires) {
@@ -102,7 +102,7 @@ export class VideoStatsManager {
}) {
const { video } = options
- logger.debug('Processing local download for %s.', video.url, lTags())
+ logger.debug('Processing local download for %s.', video.url)
await this.videoStats.addLocalDownload({ video })
}
@@ -114,7 +114,7 @@ export class VideoStatsManager {
}) {
const { video, downloadId, byActorUrl } = options
- logger.debug('Processing remote download for %s.', video.url, lTags())
+ logger.debug('Processing remote download for %s.', video.url)
await this.videoStats.addRemoteDownload({ video, downloadId, byActorUrl })
}
diff --git a/server/core/lib/storyboard.ts b/server/core/lib/storyboard.ts
index 86b746244b..005189d48d 100644
--- a/server/core/lib/storyboard.ts
+++ b/server/core/lib/storyboard.ts
@@ -1,6 +1,6 @@
import { ffprobePromise, getVideoStreamDimensionsInfo } from '@peertube/peertube-ffmpeg'
import { retryTransactionWrapper } from '@server/helpers/database-utils.js'
-import { LoggerTags, logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { STORYBOARD } from '@server/initializers/constants.js'
import { sequelizeTypescript } from '@server/initializers/database.js'
import { StoryboardModel } from '@server/models/video/storyboard.js'
@@ -9,6 +9,8 @@ import { MVideo } from '@server/types/models/index.js'
import { scheduleVideoFederation } from './activitypub/videos/federate.js'
import { deleteFileAndCatch } from '@server/helpers/fs.js'
+const logger = createLogger()
+
export async function buildSpriteSize (videoPath: string) {
const probe = await ffprobePromise(videoPath)
const videoStreamInfo = await getVideoStreamDimensionsInfo(videoPath, probe)
@@ -54,7 +56,6 @@ export function findGridSize (options: {
export async function insertStoryboardInDatabase (options: {
videoUUID: string
- lTags: LoggerTags
filename: string
destination: string
imageSize: { width: number, height: number }
@@ -63,13 +64,13 @@ export async function insertStoryboardInDatabase (options: {
spriteDuration: number
federate: boolean
}) {
- const { videoUUID, lTags, imageSize, spriteHeight, spriteWidth, spriteDuration, destination, filename, federate } = options
+ const { videoUUID, imageSize, spriteHeight, spriteWidth, spriteDuration, destination, filename, federate } = options
await retryTransactionWrapper(() => {
return sequelizeTypescript.transaction(async transaction => {
const video = await VideoModel.loadFull(videoUUID, transaction)
if (!video) {
- logger.info(`Video ${videoUUID} does not exist anymore, skipping storyboard generation.`, lTags)
+ logger.info(`Video ${videoUUID} does not exist anymore, skipping storyboard generation.`)
deleteFileAndCatch(destination)
return
}
diff --git a/server/core/lib/sync-channel.ts b/server/core/lib/sync-channel.ts
index 76802677f8..7585a648a7 100644
--- a/server/core/lib/sync-channel.ts
+++ b/server/core/lib/sync-channel.ts
@@ -1,5 +1,5 @@
import { StreamSyncState, VideoImportState } from '@peertube/peertube-models'
-import { logger, loggerTagsFactory, LoggerTagsFn } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { YoutubeDlImportError, YoutubeDlImportErrorCode, YoutubeDLWrapper } from '@server/helpers/youtube-dl/index.js'
import { CONFIG } from '@server/initializers/config.js'
import { buildYoutubeDLImport } from '@server/lib/video-pre-import.js'
@@ -11,7 +11,7 @@ import { ServerConfigManager } from './server-config-manager.js'
import { buildRetryImportJob } from './video-post-import.js'
import { getLeastPrivatePrivacy } from './video.js'
-const rootLTags = loggerTagsFactory('channel-synchronization')
+const logger = createLogger('channel-synchronization')
export async function synchronizeChannel (options: {
channel: MChannelAccountDefault
@@ -29,139 +29,133 @@ export async function synchronizeChannel (options: {
await channelSync.save()
}
- try {
- const user = await UserModel.loadByChannelActorId(channel.Actor.id)
- const youtubeDL = new YoutubeDLWrapper(
- externalChannelUrl,
- ServerConfigManager.Instance.getEnabledResolutions('vod'),
- CONFIG.TRANSCODING.ALWAYS_TRANSCODE_ORIGINAL_RESOLUTION
- )
-
- const lTags = loggerTagsFactory(...rootLTags().tags, externalChannelUrl, channelUsername)
-
- const targetUrls = await youtubeDL.getInfoForListImport({
- userLanguage: user.getLanguage(),
- latestVideosCount: videosCountLimit
- })
-
- logger.info(
- `Fetched ${targetUrls.length} candidate URLs.`,
- { targetUrls, ...lTags() }
- )
-
- const children: CreateJobTypeAndPayload[] = []
- // Ids of video imports already persisted in DB
- // If job creation fails, these must be reverted to FAILED so they are picked up by the retry mechanism instead of staying stuck
- const touchedVideoImportIds: number[] = []
-
- let buildJobErrors = 0
- let stoppedByRateLimit = false
- let lastAttemptedPublishedAt: Date | undefined
-
- for (const targetUrl of targetUrls) {
- logger.debug(`Import candidate: ${targetUrl}`, lTags())
-
- try {
- if (await skipImport({ channel, channelSync, targetUrl, lTags })) continue
-
- const { job, videoImport } = await buildYoutubeDLImport({
- user,
- channel,
- targetUrl,
- channelSync,
- skipPublishedBeforeOrEq,
- importDataOverride: {
- privacy: channelSync?.videoPrivacy || getLeastPrivatePrivacy(),
- support: channel.support
- }
- })
-
- children.push(job)
-
- if (videoImport.Video?.originallyPublishedAt) {
- lastAttemptedPublishedAt = videoImport.Video.originallyPublishedAt
- }
- touchedVideoImportIds.push(videoImport.id)
- } catch (err) {
- if (err instanceof YoutubeDlImportError) {
- if (
- err.code === YoutubeDlImportErrorCode.SKIP_PUBLICATION_DATE ||
- err.code === YoutubeDlImportErrorCode.IS_LIVE ||
- err.isUnavailableVideoError() ||
- err.isAgeLimitError() ||
- err.isRemovedVideoError()
- ) {
- continue
+ // Inner functions (skipImport, buildYoutubeDLImport...) inherit these tags without having to inject them
+ return logger.withContext([ externalChannelUrl, channelUsername ], async () => {
+ try {
+ const user = await UserModel.loadByChannelActorId(channel.Actor.id)
+ const youtubeDL = new YoutubeDLWrapper(
+ externalChannelUrl,
+ ServerConfigManager.Instance.getEnabledResolutions('vod'),
+ CONFIG.TRANSCODING.ALWAYS_TRANSCODE_ORIGINAL_RESOLUTION
+ )
+
+ const targetUrls = await youtubeDL.getInfoForListImport({
+ userLanguage: user.getLanguage(),
+ latestVideosCount: videosCountLimit
+ })
+
+ logger.info(`Fetched ${targetUrls.length} candidate URLs.`, { targetUrls })
+
+ const children: CreateJobTypeAndPayload[] = []
+ // Ids of video imports already persisted in DB
+ // If job creation fails, these must be reverted to FAILED so they are picked up by the retry mechanism instead of staying stuck
+ const touchedVideoImportIds: number[] = []
+
+ let buildJobErrors = 0
+ let stoppedByRateLimit = false
+ let lastAttemptedPublishedAt: Date | undefined
+
+ for (const targetUrl of targetUrls) {
+ logger.debug(`Import candidate: ${targetUrl}`)
+
+ try {
+ if (await skipImport({ channel, channelSync, targetUrl })) continue
+
+ const { job, videoImport } = await buildYoutubeDLImport({
+ user,
+ channel,
+ targetUrl,
+ channelSync,
+ skipPublishedBeforeOrEq,
+ importDataOverride: {
+ privacy: channelSync?.videoPrivacy || getLeastPrivatePrivacy(),
+ support: channel.support
+ }
+ })
+
+ children.push(job)
+
+ if (videoImport.Video?.originallyPublishedAt) {
+ lastAttemptedPublishedAt = videoImport.Video.originallyPublishedAt
}
-
- if (err.isRateLimitError()) {
- logger.info(`Stopping synchronization due to rate limit error in channel ${channelUsername}.`, { err, ...lTags() })
- stoppedByRateLimit = true
- break
+ touchedVideoImportIds.push(videoImport.id)
+ } catch (err) {
+ if (err instanceof YoutubeDlImportError) {
+ if (
+ err.code === YoutubeDlImportErrorCode.SKIP_PUBLICATION_DATE ||
+ err.code === YoutubeDlImportErrorCode.IS_LIVE ||
+ err.isUnavailableVideoError() ||
+ err.isAgeLimitError() ||
+ err.isRemovedVideoError()
+ ) {
+ continue
+ }
+
+ if (err.isRateLimitError()) {
+ logger.info(`Stopping synchronization due to rate limit error in channel ${channelUsername}.`, { err })
+ stoppedByRateLimit = true
+ break
+ }
}
- }
- buildJobErrors++
+ buildJobErrors++
- logger.error(`Cannot build import for ${targetUrl} in channel ${channelUsername}`, { err, ...lTags() })
+ logger.error(`Cannot build import for ${targetUrl} in channel ${channelUsername}`, { err })
+ }
}
- }
- if (channelSync) {
- // Remember how far we got so we retry a full sync next time
- if (stoppedByRateLimit) {
- if (lastAttemptedPublishedAt) channelSync.fullSyncCutoffAt = lastAttemptedPublishedAt
- } else {
- // Not interrupted, reset full sync date
- channelSync.fullSyncCutoffAt = null
- }
+ if (channelSync) {
+ // Remember how far we got so we retry a full sync next time
+ if (stoppedByRateLimit) {
+ if (lastAttemptedPublishedAt) channelSync.fullSyncCutoffAt = lastAttemptedPublishedAt
+ } else {
+ // Not interrupted, reset full sync date
+ channelSync.fullSyncCutoffAt = null
+ }
- await channelSync.save()
+ await channelSync.save()
- // Retry failed imports from this sync (if any)
- const failed = await VideoImportModel.listFailedBySyncId({ channelSyncId: channelSync.id })
- for (const videoImport of failed) {
- logger.info(
- `Retrying failed video import (id: ${videoImport.id}) for channel "${channel.Actor.preferredUsername}"`,
- rootLTags()
- )
+ // Retry failed imports from this sync (if any)
+ const failed = await VideoImportModel.listFailedBySyncId({ channelSyncId: channelSync.id })
+ for (const videoImport of failed) {
+ logger.info(`Retrying failed video import (id: ${videoImport.id}) for channel "${channel.Actor.preferredUsername}"`)
- children.push(await buildRetryImportJob(videoImport))
- touchedVideoImportIds.push(videoImport.id)
+ children.push(await buildRetryImportJob(videoImport))
+ touchedVideoImportIds.push(videoImport.id)
+ }
}
- }
- // Will update the channel sync status
- const parent: CreateJobTypeAndPayload = {
- type: 'after-video-channel-import',
- payload: {
- channelSyncId: channelSync?.id,
- buildJobErrors
+ // Will update the channel sync status
+ const parent: CreateJobTypeAndPayload = {
+ type: 'after-video-channel-import',
+ payload: {
+ channelSyncId: channelSync?.id,
+ buildJobErrors
+ }
}
- }
- try {
- await JobQueue.Instance.createJobWithChildren(parent, children)
- } catch (err) {
try {
- await VideoImportModel.updateStateByIds(touchedVideoImportIds, VideoImportState.FAILED, 'Failed to create the video import job')
- } catch (updateErr) {
- logger.error(`Failed to update state of video imports to FAILED after failing to create the video import job`, {
- updateErr,
- ...rootLTags()
- })
- }
+ await JobQueue.Instance.createJobWithChildren(parent, children)
+ } catch (err) {
+ try {
+ await VideoImportModel.updateStateByIds(touchedVideoImportIds, VideoImportState.FAILED, 'Failed to create the video import job')
+ } catch (updateErr) {
+ logger.error(`Failed to update state of video imports to FAILED after failing to create the video import job`, {
+ updateErr
+ })
+ }
- throw err
- }
- } catch (err) {
- logger.error(`Failed to import ${externalChannelUrl} in channel ${channelUsername}`, { err, ...rootLTags() })
+ throw err
+ }
+ } catch (err) {
+ logger.error(`Failed to import ${externalChannelUrl} in channel ${channelUsername}`, { err })
- if (channelSync) {
- channelSync.state = StreamSyncState.FAILED
- await channelSync.save()
+ if (channelSync) {
+ channelSync.state = StreamSyncState.FAILED
+ await channelSync.save()
+ }
}
- }
+ })
}
// ---------------------------------------------------------------------------
@@ -170,14 +164,13 @@ async function skipImport (options: {
channel: MChannelAccountDefault
channelSync?: MChannelSync
targetUrl: string
- lTags: LoggerTagsFn
}) {
- const { channel, channelSync, targetUrl, lTags } = options
+ const { channel, channelSync, targetUrl } = options
if (await VideoImportModel.urlAlreadyImported({ channelId: channel.id, channelSyncId: channelSync?.id, targetUrl })) {
logger.debug(
`${targetUrl} is already imported for channel ${channel.name}, skipping video channel synchronization.`,
- { channelSync, ...lTags() }
+ { channelSync }
)
return true
diff --git a/server/core/lib/thumbnail.ts b/server/core/lib/thumbnail.ts
index 06fa93a3cf..859e694ee6 100644
--- a/server/core/lib/thumbnail.ts
+++ b/server/core/lib/thumbnail.ts
@@ -1,7 +1,7 @@
import { sortBy } from '@peertube/peertube-core-utils'
import { ThumbnailAspectRatio, VideoFileStream } from '@peertube/peertube-models'
import { generateThumbnailFromVideo } from '@server/helpers/ffmpeg/ffmpeg-image.js'
-import { logger, loggerTagsFactory } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import Bluebird from 'bluebird'
import { FfprobeData } from 'fluent-ffmpeg'
import { remove } from 'fs-extra/esm'
@@ -16,7 +16,7 @@ import { MVideoPlaylistThumbnail } from '../types/models/video/video-playlist.js
import downloadImage from './image-downloader.js'
import { VideoPathManager } from './video-path-manager.js'
-const lTags = loggerTagsFactory('thumbnail')
+const logger = createLogger('thumbnail')
type ImageSize = { height: number, width: number, aspectRatio: ThumbnailAspectRatio }
@@ -92,8 +92,7 @@ export function updateRemotePlaylistThumbnailFromUrl (options: {
if (existingThumbnail) {
logger.debug(
`Remote thumbnail changed for playlist ${playlist.url}, ` +
- `updating filename from ${existingThumbnail.filename} to ${generatedFilename}`,
- lTags(playlist.uuid)
+ `updating filename from ${existingThumbnail.filename} to ${generatedFilename}`
)
}
@@ -137,7 +136,7 @@ export async function createLocalVideoThumbnailsFromImage (options: {
try {
await remove(inputPath)
} catch (err) {
- logger.error('Cannot remove original image after thumbnail generation.', { err, ...lTags() })
+ logger.error('Cannot remove original image after thumbnail generation.', { err })
}
}
@@ -284,8 +283,7 @@ export function updateRemoteVideoThumbnail (options: {
if (hasThumbnailUrlChanged({ existingThumbnail, fileUrl, video, extension })) {
if (existingThumbnail) {
logger.debug(
- `Remote thumbnail changed for video ${video.url}, updating filename from ${existingThumbnail.filename} to ${generatedFilename}`,
- lTags(video.uuid)
+ `Remote thumbnail changed for video ${video.url}, updating filename from ${existingThumbnail.filename} to ${generatedFilename}`
)
}
@@ -314,7 +312,7 @@ export function updateRemoteVideoThumbnail (options: {
export async function regenerateLocalVideoThumbnailsFromVideoIfNeeded (video: MVideoWithAllFiles, ffprobe: FfprobeData) {
if (video.Thumbnails.some(t => t.automaticallyGenerated === false)) return
- logger.info('Re-generate thumbnails for video ' + video.url, lTags(video.uuid))
+ logger.info('Re-generate thumbnails for video ' + video.url)
const thumbnails = await createLocalVideoThumbnailsFromVideo({
video,
@@ -455,12 +453,12 @@ async function generateImageFromVideoFile (options: {
return destination
} catch (err) {
- logger.error('Cannot generate image from video %s.', fromPath, { err, ...lTags() })
+ logger.error('Cannot generate image from video %s.', fromPath, { err })
try {
await remove(pendingImagePath)
} catch (err) {
- logger.debug('Cannot remove pending image path after generation error.', { err, ...lTags() })
+ logger.debug('Cannot remove pending image path after generation error.', { err })
}
throw err
@@ -472,7 +470,7 @@ function getImageExtension (input: string) {
if (MIMETYPES.IMAGE.EXT_MIMETYPE[extension]) return extension
- logger.warn('Cannot determine image extension from input ' + input, lTags())
+ logger.warn('Cannot determine image extension from input ' + input)
return '.jpg'
}
diff --git a/server/core/lib/timeserie.ts b/server/core/lib/timeserie.ts
index 9723266ffe..6b239eab7a 100644
--- a/server/core/lib/timeserie.ts
+++ b/server/core/lib/timeserie.ts
@@ -1,4 +1,6 @@
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
+
+const logger = createLogger()
function buildGroupByAndBoundaries (startDateString: string, endDateString: string) {
const startDate = new Date(startDateString)
diff --git a/server/core/lib/transcoding/default-transcoding-profiles.ts b/server/core/lib/transcoding/default-transcoding-profiles.ts
index f1a2feaa2a..4b3b690b32 100644
--- a/server/core/lib/transcoding/default-transcoding-profiles.ts
+++ b/server/core/lib/transcoding/default-transcoding-profiles.ts
@@ -1,7 +1,9 @@
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { FFmpegCommandWrapper, getDefaultAvailableEncoders } from '@peertube/peertube-ffmpeg'
import { AvailableEncoders, EncoderOptionsBuilder } from '@peertube/peertube-models'
+const logger = createLogger()
+
// ---------------------------------------------------------------------------
// Profile manager to get and change default profiles
// ---------------------------------------------------------------------------
diff --git a/server/core/lib/transcoding/shared/ffmpeg-builder.ts b/server/core/lib/transcoding/shared/ffmpeg-builder.ts
index acb51619c5..35dc47223d 100644
--- a/server/core/lib/transcoding/shared/ffmpeg-builder.ts
+++ b/server/core/lib/transcoding/shared/ffmpeg-builder.ts
@@ -1,9 +1,11 @@
import { FFmpegVOD } from '@peertube/peertube-ffmpeg'
import { getFFmpegCommandWrapperOptions } from '@server/helpers/ffmpeg/index.js'
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { Job } from 'bullmq'
import { VideoTranscodingProfilesManager } from '../default-transcoding-profiles.js'
+const logger = createLogger()
+
export function buildFFmpegVOD (options: {
job?: Job
abortSignal?: AbortSignal
diff --git a/server/core/lib/transcoding/shared/job-builders/abstract-job-builder.ts b/server/core/lib/transcoding/shared/job-builders/abstract-job-builder.ts
index 8b839cf0cd..b6237c719f 100644
--- a/server/core/lib/transcoding/shared/job-builders/abstract-job-builder.ts
+++ b/server/core/lib/transcoding/shared/job-builders/abstract-job-builder.ts
@@ -1,13 +1,13 @@
import { VideoFileStreamType, VideoResolution } from '@peertube/peertube-models'
import { computeOutputFPS } from '@server/helpers/ffmpeg/framerate.js'
-import { logger, loggerTagsFactory } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { CONFIG } from '@server/initializers/config.js'
import { DEFAULT_AUDIO_MERGE_FPS, DEFAULT_AUDIO_MERGE_RESOLUTION } from '@server/initializers/constants.js'
import { Hooks } from '@server/lib/plugins/hooks.js'
import { MUserId, MVideoFile, MVideoFull } from '@server/types/models/index.js'
import { buildOriginalFileResolution, computeResolutionsToTranscode } from '../../transcoding-resolutions.js'
-const lTags = loggerTagsFactory('transcoding')
+const logger = createLogger('transcoding')
export type TranscodingPriorityType = 'required' | 'optional'
@@ -141,7 +141,7 @@ export abstract class AbstractJobBuilder<P extends { transcodingPriority: Transc
const inputStreams = video.getStreamTypes()
const maxResolution = Math.max(...resolutions)
- logger.info(`Manually creating transcoding jobs for ${transcodingType}`, { resolutions, maxResolution, ...lTags(video.uuid) })
+ logger.info(`Manually creating transcoding jobs for ${transcodingType}`, { resolutions, maxResolution })
const inputFPS = video.getMaxFPS()
@@ -237,7 +237,7 @@ export abstract class AbstractJobBuilder<P extends { transcodingPriority: Transc
options
)
- logger.debug('Lower resolutions built for %s.', video.uuid, { resolutionsEnabled, ...lTags(video.uuid) })
+ logger.debug('Lower resolutions built for %s.', video.uuid, { resolutionsEnabled })
const sequentialPayloads: P[][] = []
diff --git a/server/core/lib/uploadx.ts b/server/core/lib/uploadx.ts
index fe161d4fe7..04939e6a49 100644
--- a/server/core/lib/uploadx.ts
+++ b/server/core/lib/uploadx.ts
@@ -1,5 +1,5 @@
import { install } from '@logtape/adaptor-winston'
-import { buildLogger } from '@server/helpers/logger.js'
+import { buildWinstonLogger } from '@server/helpers/logger.js'
import { getResumableUploadPath } from '@server/helpers/upload.js'
import { authenticate } from '@server/middlewares/auth.js'
import { resumableInitValidator } from '@server/middlewares/validators/resumable-upload.js'
@@ -7,7 +7,7 @@ import { FileQuery, Uploadx, Metadata as UploadXMetadata } from '@uploadx/core'
import express, { NextFunction, Request, RequestHandler, Response } from 'express'
import { extname } from 'path'
-const logger = buildLogger({ labelSuffix: 'uploadx' })
+const logger = buildWinstonLogger({ labelSuffix: 'uploadx' })
install(logger)
export const uploadx = new Uploadx({
diff --git a/server/core/lib/user-import-export/exporters/channels-exporter.ts b/server/core/lib/user-import-export/exporters/channels-exporter.ts
index 21621c2128..301571e631 100644
--- a/server/core/lib/user-import-export/exporters/channels-exporter.ts
+++ b/server/core/lib/user-import-export/exporters/channels-exporter.ts
@@ -1,5 +1,5 @@
import { ChannelExportJSON, PlayerChannelSettings } from '@peertube/peertube-models'
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { PlayerSettingModel } from '@server/models/video/player-setting.js'
import { VideoChannelModel } from '@server/models/video/video-channel.js'
import { MChannelBannerAccountDefault } from '@server/types/models/index.js'
@@ -7,6 +7,8 @@ import { MPlayerSetting } from '@server/types/models/video/player-setting.js'
import { ExportResult } from './abstract-user-exporter.js'
import { ActorExporter } from './actor-exporter.js'
+const logger = createLogger()
+
export class ChannelsExporter extends ActorExporter<ChannelExportJSON> {
async export () {
const channelsJSON: ChannelExportJSON['channels'] = []
diff --git a/server/core/lib/user-import-export/exporters/videos-exporter.ts b/server/core/lib/user-import-export/exporters/videos-exporter.ts
index dc083901e4..75f3b3543a 100644
--- a/server/core/lib/user-import-export/exporters/videos-exporter.ts
+++ b/server/core/lib/user-import-export/exporters/videos-exporter.ts
@@ -1,6 +1,6 @@
import { pick, sortBy } from '@peertube/peertube-core-utils'
import { ActivityCreate, FileStorage, VideoExportJSON, VideoObject, VideoPrivacy } from '@peertube/peertube-models'
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { audiencify, getVideoAudience } from '@server/lib/activitypub/audience.js'
import { buildCreateActivity } from '@server/lib/activitypub/send/send-create.js'
import { buildChaptersAPHasPart } from '@server/lib/activitypub/video-chapters.js'
@@ -41,6 +41,8 @@ import { extname, join } from 'path'
import { PassThrough, Readable } from 'stream'
import { AbstractUserExporter, ExportResult } from './abstract-user-exporter.js'
+const logger = createLogger()
+
export class VideosExporter extends AbstractUserExporter<VideoExportJSON> {
// oxlint-disable-next-line no-useless-constructor
constructor (
diff --git a/server/core/lib/user-import-export/importers/abstract-user-importer.ts b/server/core/lib/user-import-export/importers/abstract-user-importer.ts
index 6f435e0c4a..b803093605 100644
--- a/server/core/lib/user-import-export/importers/abstract-user-importer.ts
+++ b/server/core/lib/user-import-export/importers/abstract-user-importer.ts
@@ -1,13 +1,13 @@
import { getFileSize } from '@peertube/peertube-node-utils'
import { Awaitable } from '@peertube/peertube-typescript-utils'
-import { logger, loggerTagsFactory } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { MUserDefault } from '@server/types/models/user/user.js'
import { pathExists, readJSON, remove } from 'fs-extra/esm'
import { dirname, resolve } from 'path'
-const lTags = loggerTagsFactory('user-import')
+const logger = createLogger()
-export abstract class AbstractUserImporter <
+export abstract class AbstractUserImporter<
ROOT_OBJECT,
OBJECT extends { archiveFiles?: Record<string, string | Record<string, string>> },
SANITIZED_OBJECT
@@ -58,22 +58,21 @@ export abstract class AbstractUserImporter <
}
}
} catch (err) {
- logger.error(`Cannot remove file ${file} after successful import`, { err, ...lTags() })
+ logger.error(`Cannot remove file ${file} after successful import`, { err })
}
}
}
protected async isFileValidOrLog (filePath: string, maxSize: number) {
if (!await pathExists(filePath)) {
- logger.warn(`Do not import file ${filePath} that do not exist in zip`, lTags())
+ logger.warn(`Do not import file ${filePath} that do not exist in zip`)
return false
}
const size = await getFileSize(filePath)
if (size > maxSize) {
logger.warn(
- `Do not import too big file ${filePath} (${size} > ${maxSize})`,
- lTags()
+ `Do not import too big file ${filePath} (${size} > ${maxSize})`
)
return false
}
@@ -94,7 +93,7 @@ export abstract class AbstractUserImporter <
const sanitized = this.sanitize(importObject)
if (!sanitized) {
- logger.warn('Do not import object after invalid sanitization', { importObject, ...lTags() })
+ logger.warn('Do not import object after invalid sanitization', { importObject })
summary.errors++
continue
}
@@ -106,7 +105,7 @@ export abstract class AbstractUserImporter <
if (result.duplicate === true) summary.duplicates++
else summary.success++
} catch (err) {
- logger.error('Cannot import object from ' + this.jsonFilePath, { err, importObject, ...lTags() })
+ logger.error('Cannot import object from ' + this.jsonFilePath, { err, importObject })
summary.errors++
}
diff --git a/server/core/lib/user-import-export/importers/account-blocklist-importer.ts b/server/core/lib/user-import-export/importers/account-blocklist-importer.ts
index 2b084f3576..d5f6e0e803 100644
--- a/server/core/lib/user-import-export/importers/account-blocklist-importer.ts
+++ b/server/core/lib/user-import-export/importers/account-blocklist-importer.ts
@@ -2,13 +2,13 @@ import { pick } from '@peertube/peertube-core-utils'
import { BlocklistExportJSON } from '@peertube/peertube-models'
import { isValidActorHandle } from '@server/helpers/custom-validators/activitypub/actor.js'
import { isHostValid } from '@server/helpers/custom-validators/servers.js'
-import { logger, loggerTagsFactory } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { addAccountInBlocklist, addServerInBlocklist } from '@server/lib/blocklist.js'
import { AccountModel } from '@server/models/account/account.js'
import { ServerModel } from '@server/models/server/server.js'
import { AbstractUserImporter } from './abstract-user-importer.js'
-const lTags = loggerTagsFactory('user-import')
+const logger = createLogger()
type ImportObject = { handle: string | null, host: string | null, archiveFiles?: never }
@@ -39,7 +39,7 @@ export class BlocklistImporter extends AbstractUserImporter<BlocklistExportJSON,
private async importAccountBlock (handle: string) {
const accountToBlock = await AccountModel.loadByHandle(handle)
if (!accountToBlock) {
- logger.info('Account %s was not blocked on user import because it cannot be found in the database.', handle, lTags())
+ logger.info('Account %s was not blocked on user import because it cannot be found in the database.', handle)
return
}
@@ -49,7 +49,7 @@ export class BlocklistImporter extends AbstractUserImporter<BlocklistExportJSON,
removeNotificationOfUserId: this.user.id
})
- logger.info('Account %s blocked on user import.', handle, lTags())
+ logger.info('Account %s blocked on user import.', handle)
}
private async importServerBlock (hostToBlock: string) {
@@ -61,6 +61,6 @@ export class BlocklistImporter extends AbstractUserImporter<BlocklistExportJSON,
removeNotificationOfUserId: this.user.id
})
- logger.info('Server %s blocked on user import.', hostToBlock, lTags())
+ logger.info('Server %s blocked on user import.', hostToBlock)
}
}
diff --git a/server/core/lib/user-import-export/importers/account-importer.ts b/server/core/lib/user-import-export/importers/account-importer.ts
index fdd63ea3fc..385a42eafc 100644
--- a/server/core/lib/user-import-export/importers/account-importer.ts
+++ b/server/core/lib/user-import-export/importers/account-importer.ts
@@ -1,19 +1,18 @@
+import { pick } from '@peertube/peertube-core-utils'
import { AccountExportJSON, ActorImageType } from '@peertube/peertube-models'
-import { logger, loggerTagsFactory } from '@server/helpers/logger.js'
-import { AbstractUserImporter } from './abstract-user-importer.js'
-import { updateLocalActorImageFiles } from '@server/lib/local-actor.js'
+import { isUserDescriptionValid, isUserDisplayNameValid } from '@server/helpers/custom-validators/users.js'
import { saveInTransactionWithRetries } from '@server/helpers/database-utils.js'
+import { createLogger } from '@server/helpers/logger.js'
import { CONSTRAINTS_FIELDS } from '@server/initializers/constants.js'
+import { updateLocalActorImageFiles } from '@server/lib/local-actor.js'
import { MAccountDefault } from '@server/types/models/index.js'
-import { isUserDescriptionValid, isUserDisplayNameValid } from '@server/helpers/custom-validators/users.js'
-import { pick } from '@peertube/peertube-core-utils'
+import { AbstractUserImporter } from './abstract-user-importer.js'
-const lTags = loggerTagsFactory('user-import')
+const logger = createLogger()
type SanitizedObject = Pick<AccountExportJSON, 'description' | 'displayName' | 'archiveFiles'>
-export class AccountImporter extends AbstractUserImporter <AccountExportJSON, AccountExportJSON, SanitizedObject> {
-
+export class AccountImporter extends AbstractUserImporter<AccountExportJSON, AccountExportJSON, SanitizedObject> {
protected getImportObjects (json: AccountExportJSON) {
return [ json ]
}
@@ -36,7 +35,7 @@ export class AccountImporter extends AbstractUserImporter <AccountExportJSON, Ac
await this.importAvatar(account, accountImportData)
- logger.info('Account %s imported.', account.name, lTags())
+ logger.info('Account %s imported.', account.name)
return { duplicate: false }
}
diff --git a/server/core/lib/user-import-export/importers/channels-importer.ts b/server/core/lib/user-import-export/importers/channels-importer.ts
index 3326ab2f7b..e457beabe5 100644
--- a/server/core/lib/user-import-export/importers/channels-importer.ts
+++ b/server/core/lib/user-import-export/importers/channels-importer.ts
@@ -8,7 +8,7 @@ import {
isVideoChannelSupportValid,
isVideoChannelUsernameValid
} from '@server/helpers/custom-validators/video-channels.js'
-import { logger, loggerTagsFactory } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { CONSTRAINTS_FIELDS } from '@server/initializers/constants.js'
import { sequelizeTypescript } from '@server/initializers/database.js'
import { JobQueue } from '@server/lib/job-queue/job-queue.js'
@@ -19,7 +19,7 @@ import { VideoChannelModel } from '@server/models/video/video-channel.js'
import { MChannelId } from '@server/types/models/index.js'
import { AbstractUserImporter } from './abstract-user-importer.js'
-const lTags = loggerTagsFactory('user-import')
+const logger = createLogger()
type SanitizedObject = Pick<
ChannelExportJSON['channels'][0],
@@ -53,7 +53,7 @@ export class ChannelsImporter extends AbstractUserImporter<ChannelExportJSON, Ch
const existingChannel = await VideoChannelModel.loadLocalByNameAndPopulateAccount(channelImportData.name)
if (existingChannel) {
- logger.info(`Do not import channel ${existingChannel.name} that already exists on this PeerTube instance`, lTags())
+ logger.info(`Do not import channel ${existingChannel.name} that already exists on this PeerTube instance`)
} else {
const videoChannelCreated = await sequelizeTypescript.transaction(async t => {
return createLocalVideoChannelWithoutKeys(
@@ -85,7 +85,7 @@ export class ChannelsImporter extends AbstractUserImporter<ChannelExportJSON, Ch
})
}
- logger.info('Video channel %s imported.', channelImportData.name, lTags())
+ logger.info('Video channel %s imported.', channelImportData.name)
}
return {
diff --git a/server/core/lib/user-import-export/importers/following-importer.ts b/server/core/lib/user-import-export/importers/following-importer.ts
index 3c6b131ef1..256dc69b20 100644
--- a/server/core/lib/user-import-export/importers/following-importer.ts
+++ b/server/core/lib/user-import-export/importers/following-importer.ts
@@ -1,16 +1,15 @@
+import { pick } from '@peertube/peertube-core-utils'
import { FollowingExportJSON } from '@peertube/peertube-models'
-import { logger, loggerTagsFactory } from '@server/helpers/logger.js'
-import { AbstractUserImporter } from './abstract-user-importer.js'
-import { JobQueue } from '@server/lib/job-queue/job-queue.js'
import { isValidActorHandle } from '@server/helpers/custom-validators/activitypub/actor.js'
-import { pick } from '@peertube/peertube-core-utils'
+import { createLogger } from '@server/helpers/logger.js'
+import { JobQueue } from '@server/lib/job-queue/job-queue.js'
+import { AbstractUserImporter } from './abstract-user-importer.js'
-const lTags = loggerTagsFactory('user-import')
+const logger = createLogger()
type SanitizedObject = Pick<FollowingExportJSON['following'][0], 'targetHandle'>
-export class FollowingImporter extends AbstractUserImporter <FollowingExportJSON, FollowingExportJSON['following'][0], SanitizedObject> {
-
+export class FollowingImporter extends AbstractUserImporter<FollowingExportJSON, FollowingExportJSON['following'][0], SanitizedObject> {
protected getImportObjects (json: FollowingExportJSON) {
return json.following
}
@@ -33,7 +32,7 @@ export class FollowingImporter extends AbstractUserImporter <FollowingExportJSON
await JobQueue.Instance.createJob({ type: 'activitypub-follow', payload })
- logger.info('Subscription job of %s created on user import.', followingImportData.targetHandle, lTags())
+ logger.info('Subscription job of %s created on user import.', followingImportData.targetHandle)
return { duplicate: false }
}
diff --git a/server/core/lib/user-import-export/importers/user-settings-importer.ts b/server/core/lib/user-import-export/importers/user-settings-importer.ts
index 2226e9b97c..1e3f42a439 100644
--- a/server/core/lib/user-import-export/importers/user-settings-importer.ts
+++ b/server/core/lib/user-import-export/importers/user-settings-importer.ts
@@ -14,12 +14,12 @@ import {
isUserVideosHistoryEnabledValid
} from '@server/helpers/custom-validators/users.js'
import { saveInTransactionWithRetries } from '@server/helpers/database-utils.js'
-import { logger, loggerTagsFactory } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { isThemeRegistered } from '@server/lib/plugins/theme-utils.js'
import { UserNotificationSettingModel } from '@server/models/user/user-notification-setting.js'
import { AbstractUserImporter } from './abstract-user-importer.js'
-const lTags = loggerTagsFactory('user-import')
+const logger = createLogger()
type SanitizedObject = Pick<
UserSettingsExportJSON,
@@ -84,7 +84,7 @@ export class UserSettingsImporter extends AbstractUserImporter<UserSettingsExpor
await this.updateSettings(userImportData.notificationSettings)
- logger.info('Settings of user %s imported.', this.user.username, lTags())
+ logger.info('Settings of user %s imported.', this.user.username)
return { duplicate: false }
}
diff --git a/server/core/lib/user-import-export/importers/video-playlists-importer.ts b/server/core/lib/user-import-export/importers/video-playlists-importer.ts
index f4beb8d22f..6ba06314b1 100644
--- a/server/core/lib/user-import-export/importers/video-playlists-importer.ts
+++ b/server/core/lib/user-import-export/importers/video-playlists-importer.ts
@@ -12,7 +12,7 @@ import {
isVideoPlaylistTypeValid
} from '@server/helpers/custom-validators/video-playlists.js'
import { saveInTransactionWithRetries } from '@server/helpers/database-utils.js'
-import { logger, loggerTagsFactory } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { CONSTRAINTS_FIELDS, USER_IMPORT } from '@server/initializers/constants.js'
import { sequelizeTypescript } from '@server/initializers/database.js'
import { sendCreateVideoPlaylist } from '@server/lib/activitypub/send/send-create.js'
@@ -27,7 +27,7 @@ import { VideoModel } from '@server/models/video/video.js'
import { MChannelBannerAccountDefault, MVideoPlaylistFull, MVideoPlaylistThumbnail } from '@server/types/models/index.js'
import { AbstractUserImporter } from './abstract-user-importer.js'
-const lTags = loggerTagsFactory('user-import')
+const logger = createLogger()
type ImportObject = VideoPlaylistsExportJSON['videoPlaylists'][0]
type SanitizedObject = Pick<ImportObject, 'type' | 'displayName' | 'privacy' | 'elements' | 'description' | 'channel' | 'archiveFiles'>
@@ -61,7 +61,7 @@ export class VideoPlaylistsImporter extends AbstractUserImporter<VideoPlaylistsE
const existingPlaylist = await VideoPlaylistModel.loadRegularByAccountAndName(this.user.Account, playlistImportData.displayName)
if (existingPlaylist) {
- logger.info(`Do not import playlist ${playlistImportData.displayName} that already exists in the account`, lTags())
+ logger.info(`Do not import playlist ${playlistImportData.displayName} that already exists in the account`)
return { duplicate: true }
}
@@ -73,7 +73,7 @@ export class VideoPlaylistsImporter extends AbstractUserImporter<VideoPlaylistsE
await sendCreateVideoPlaylist(videoPlaylist, undefined)
- logger.info('Video playlist %s imported.', videoPlaylist.name, lTags(videoPlaylist.uuid))
+ logger.info('Video playlist %s imported.', videoPlaylist.name, { tags: videoPlaylist.uuid })
return { duplicate: false }
}
@@ -138,7 +138,7 @@ export class VideoPlaylistsImporter extends AbstractUserImporter<VideoPlaylistsE
const video = await loadOrCreateVideoIfAllowedForUser(element.videoUrl)
if (!video) {
- logger.debug(`Cannot get or create video ${element.videoUrl} to create playlist element in user import`, lTags())
+ logger.debug(`Cannot get or create video ${element.videoUrl} to create playlist element in user import`)
continue
}
@@ -185,7 +185,7 @@ export class VideoPlaylistsImporter extends AbstractUserImporter<VideoPlaylistsE
try {
await generateThumbnailForPlaylistIfNeeded({ videoPlaylist: playlist, element, video })
} catch (err) {
- logger.error('Cannot generate thumbnail of playlist', { err, ...lTags() })
+ logger.error('Cannot generate thumbnail of playlist', { err })
}
}
}
diff --git a/server/core/lib/user-import-export/importers/videos-importer.ts b/server/core/lib/user-import-export/importers/videos-importer.ts
index 44e743adaf..11dd1bffed 100644
--- a/server/core/lib/user-import-export/importers/videos-importer.ts
+++ b/server/core/lib/user-import-export/importers/videos-importer.ts
@@ -25,7 +25,7 @@ import {
isVideoSupportValid,
isVideoTagValid
} from '@server/helpers/custom-validators/videos.js'
-import { logger, loggerTagsFactory } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { CONFIG } from '@server/initializers/config.js'
import { CONSTRAINTS_FIELDS } from '@server/initializers/constants.js'
import { LocalVideoCreator } from '@server/lib/local-video-creator.js'
@@ -43,7 +43,7 @@ import { FfprobeData } from 'fluent-ffmpeg'
import { parse } from 'path'
import { AbstractUserImporter } from './abstract-user-importer.js'
-const lTags = loggerTagsFactory('user-import')
+const logger = createLogger()
type ImportObject = VideoExportJSON['videos'][0]
type SanitizedObject = Pick<
@@ -193,7 +193,7 @@ export class VideosImporter extends AbstractUserImporter<VideoExportJSON, Import
const existingVideo = await VideoModel.loadByNameAndChannel(videoChannel, videoImportData.name)
if (existingVideo && Math.abs(existingVideo.duration - videoImportData.duration) <= 1) {
- logger.info(`Do not import video ${videoImportData.name} that already exists in the account`, lTags())
+ logger.info(`Do not import video ${videoImportData.name} that already exists in the account`)
return { duplicate: true }
}
@@ -218,8 +218,6 @@ export class VideosImporter extends AbstractUserImporter<VideoExportJSON, Import
const thumbnailPath = this.getSafeArchivePathOrThrow(videoImportData.archiveFiles.thumbnail)
const localVideoCreator = new LocalVideoCreator({
- lTags,
-
videoFile: videoFilePath
? { path: videoFilePath, probe: ffprobe }
: undefined,
@@ -280,11 +278,13 @@ export class VideosImporter extends AbstractUserImporter<VideoExportJSON, Import
const { video } = await localVideoCreator.create()
- await this.importCaptions(video, videoImportData)
- await this.importPlayerSettings(video, videoImportData)
- await this.importVideoEmbedPrivacyDomains(video, videoImportData)
+ await logger.withContext([ video.uuid ], async () => {
+ await this.importCaptions(video, videoImportData)
+ await this.importPlayerSettings(video, videoImportData)
+ await this.importVideoEmbedPrivacyDomains(video, videoImportData)
- logger.info('Video %s imported.', video.name, lTags(video.uuid))
+ logger.info('Video %s imported.', video.name)
+ })
return { duplicate: false }
}
@@ -297,7 +297,7 @@ export class VideosImporter extends AbstractUserImporter<VideoExportJSON, Import
const relativeFilePath = videoImportData.archiveFiles?.captions?.[captionImport.language]
if (!relativeFilePath) {
- logger.warn('Cannot import caption ' + captionImport.language + ': file does not exist in the archive', lTags(video.uuid))
+ logger.warn('Cannot import caption ' + captionImport.language + ': file does not exist in the archive')
continue
}
@@ -366,7 +366,7 @@ export class VideosImporter extends AbstractUserImporter<VideoExportJSON, Import
const acceptedResult = await Hooks.wrapFun(isLocalVideoFileAccepted, acceptParameters, 'filter:api.video.user-import.accept.result')
if (acceptedResult?.accepted !== true) {
- logger.info('Refused local video file to import.', { acceptedResult, acceptParameters, ...lTags() })
+ logger.info('Refused local video file to import.', { acceptedResult, acceptParameters })
throw new Error('Video file is not accepted: ' + acceptedResult.errorMessage || 'unknown reason')
}
diff --git a/server/core/lib/user-import-export/user-exporter.ts b/server/core/lib/user-import-export/user-exporter.ts
index 4984322fc9..64554f3381 100644
--- a/server/core/lib/user-import-export/user-exporter.ts
+++ b/server/core/lib/user-import-export/user-exporter.ts
@@ -2,7 +2,7 @@ import { FileStorage, UserExportState } from '@peertube/peertube-models'
import { getFileSize } from '@peertube/peertube-node-utils'
import { activityPubContextify } from '@server/helpers/activity-pub-utils.js'
import { saveInTransactionWithRetries } from '@server/helpers/database-utils.js'
-import { logger, loggerTagsFactory } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { UserModel } from '@server/models/user/user.js'
import { MUserDefault, MUserExport } from '@server/types/models/index.js'
import type { Archiver } from 'archiver'
@@ -33,7 +33,7 @@ import {
WatchedWordsListsExporter
} from './exporters/index.js'
-const lTags = loggerTagsFactory('user-export')
+const logger = createLogger('user-export')
export class UserExporter {
private archive: Archiver
@@ -70,7 +70,7 @@ export class UserExporter {
await saveInTransactionWithRetries(exportModel)
} catch (err) {
- logger.error('Cannot generate an export', { err, ...lTags() })
+ logger.error('Cannot generate an export', { err })
try {
exportModel.state = UserExportState.ERRORED
@@ -78,7 +78,7 @@ export class UserExporter {
await saveInTransactionWithRetries(exportModel)
} catch (innerErr) {
- logger.error('Cannot set export error state', { err: innerErr, ...lTags() })
+ logger.error('Cannot set export error state', { err: innerErr })
}
try {
@@ -88,7 +88,7 @@ export class UserExporter {
await removeUserExportObjectStorage(exportModel)
}
} catch (innerErr) {
- logger.error('Cannot remove archive path after failure', { err: innerErr, ...lTags() })
+ logger.error('Cannot remove archive path after failure', { err: innerErr })
}
throw err
@@ -115,7 +115,7 @@ export class UserExporter {
})
this.archive.on('warning', err => {
- logger.warn('Warning to archive a file in ' + exportModel.filename, { ...lTags(), err })
+ logger.warn('Warning to archive a file in ' + exportModel.filename, { err })
})
this.archive.on('error', err => {
@@ -131,7 +131,7 @@ export class UserExporter {
for (const { exporter, jsonFilename } of this.buildExporters(exportModel, user)) {
const { json, staticFiles, activityPub, activityPubOutbox } = await exporter.export()
- logger.debug(`Adding JSON file ${jsonFilename} in archive ${exportModel.filename}`, lTags())
+ logger.debug(`Adding JSON file ${jsonFilename} in archive ${exportModel.filename}`)
this.appendJSON(json, join('peertube', jsonFilename))
if (activityPub) {
@@ -148,12 +148,12 @@ export class UserExporter {
for (const file of staticFiles) {
const archivePath = join('files', parse(jsonFilename).name, file.archivePath)
- logger.debug(`Adding static file ${archivePath} in archive`, lTags())
+ logger.debug(`Adding static file ${archivePath} in archive`)
try {
await this.addToArchiveAndWait(await file.readStreamFactory(), archivePath)
} catch (err) {
- logger.error(`Cannot add ${archivePath} in archive`, { err, ...lTags() })
+ logger.error(`Cannot add ${archivePath} in archive`, { err })
}
}
}
diff --git a/server/core/lib/user-import-export/user-importer.ts b/server/core/lib/user-import-export/user-importer.ts
index 775ccdd963..2e9061d85e 100644
--- a/server/core/lib/user-import-export/user-importer.ts
+++ b/server/core/lib/user-import-export/user-importer.ts
@@ -1,7 +1,8 @@
import { UserImportResultSummary, UserImportState } from '@peertube/peertube-models'
import { getFilenameWithoutExt, getFileSize } from '@peertube/peertube-node-utils'
+import { parseBytes } from '@server/helpers/core-utils.js'
import { saveInTransactionWithRetries } from '@server/helpers/database-utils.js'
-import { logger, loggerTagsFactory } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { unzip } from '@server/helpers/unzip.js'
import { UserModel } from '@server/models/user/user.js'
import { MUserDefault, MUserImport } from '@server/types/models/index.js'
@@ -20,9 +21,8 @@ import { UserVideoHistoryImporter } from './importers/user-video-history-importe
import { VideoPlaylistsImporter } from './importers/video-playlists-importer.js'
import { VideosImporter } from './importers/videos-importer.js'
import { WatchedWordsListsImporter } from './importers/watched-words-lists-importer.js'
-import { parseBytes } from '@server/helpers/core-utils.js'
-const lTags = loggerTagsFactory('user-import')
+const logger = createLogger('user-import')
export class UserImporter {
private extractedDirectory: string
@@ -63,25 +63,27 @@ export class UserImporter {
const user = await UserModel.loadByIdFull(importModel.userId)
- for (const { name, importer } of this.buildImporters(user)) {
- try {
- const { duplicates, errors, success } = await importer.import()
+ await logger.withContext([ user.username ], async () => {
+ for (const { name, importer } of this.buildImporters(user)) {
+ try {
+ const { duplicates, errors, success } = await importer.import()
- resultSummary.stats[name].duplicates += duplicates
- resultSummary.stats[name].errors += errors
- resultSummary.stats[name].success += success
- } catch (err) {
- logger.error(`Cannot import ${importer.getJSONFilePath()} from ${inputZip}`, { err, ...lTags() })
+ resultSummary.stats[name].duplicates += duplicates
+ resultSummary.stats[name].errors += errors
+ resultSummary.stats[name].success += success
+ } catch (err) {
+ logger.error(`Cannot import ${importer.getJSONFilePath()} from ${inputZip}`, { err })
- resultSummary.stats[name].errors++
+ resultSummary.stats[name].errors++
+ }
}
- }
- importModel.state = UserImportState.COMPLETED
- importModel.resultSummary = resultSummary
- await saveInTransactionWithRetries(importModel)
+ importModel.state = UserImportState.COMPLETED
+ importModel.resultSummary = resultSummary
+ await saveInTransactionWithRetries(importModel)
+ })
} catch (err) {
- logger.error('Cannot import user archive', { err, ...lTags() })
+ logger.error('Cannot import user archive', { err })
try {
importModel.state = UserImportState.ERRORED
@@ -89,7 +91,7 @@ export class UserImporter {
await saveInTransactionWithRetries(importModel)
} catch (innerErr) {
- logger.error('Cannot set import error state', { err: innerErr, ...lTags() })
+ logger.error('Cannot set import error state', { err: innerErr })
}
throw err
@@ -98,7 +100,7 @@ export class UserImporter {
await remove(getFSUserImportFilePath(importModel))
await remove(this.extractedDirectory)
} catch (innerErr) {
- logger.error('Cannot remove import archive and directory after failure', { err: innerErr, ...lTags() })
+ logger.error('Cannot remove import archive and directory after failure', { err: innerErr })
}
}
}
diff --git a/server/core/lib/user.ts b/server/core/lib/user.ts
index d7ea972e32..4d62b5e494 100644
--- a/server/core/lib/user.ts
+++ b/server/core/lib/user.ts
@@ -8,7 +8,7 @@ import {
UserRole,
UserRoleType
} from '@peertube/peertube-models'
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { CONFIG } from '@server/initializers/config.js'
import { UserModel } from '@server/models/user/user.js'
import { Transaction } from 'sequelize'
@@ -28,6 +28,8 @@ import { createLocalVideoChannelWithoutKeys } from './video-channel.js'
import { createWatchLaterPlaylist } from './video-playlist.js'
import { createPrivateAndPublicKeys } from '@server/helpers/peertube-crypto.js'
+const logger = createLogger()
+
type ChannelNames = { name: string, displayName: string }
export function buildUser (options: {
diff --git a/server/core/lib/video-blacklist.ts b/server/core/lib/video-blacklist.ts
index a61f9e5f8e..795d741286 100644
--- a/server/core/lib/video-blacklist.ts
+++ b/server/core/lib/video-blacklist.ts
@@ -22,7 +22,7 @@ import {
MVideoWithSchedule
} from '@server/types/models/index.js'
import { Transaction } from 'sequelize'
-import { logger, loggerTagsFactory } from '../helpers/logger.js'
+import { createLogger } from '../helpers/logger.js'
import { CONFIG } from '../initializers/config.js'
import { VideoBlacklistModel } from '../models/video/video-blacklist.js'
import { sendDeleteVideo } from './activitypub/send/index.js'
@@ -31,7 +31,7 @@ import { LiveManager } from './live/live-manager.js'
import { Notifier } from './notifier/index.js'
import { Hooks } from './plugins/hooks.js'
-const lTags = loggerTagsFactory('blacklist')
+const logger = createLogger('blacklist')
export async function autoBlacklistVideoIfNeeded (parameters: {
video: MVideoWithBlacklistLight
@@ -99,7 +99,7 @@ async function _autoBlacklist (options: {
afterCommitIfTransaction(transaction, () => Notifier.Instance.notifyOnVideoAutoBlacklist(videoBlacklist))
}
- logger.info('Video %s auto-blacklisted.', video.uuid, lTags(video.uuid))
+ logger.info('Video %s auto-blacklisted.', video.uuid)
}
function _autoBlacklistByInstancePolicyNeeded (parameters: {
diff --git a/server/core/lib/video-captions.ts b/server/core/lib/video-captions.ts
index 926c303a53..4339315012 100644
--- a/server/core/lib/video-captions.ts
+++ b/server/core/lib/video-captions.ts
@@ -1,10 +1,10 @@
import { FileStorage, VideoFileStream } from '@peertube/peertube-models'
import { buildSUUID } from '@peertube/peertube-node-utils'
-import { AbstractTranscriber, TranscriptionModel, WhisperBuiltinModel, transcriberFactory } from '@peertube/peertube-transcription'
+import { AbstractTranscriber, transcriberFactory, TranscriptionModel, WhisperBuiltinModel } from '@peertube/peertube-transcription'
import { moveAndProcessCaptionFile } from '@server/helpers/captions-utils.js'
import { isVideoCaptionLanguageValid, isVTTFileValid } from '@server/helpers/custom-validators/video-captions.js'
import { retryTransactionWrapper } from '@server/helpers/database-utils.js'
-import { logger, loggerTagsFactory } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { CONFIG } from '@server/initializers/config.js'
import { DIRECTORIES } from '@server/initializers/constants.js'
import { sequelizeTypescript } from '@server/initializers/database.js'
@@ -12,7 +12,7 @@ import { VideoCaptionModel } from '@server/models/video/video-caption.js'
import { VideoJobInfoModel } from '@server/models/video/video-job-info.js'
import { VideoStreamingPlaylistModel } from '@server/models/video/video-streaming-playlist.js'
import { VideoModel } from '@server/models/video/video.js'
-import { MStreamingPlaylist, MVideo, MVideoCaption, MVideoFull, MVideoId, MVideoUUID, MVideoUrl } from '@server/types/models/index.js'
+import { MStreamingPlaylist, MVideo, MVideoCaption, MVideoFull, MVideoId, MVideoUrl, MVideoUUID } from '@server/types/models/index.js'
import { MutexInterface } from 'async-mutex'
import { ensureDir, remove } from 'fs-extra/esm'
import { writeFile } from 'fs/promises'
@@ -24,7 +24,7 @@ import { Notifier } from './notifier/notifier.js'
import { TranscriptionJobHandler } from './runners/index.js'
import { VideoPathManager } from './video-path-manager.js'
-const lTags = loggerTagsFactory('video-caption')
+const logger = createLogger('caption')
export async function createLocalCaption (options: {
video: MVideo
@@ -49,7 +49,7 @@ export async function createLocalCaption (options: {
if (!await isVTTFileValid(captionDest)) {
remove(captionDest)
- .catch(err => logger.error('Cannot remove invalid VTT file', { err, ...lTags(video.uuid) }))
+ .catch(err => logger.error('Cannot remove invalid VTT file', { err }))
throw new Error(`Invalid VTT file`)
}
@@ -71,7 +71,7 @@ export async function createLocalCaption (options: {
await JobQueue.Instance.createJob({ type: 'move-to-object-storage', payload: { captionId: videoCaption.id } })
}
- logger.info(`Created/replaced caption ${videoCaption.filename} of ${language} of video ${video.uuid}`, lTags(video.uuid))
+ logger.info(`Created/replaced caption ${videoCaption.filename} of ${language} of video ${video.uuid}`)
return Object.assign(videoCaption, { Video: video })
}
@@ -90,10 +90,7 @@ export async function createAllCaptionPlaylistsOnFSIfNeeded (video: MVideo) {
caption.m3u8Filename = await upsertCaptionPlaylistOnFS(caption, video)
await caption.save()
} catch (err) {
- logger.error(
- `Cannot create caption playlist ${caption.filename} (${caption.language}) of video ${video.uuid}`,
- { ...lTags(video.uuid), err }
- )
+ logger.error(`Cannot create caption playlist ${caption.filename} (${caption.language}) of video ${video.uuid}`, { err })
}
}
}
@@ -106,7 +103,7 @@ export async function updateHLSMasterOnCaptionChangeIfNeeded (video: MVideo) {
}
export async function updateHLSMasterOnCaptionChange (video: MVideo, hls: MStreamingPlaylist) {
- logger.debug(`Updating HLS master playlist of video ${video.uuid} after caption change`, lTags(video.uuid))
+ logger.debug(`Updating HLS master playlist of video ${video.uuid} after caption change`)
await updateM3U8AndShaPlaylist(video, hls)
}
@@ -127,11 +124,11 @@ export async function createTranscriptionTaskIfNeeded (video: MVideoId & MVideoU
if (CONFIG.VIDEO_TRANSCRIPTION.ENABLED !== true) return
if (!await VideoModel.loadHasStream(video.id, VideoFileStream.AUDIO)) {
- logger.info(`Do not create transcription job for ${video.url} that doesn't have an audio stream`, lTags(video.uuid))
+ logger.info(`Do not create transcription job for ${video.url} that doesn't have an audio stream`)
return
}
- logger.info(`Creating transcription job for ${video.url}`, lTags(video.uuid))
+ logger.info(`Creating transcription job for ${video.url}`)
if (CONFIG.VIDEO_TRANSCRIPTION.REMOTE_RUNNERS.ENABLED === true) {
await new TranscriptionJobHandler().create({ video })
@@ -171,7 +168,7 @@ export async function generateSubtitle (options: {
})
if (!CONFIG.VIDEO_TRANSCRIPTION.ENGINE_PATH) {
- logger.info(`Installing transcriber ${transcriber.engine.name} to generate subtitles`, lTags())
+ logger.info(`Installing transcriber ${transcriber.engine.name} to generate subtitles`)
await transcriber.install(DIRECTORIES.LOCAL_PIP_DIRECTORY)
}
}
@@ -180,17 +177,14 @@ export async function generateSubtitle (options: {
const video = await VideoModel.loadFull(options.video.uuid)
if (!video) {
- logger.info('Do not process transcription, video does not exist anymore.', lTags(options.video.uuid))
+ logger.info('Do not process transcription, video does not exist anymore.')
return undefined
}
const file = video.getMaxQualityFile(VideoFileStream.AUDIO)
if (!file) {
- logger.info(
- `Do not run transcription for ${video.uuid} in ${outputPath} because it does not contain an audio stream`,
- { video, ...lTags(video.uuid) }
- )
+ logger.info(`Do not run transcription for ${video.uuid} in ${outputPath} because it does not contain an audio stream`, { video })
return
}
@@ -199,7 +193,7 @@ export async function generateSubtitle (options: {
// Release input file mutex now we are going to run the command
setTimeout(() => inputFileMutexReleaser(), 1000)
- logger.info(`Running transcription for ${video.uuid} in ${outputPath}`, lTags(video.uuid))
+ logger.info(`Running transcription for ${video.uuid} in ${outputPath}`)
const transcriptFile = await transcriber.transcribe({
mediaFilePath: inputPath,
@@ -217,7 +211,7 @@ export async function generateSubtitle (options: {
const refreshedVideo = await VideoModel.loadFull(video.uuid)
if (!refreshedVideo) {
- logger.info(`Do not process transcription for video ${video.uuid}: it does not exist anymore.`, lTags(video.uuid))
+ logger.info(`Do not process transcription for video ${video.uuid}: it does not exist anymore.`)
return
}
@@ -228,7 +222,7 @@ export async function generateSubtitle (options: {
if (inputFileMutexReleaser) inputFileMutexReleaser()
VideoJobInfoModel.decrease(options.video.uuid, 'pendingTranscription')
- .catch(err => logger.error('Cannot decrease pendingTranscription job count', { err, ...lTags(options.video.uuid) }))
+ .catch(err => logger.error('Cannot decrease pendingTranscription job count', { err }))
}
}
@@ -236,12 +230,11 @@ export async function onTranscriptionEnded (options: {
video: MVideoFull
language: string
vttPath: string
- lTags?: (string | number)[]
}) {
- const { video, language, vttPath, lTags: customLTags = [] } = options
+ const { video, language, vttPath } = options
if (!isVideoCaptionLanguageValid(language)) {
- logger.warn(`Invalid transcription language for video ${video.uuid}`, lTags(video.uuid))
+ logger.warn(`Invalid transcription language for video ${video.uuid}`)
return
}
@@ -257,9 +250,7 @@ export async function onTranscriptionEnded (options: {
if (existing && !existing.automaticallyGenerated) {
logger.info(
- // oxlint-disable-next-line max-len
- `Do not replace existing caption for video ${video.uuid} after transcription (subtitle may have been added while during the transcription process)`,
- lTags(video.uuid)
+ `Do not replace existing caption for video ${video.uuid} after transcription (subtitle may have been added while during the transcription process)`
)
return
}
@@ -282,14 +273,14 @@ export async function onTranscriptionEnded (options: {
scheduleVideoFederation({ video })
- logger.info(`Transcription ended for ${video.uuid}`, lTags(video.uuid, ...customLTags))
+ logger.info(`Transcription ended for ${video.uuid}`)
}
export async function upsertCaptionPlaylistOnFS (caption: MVideoCaption, video: MVideo) {
const m3u8Filename = VideoCaptionModel.generateM3U8Filename(caption.filename)
const m3u8Destination = VideoPathManager.Instance.getFSHLSOutputPath(video, m3u8Filename)
- logger.debug(`Creating caption playlist ${m3u8Destination} of video ${video.uuid}`, lTags(video.uuid))
+ logger.debug(`Creating caption playlist ${m3u8Destination} of video ${video.uuid}`)
const content = buildCaptionM3U8Content({ video, caption })
await ensureDir(dirname(m3u8Destination))
diff --git a/server/core/lib/video-chapters.ts b/server/core/lib/video-chapters.ts
index eac1c0e171..0b5b4baa34 100644
--- a/server/core/lib/video-chapters.ts
+++ b/server/core/lib/video-chapters.ts
@@ -1,14 +1,14 @@
import { parseChapters, sortBy } from '@peertube/peertube-core-utils'
import { VideoChapter } from '@peertube/peertube-models'
import { afterCommitIfTransaction } from '@server/helpers/database-utils.js'
-import { logger, loggerTagsFactory } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { CONSTRAINTS_FIELDS } from '@server/initializers/constants.js'
import { VideoChapterModel } from '@server/models/video/video-chapter.js'
import { MVideoImmutable } from '@server/types/models/index.js'
import { Transaction } from 'sequelize'
import { InternalEventEmitter } from './internal-event-emitter.js'
-const lTags = loggerTagsFactory('video', 'chapters')
+const logger = createLogger('video', 'chapter')
export async function replaceChapters (options: {
video: MVideoImmutable
@@ -53,10 +53,12 @@ export async function replaceChaptersFromDescriptionIfNeeded (options: {
const chaptersFromOldDescription = sortBy(parseChapters(oldDescription, CONSTRAINTS_FIELDS.VIDEO_CHAPTERS.TITLE.max), 'timecode')
const existingChapters = await VideoChapterModel.listChaptersOfVideo(video.id, transaction)
- logger.debug(
- 'Check if we replace chapters from description',
- { oldDescription, chaptersFromOldDescription, newDescription, existingChapters, ...lTags(video.uuid) }
- )
+ logger.debug('Check if we replace chapters from description', {
+ oldDescription,
+ chaptersFromOldDescription,
+ newDescription,
+ existingChapters
+ })
// Then we can update chapters from the new description
if (areSameChapters(chaptersFromOldDescription, existingChapters)) {
@@ -65,7 +67,7 @@ export async function replaceChaptersFromDescriptionIfNeeded (options: {
await replaceChapters({ video, chapters: chaptersFromNewDescription, transaction })
- logger.info('Replaced chapters of video ' + video.uuid, { chaptersFromNewDescription, ...lTags(video.uuid) })
+ logger.info('Replaced chapters of video ' + video.uuid, { chaptersFromNewDescription })
return true
}
diff --git a/server/core/lib/video-comment.ts b/server/core/lib/video-comment.ts
index 2d598bc8ac..71b92661b2 100644
--- a/server/core/lib/video-comment.ts
+++ b/server/core/lib/video-comment.ts
@@ -1,5 +1,5 @@
import { AutomaticTagPolicy, ResultList, UserRight, VideoCommentPolicy, VideoCommentThreadTree } from '@peertube/peertube-models'
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { sequelizeTypescript } from '@server/initializers/database.js'
import { AccountModel } from '@server/models/account/account.js'
import { getServerAccount } from '@server/models/application/application.js'
@@ -24,6 +24,8 @@ import { Notifier } from './notifier/notifier.js'
import { Hooks } from './plugins/hooks.js'
import { afterCommitIfTransaction } from '@server/helpers/database-utils.js'
+const logger = createLogger()
+
export async function removeComment (commentArg: MComment, req: express.Request, res: express.Response) {
let videoCommentInstanceBefore: MCommentOwnerVideo
diff --git a/server/core/lib/video-download.ts b/server/core/lib/video-download.ts
index d7411376ec..469ae859e2 100644
--- a/server/core/lib/video-download.ts
+++ b/server/core/lib/video-download.ts
@@ -1,7 +1,7 @@
import { FFmpegContainer } from '@peertube/peertube-ffmpeg'
import { FileStorage } from '@peertube/peertube-models'
import { getFFmpegCommandWrapperOptions } from '@server/helpers/ffmpeg/ffmpeg-options.js'
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { buildRequestError, doRequestAndSaveToFile, generateRequestStream } from '@server/helpers/requests.js'
import { ThrottleStream } from '@server/helpers/stream-throttle.js'
import { REQUEST_TIMEOUTS } from '@server/initializers/constants.js'
@@ -10,7 +10,6 @@ import { createReadStream } from 'fs'
import { remove } from 'fs-extra/esm'
import { PassThrough, Readable, Writable } from 'stream'
import { pipeline } from 'stream/promises'
-import { lTags } from './object-storage/shared/index.js'
import {
getHLSFileReadStream,
getWebVideoFileReadStream,
@@ -19,6 +18,8 @@ import {
} from './object-storage/videos.js'
import { VideoPathManager } from './video-path-manager.js'
+const logger = createLogger('video-download')
+
export class VideoDownload {
static totalDownloads = 0
@@ -46,114 +47,116 @@ export class VideoDownload {
bytesPerIpPerSecond: number
ip: string
}) {
- const totalBytesPerSecond = options?.totalBytesPerSecond
- const bytesPerIpPerSecond = options?.bytesPerIpPerSecond
- const ip = options?.ip
+ return logger.withContext([ this.video.uuid ], async () => {
+ const totalBytesPerSecond = options?.totalBytesPerSecond
+ const bytesPerIpPerSecond = options?.bytesPerIpPerSecond
+ const ip = options?.ip
+
+ let rejectOnStreamError: (err: Error) => void
+ const streamErrorPromise = new Promise<never>((_, rej) => {
+ rejectOnStreamError = rej
+ })
- let rejectOnStreamError: (err: Error) => void
- const streamErrorPromise = new Promise<never>((_, rej) => {
- rejectOnStreamError = rej
- })
+ const run = async () => {
+ VideoDownload.totalDownloads++
- const run = async () => {
- VideoDownload.totalDownloads++
+ const maxResolution = await this.buildMuxInputs(rejectOnStreamError)
- const maxResolution = await this.buildMuxInputs(rejectOnStreamError)
+ // Include cover to audio file?
+ const { coverPath, isTmpDestination } = maxResolution === 0
+ ? await this.buildCoverInput()
+ : { coverPath: undefined, isTmpDestination: false }
- // Include cover to audio file?
- const { coverPath, isTmpDestination } = maxResolution === 0
- ? await this.buildCoverInput()
- : { coverPath: undefined, isTmpDestination: false }
+ if (coverPath && isTmpDestination) {
+ this.tmpDestinations.push(coverPath)
+ }
- if (coverPath && isTmpDestination) {
- this.tmpDestinations.push(coverPath)
- }
+ // Prefer sending the file directly if possible
+ if (this.allowDirectSending && !coverPath && this.inputs.length === 1) {
+ logger.info(`Piping single file for video ${this.video.url}`, { input: this.inputsToLog()[0] })
- // Prefer sending the file directly if possible
- if (this.allowDirectSending && !coverPath && this.inputs.length === 1) {
- logger.info(`Piping single file for video ${this.video.url}`, { input: this.inputsToLog()[0], ...lTags(this.video.uuid) })
+ const input = typeof this.inputs[0] === 'string'
+ ? createReadStream(this.inputs[0])
+ : this.inputs[0]
- const input = typeof this.inputs[0] === 'string'
- ? createReadStream(this.inputs[0])
- : this.inputs[0]
+ const throttleStream = totalBytesPerSecond || bytesPerIpPerSecond
+ ? new ThrottleStream({ totalBytesPerSecond, bytesPerIpPerSecond, ip })
+ : new PassThrough()
- const throttleStream = totalBytesPerSecond || bytesPerIpPerSecond
- ? new ThrottleStream({ totalBytesPerSecond, bytesPerIpPerSecond, ip })
- : new PassThrough()
+ try {
+ await pipeline(input, throttleStream, output)
+ } catch (err) {
+ if ((err?.message || '').includes('Output stream closed')) {
+ logger.info(`Client aborted direct download for video ${this.video.url}`)
+ return
+ }
- try {
- await pipeline(input, throttleStream, output)
- } catch (err) {
- if ((err?.message || '').includes('Output stream closed')) {
- logger.info(`Client aborted direct download for video ${this.video.url}`, lTags(this.video.uuid))
- return
+ throw err
}
- throw err
+ return
}
- return
- }
+ logger.info(`Muxing files for video ${this.video.url}`, { inputs: this.inputsToLog() })
- logger.info(`Muxing files for video ${this.video.url}`, { inputs: this.inputsToLog(), ...lTags(this.video.uuid) })
+ this.ffmpegContainer = new FFmpegContainer(getFFmpegCommandWrapperOptions('vod'))
- this.ffmpegContainer = new FFmpegContainer(getFFmpegCommandWrapperOptions('vod'))
+ const throttleStream = totalBytesPerSecond || bytesPerIpPerSecond
+ ? new ThrottleStream({ totalBytesPerSecond, bytesPerIpPerSecond, ip })
+ : undefined
- const throttleStream = totalBytesPerSecond || bytesPerIpPerSecond
- ? new ThrottleStream({ totalBytesPerSecond, bytesPerIpPerSecond, ip })
- : undefined
+ const finalOutput = throttleStream ?? output
- const finalOutput = throttleStream ?? output
+ const throttlePipeline = throttleStream
+ ? pipeline(throttleStream, output)
+ : Promise.resolve()
- const throttlePipeline = throttleStream
- ? pipeline(throttleStream, output)
- : Promise.resolve()
+ try {
+ // Run in parallel to prevent throttlePipeline unhandled rejection if an input stream errors
+ await Promise.all([
+ this.ffmpegContainer.mergeInputs({
+ inputs: this.inputs,
+ output: finalOutput,
+ logError: false,
- try {
- // Run in parallel to prevent throttlePipeline unhandled rejection if an input stream errors
- await Promise.all([
- this.ffmpegContainer.mergeInputs({
- inputs: this.inputs,
- output: finalOutput,
- logError: false,
-
- // Include a cover if this is an audio file
- coverPath
- }),
-
- throttlePipeline
- ])
-
- logger.info(`Mux ended for video ${this.video.url}`, { inputs: this.inputsToLog(), ...lTags(this.video.uuid) })
- } catch (err) {
- const message = err?.message || ''
-
- if (message.includes('Output stream closed')) {
- logger.info(`Client aborted mux for video ${this.video.url}`, lTags(this.video.uuid))
- return
- }
+ // Include a cover if this is an audio file
+ coverPath
+ }),
- if (err.inputStreamError) {
- err.inputStreamError = buildRequestError(err.inputStreamError)
- }
+ throttlePipeline
+ ])
- logger.warn(`Cannot mux files of video ${this.video.url}`, { err, inputs: this.inputsToLog(), ...lTags(this.video.uuid) })
+ logger.info(`Mux ended for video ${this.video.url}`, { inputs: this.inputsToLog() })
+ } catch (err) {
+ const message = err?.message || ''
- throw err
- } finally {
- // cleanup() may already have force killed and unset ffmpegContainer if a stream errored and won the race below
- this.ffmpegContainer?.forceKill()
+ if (message.includes('Output stream closed')) {
+ logger.info(`Client aborted mux for video ${this.video.url}`)
+ return
+ }
+
+ if (err.inputStreamError) {
+ err.inputStreamError = buildRequestError(err.inputStreamError)
+ }
+
+ logger.warn(`Cannot mux files of video ${this.video.url}`, { err, inputs: this.inputsToLog() })
+
+ throw err
+ } finally {
+ // cleanup() may already have force killed and unset ffmpegContainer if a stream errored and won the race below
+ this.ffmpegContainer?.forceKill()
+ }
}
- }
- try {
- // If a stream errors, don't wait for run() to notice: reject immediately so the caller isn't stuck
- // run() keeps executing in the background but will abort once cleanup() destroys its streams/ffmpeg process
- await Promise.race([ run(), streamErrorPromise ])
- } finally {
- this.cleanup()
- .catch(cleanupErr => logger.error('Cannot cleanup after mux error', { err: cleanupErr, ...lTags(this.video.uuid) }))
- }
+ try {
+ // If a stream errors, don't wait for run() to notice: reject immediately so the caller isn't stuck
+ // run() keeps executing in the background but will abort once cleanup() destroys its streams/ffmpeg process
+ await Promise.race([ run(), streamErrorPromise ])
+ } finally {
+ this.cleanup()
+ .catch(cleanupErr => logger.error('Cannot cleanup after mux error', { err: cleanupErr }))
+ }
+ })
}
// ---------------------------------------------------------------------------
@@ -179,8 +182,7 @@ export class VideoDownload {
logger.warn(`Cannot build mux input of video ${this.video.url}`, {
err,
- inputs: this.inputsToLog(),
- ...lTags(this.video.uuid)
+ inputs: this.inputsToLog()
})
// cleanup() is already run by muxToMergeVideoFiles's finally block once this rejection wins the race
@@ -316,7 +318,7 @@ export class VideoDownload {
for (const destination of this.tmpDestinations) {
await remove(destination)
- .catch(err => logger.error('Cannot remove tmp destination', { err, destination, ...lTags(this.video.uuid) }))
+ .catch(err => logger.error('Cannot remove tmp destination', { err, destination }))
}
for (const input of this.inputs) {
@@ -330,6 +332,6 @@ export class VideoDownload {
this.ffmpegContainer = undefined
}
- logger.debug(`Cleaned muxing for video ${this.video.url}`, { inputs: this.inputsToLog(), ...lTags(this.video.uuid) })
+ logger.debug(`Cleaned muxing for video ${this.video.url}`, { inputs: this.inputsToLog() })
}
}
diff --git a/server/core/lib/video-file.ts b/server/core/lib/video-file.ts
index 404776a933..c7e247ce6e 100644
--- a/server/core/lib/video-file.ts
+++ b/server/core/lib/video-file.ts
@@ -8,7 +8,7 @@ import {
} from '@peertube/peertube-ffmpeg'
import { FileStorage, VideoFileFormatFlag, VideoFileMetadata, VideoFileStream, VideoResolution } from '@peertube/peertube-models'
import { getFileSize, getLowercaseExtension } from '@peertube/peertube-node-utils'
-import { logger, loggerTagsFactory } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { CONFIG } from '@server/initializers/config.js'
import { MIMETYPES } from '@server/initializers/constants.js'
import { VideoFileModel } from '@server/models/video/video-file.js'
@@ -20,6 +20,8 @@ import { storeOriginalVideoFile } from './object-storage/videos.js'
import { generateHLSVideoFilename, generateWebVideoFilename } from './paths.js'
import { VideoPathManager } from './video-path-manager.js'
+const logger = createLogger()
+
export async function buildNewFile (options: {
path: string
mode: 'web-video' | 'hls'
@@ -221,9 +223,7 @@ export async function saveNewOriginalFileIfNeeded (video: MVideo, videoFile: MVi
if (!videoSource || videoSource.keptOriginalFilename) return
videoSource.keptOriginalFilename = videoFile.filename
- const lTags = loggerTagsFactory(video.uuid)
-
- logger.info(`Storing original video file ${videoSource.keptOriginalFilename} of video ${video.name}`, lTags())
+ logger.info(`Storing original video file ${videoSource.keptOriginalFilename} of video ${video.name}`)
const sourcePath = VideoPathManager.Instance.getFSVideoFileOutputPath(video, videoFile)
@@ -250,7 +250,7 @@ export async function saveNewOriginalFileIfNeeded (video: MVideo, videoFile: MVi
try {
await video.removeOriginalFile(oldSource)
} catch (err) {
- logger.error('Cannot delete old original file ' + oldSource.keptOriginalFilename, { err, ...lTags() })
+ logger.error('Cannot delete old original file ' + oldSource.keptOriginalFilename, { err })
}
}
}
diff --git a/server/core/lib/video-path-manager.ts b/server/core/lib/video-path-manager.ts
index f77ab8d489..4ec84a69fc 100644
--- a/server/core/lib/video-path-manager.ts
+++ b/server/core/lib/video-path-manager.ts
@@ -1,7 +1,7 @@
import { FileStorage } from '@peertube/peertube-models'
import { buildUUID } from '@peertube/peertube-node-utils'
import { Awaitable } from '@peertube/peertube-typescript-utils'
-import { logger, loggerTagsFactory } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { extractVideo } from '@server/helpers/video.js'
import { CONFIG } from '@server/initializers/config.js'
import { DIRECTORIES } from '@server/initializers/constants.js'
@@ -21,12 +21,12 @@ import { makeHLSFileAvailable, makeWebVideoFileAvailable } from './object-storag
import { getHLSDirectory, getHLSResolutionPlaylistFilename } from './paths.js'
import { isVideoInPrivateDirectory } from './video-privacy.js'
+const logger = createLogger('video-path-manager')
+
type MakeAvailableCB<T> = (path: string) => Awaitable<T>
type MakeAvailableMultipleCB<T> = (paths: string[]) => Awaitable<T>
type MakeAvailableCreateMethod = { method: () => Awaitable<string>, clean: boolean }
-const lTags = loggerTagsFactory('video-path-manager')
-
class VideoPathManager {
private static instance: VideoPathManager
@@ -175,7 +175,7 @@ class VideoPathManager {
const mutex = this.videoFileMutexStore.get(videoUUID)
const releaser = await mutex.acquire()
- logger.debug('Locked files of %s.', videoUUID, lTags(videoUUID))
+ logger.debug('Locked files of %s.', videoUUID)
return releaser
}
@@ -185,7 +185,7 @@ class VideoPathManager {
mutex.release()
- logger.debug('Released lockfiles of %s.', videoUUID, lTags(videoUUID))
+ logger.debug('Released lockfiles of %s.', videoUUID)
}
private async makeAvailableFactory<T> (options: {
diff --git a/server/core/lib/video-playlist.ts b/server/core/lib/video-playlist.ts
index a0ded9bcea..a935612767 100644
--- a/server/core/lib/video-playlist.ts
+++ b/server/core/lib/video-playlist.ts
@@ -1,7 +1,7 @@
import { VideoPlaylistPrivacy, VideoPlaylistType } from '@peertube/peertube-models'
import { retryTransactionWrapper } from '@server/helpers/database-utils.js'
import { generateImageFilename } from '@server/helpers/image-utils.js'
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { CONFIG } from '@server/initializers/config.js'
import { sequelizeTypescript } from '@server/initializers/database.js'
import { SequelizeModel } from '@server/models/shared/sequelize-type.js'
@@ -18,6 +18,8 @@ import { getLocalVideoPlaylistActivityPubUrl } from './activitypub/url.js'
import downloadImage from './image-downloader.js'
import { createLocalPlaylistThumbnailsFromImage } from './thumbnail.js'
+const logger = createLogger()
+
export async function createWatchLaterPlaylist (account: MAccount, t: Transaction) {
const videoPlaylist: MVideoPlaylistOwner = new VideoPlaylistModel({
name: 'Watch later',
diff --git a/server/core/lib/video-pre-import.ts b/server/core/lib/video-pre-import.ts
index 0e3c86c82b..9029bc24d7 100644
--- a/server/core/lib/video-pre-import.ts
+++ b/server/core/lib/video-pre-import.ts
@@ -12,7 +12,7 @@ import { isVTTFileValid } from '@server/helpers/custom-validators/video-captions
import { isVideoFileExtnameValid } from '@server/helpers/custom-validators/videos.js'
import { isResolvingToUnicastOnly } from '@server/helpers/dns.js'
import { guessLanguageFromReq, t } from '@server/helpers/i18n.js'
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { YoutubeDlImportError, YoutubeDlImportErrorCode, YoutubeDLInfo, YoutubeDLWrapper } from '@server/helpers/youtube-dl/index.js'
import { CONFIG } from '@server/initializers/config.js'
import { sequelizeTypescript } from '@server/initializers/database.js'
@@ -20,6 +20,7 @@ import { Hooks } from '@server/lib/plugins/hooks.js'
import { ServerConfigManager } from '@server/lib/server-config-manager.js'
import { autoBlacklistVideoIfNeeded } from '@server/lib/video-blacklist.js'
import { setVideoTags } from '@server/lib/video.js'
+import { getServerAccount } from '@server/models/application/application.js'
import { VideoChannelActivityModel } from '@server/models/video/video-channel-activity.js'
import { VideoImportModel } from '@server/models/video/video-import.js'
import { VideoPasswordModel } from '@server/models/video/video-password.js'
@@ -40,12 +41,13 @@ import {
import express from 'express'
import { remove } from 'fs-extra/esm'
import { getLocalVideoActivityPubUrl } from './activitypub/url.js'
-import { createLocalVideoThumbnailsFromUrl, createLocalVideoThumbnailsFromImage } from './thumbnail.js'
-import { createLocalCaption } from './video-captions.js'
-import { replaceChapters, replaceChaptersFromDescriptionIfNeeded } from './video-chapters.js'
import { AutomaticTagger } from './automatic-tags/automatic-tagger.js'
-import { getServerAccount } from '@server/models/application/application.js'
import { setAndSaveVideoAutomaticTags } from './automatic-tags/automatic-tags.js'
+import { createLocalVideoThumbnailsFromImage, createLocalVideoThumbnailsFromUrl } from './thumbnail.js'
+import { createLocalCaption } from './video-captions.js'
+import { replaceChapters, replaceChaptersFromDescriptionIfNeeded } from './video-chapters.js'
+
+const logger = createLogger()
// ---------------------------------------------------------------------------
@@ -229,88 +231,90 @@ export async function buildYoutubeDLImport (options: {
importType: 'url'
})
- const thumbnails = await processThumbnails({
- inputPath: thumbnailFilePath,
- downloadUrl: youtubeDLInfo.thumbnailUrl,
- video
- })
+ return logger.withContext([ video.uuid ], async () => {
+ const thumbnails = await processThumbnails({
+ inputPath: thumbnailFilePath,
+ downloadUrl: youtubeDLInfo.thumbnailUrl,
+ video
+ })
- const videoImport = await insertFromImportIntoDB({
- video,
- thumbnails,
- videoChannel: channel,
- tags: importDataOverride.tags || youtubeDLInfo.tags,
- user,
- videoImportAttributes: {
- targetUrl,
- state: VideoImportState.PENDING,
- userId: user.id,
- videoChannelSyncId: channelSync?.id
- },
- videoPasswords: importDataOverride.videoPasswords
- })
+ const videoImport = await insertFromImportIntoDB({
+ video,
+ thumbnails,
+ videoChannel: channel,
+ tags: importDataOverride.tags || youtubeDLInfo.tags,
+ user,
+ videoImportAttributes: {
+ targetUrl,
+ state: VideoImportState.PENDING,
+ userId: user.id,
+ videoChannelSyncId: channelSync?.id
+ },
+ videoPasswords: importDataOverride.videoPasswords
+ })
- try {
- await sequelizeTypescript.transaction(async transaction => {
- // Priority to explicitly set description
- if (importDataOverride.description) {
- const inserted = await replaceChaptersFromDescriptionIfNeeded({
- newDescription: importDataOverride.description,
- video,
- transaction
- })
- if (inserted) return
- }
+ try {
+ await sequelizeTypescript.transaction(async transaction => {
+ // Priority to explicitly set description
+ if (importDataOverride.description) {
+ const inserted = await replaceChaptersFromDescriptionIfNeeded({
+ newDescription: importDataOverride.description,
+ video,
+ transaction
+ })
+ if (inserted) return
+ }
+
+ // Then priority to youtube-dl chapters
+ if (youtubeDLInfo.chapters.length !== 0) {
+ logger.info(
+ `Inserting chapters in video ${video.uuid} from youtube-dl`,
+ { chapters: youtubeDLInfo.chapters }
+ )
+
+ await replaceChapters({ video, chapters: youtubeDLInfo.chapters, transaction })
+ return
+ }
+
+ if (video.description) {
+ await replaceChaptersFromDescriptionIfNeeded({ newDescription: video.description, video, transaction })
+ }
+ })
- // Then priority to youtube-dl chapters
- if (youtubeDLInfo.chapters.length !== 0) {
- logger.info(
- `Inserting chapters in video ${video.uuid} from youtube-dl`,
- { chapters: youtubeDLInfo.chapters, tags: [ 'chapters', video.uuid ] }
- )
+ // Get video subtitles
+ await processYoutubeSubtitles({ youtubeDL, targetUrl, video, userLanguage })
- await replaceChapters({ video, chapters: youtubeDLInfo.chapters, transaction })
- return
- }
+ let fileExt = `.${youtubeDLInfo.ext}`
+ if (!isVideoFileExtnameValid(fileExt)) fileExt = '.mp4'
- if (video.description) {
- await replaceChaptersFromDescriptionIfNeeded({ newDescription: video.description, video, transaction })
+ const payload: VideoImportPayload = {
+ type: 'youtube-dl' as 'youtube-dl',
+ videoImportId: videoImport.id,
+ fileExt,
+ generateTranscription: importDataOverride.generateTranscription ?? true,
+ // If part of a sync process, there is a parent job that will aggregate children results
+ preventException: !!channelSync
}
- })
-
- // Get video subtitles
- await processYoutubeSubtitles({ youtubeDL, targetUrl, video, userLanguage })
- let fileExt = `.${youtubeDLInfo.ext}`
- if (!isVideoFileExtnameValid(fileExt)) fileExt = '.mp4'
+ videoImport.payload = payload
+ await videoImport.save()
- const payload: VideoImportPayload = {
- type: 'youtube-dl' as 'youtube-dl',
- videoImportId: videoImport.id,
- fileExt,
- generateTranscription: importDataOverride.generateTranscription ?? true,
- // If part of a sync process, there is a parent job that will aggregate children results
- preventException: !!channelSync
- }
-
- videoImport.payload = payload
- await videoImport.save()
+ return {
+ videoImport,
+ job: { type: 'video-import' as const, payload }
+ }
+ } catch (err) {
+ // Auto destroy video import to not keep a "PENDING" import that never gets a job
+ try {
+ await videoImport.Video.destroy()
+ await videoImport.destroy()
+ } catch (cleanupErr) {
+ logger.error(`Cannot cleanup video import for ${targetUrl} after a build error.`, { err: cleanupErr })
+ }
- return {
- videoImport,
- job: { type: 'video-import' as 'video-import', payload }
- }
- } catch (err) {
- // Auto destroy video import to not keep a "PENDING" import that never gets a job
- try {
- await videoImport.Video.destroy()
- await videoImport.destroy()
- } catch (cleanupErr) {
- logger.error(`Cannot cleanup video import for ${targetUrl} after a build error.`, { err: cleanupErr })
+ throw err
}
-
- throw err
- }
+ })
}
// ---------------------------------------------------------------------------
diff --git a/server/core/lib/video-privacy.ts b/server/core/lib/video-privacy.ts
index 4c3d148626..1b2fc70d6a 100644
--- a/server/core/lib/video-privacy.ts
+++ b/server/core/lib/video-privacy.ts
@@ -1,12 +1,12 @@
import { FileStorage, VideoPrivacy, VideoPrivacyType } from '@peertube/peertube-models'
-import { logger, loggerTagsFactory } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { DIRECTORIES } from '@server/initializers/constants.js'
import { MVideo, MVideoFile, MVideoFull } from '@server/types/models/index.js'
import { move } from 'fs-extra/esm'
import { join } from 'path'
import { updateHLSFilesACL, updateWebVideoFileACL } from './object-storage/index.js'
-const lTags = loggerTagsFactory('video-privacy')
+const logger = createLogger('video-privacy')
const validPrivacySet = new Set<VideoPrivacyType>([
VideoPrivacy.PRIVATE,
@@ -80,7 +80,7 @@ async function moveFiles (options: {
try {
await updateWebVideoFileACL(video, file)
} catch (err) {
- logger.error(objectStorageErrorMsg, { err, ...lTags('object-storage', video.uuid) })
+ logger.error(objectStorageErrorMsg, { err })
}
}
}
@@ -94,7 +94,7 @@ async function moveFiles (options: {
try {
await updateHLSFilesACL(video)
} catch (err) {
- logger.error(objectStorageErrorMsg, { err, ...lTags('object-storage', video.uuid) })
+ logger.error(objectStorageErrorMsg, { err })
}
}
}
diff --git a/server/core/lib/video-state.ts b/server/core/lib/video-state.ts
index b6d7d2ac7c..d061189e85 100644
--- a/server/core/lib/video-state.ts
+++ b/server/core/lib/video-state.ts
@@ -1,6 +1,6 @@
import { VideoState, VideoStateType } from '@peertube/peertube-models'
import { retryTransactionWrapper } from '@server/helpers/database-utils.js'
-import { logger, loggerTagsFactory } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { CONFIG } from '@server/initializers/config.js'
import { sequelizeTypescript } from '@server/initializers/database.js'
import { VideoModel } from '@server/models/video/video.js'
@@ -11,7 +11,7 @@ import { JobQueue } from './job-queue/index.js'
import { Notifier } from './notifier/index.js'
import { buildMoveVideoJob } from './video-jobs.js'
-const lTags = loggerTagsFactory('video-state')
+const logger = createLogger('video-state')
export function buildNextVideoState (currentState?: VideoStateType) {
if (currentState === VideoState.PUBLISHED) {
@@ -56,7 +56,7 @@ export function moveToNextState (options: {
if (videoDatabase.state === VideoState.PUBLISHED) {
scheduleVideoFederation({ video: videoDatabase, transaction: t })
- logger.debug(`Video ${videoDatabase.uuid} is already published, no state change.`, lTags(videoDatabase.uuid))
+ logger.debug(`Video ${videoDatabase.uuid} is already published, no state change.`)
return false
}
@@ -102,7 +102,7 @@ export async function moveToExternalStorageState (options: {
await video.setNewStateAndPublishedAt({ newState: VideoState.TO_MOVE_TO_EXTERNAL_STORAGE, transaction })
}
- logger.info('Creating external storage move job for video %s.', video.uuid, lTags(video.uuid))
+ logger.info('Creating external storage move job for video %s.', video.uuid)
try {
await JobQueue.Instance.createJob(
@@ -115,7 +115,7 @@ export async function moveToExternalStorageState (options: {
return true
} catch (err) {
- logger.error('Cannot add move to object storage job', { err, ...lTags(video.uuid) })
+ logger.error('Cannot add move to object storage job', { err })
return false
}
@@ -133,7 +133,7 @@ export async function moveToFileSystemState (options: {
await video.setNewStateAndPublishedAt({ newState: VideoState.TO_MOVE_TO_FILE_SYSTEM, transaction })
}
- logger.info('Creating move to file system job for video %s.', video.uuid, { tags: [ video.uuid ] })
+ logger.info('Creating move to file system job for video %s.', video.uuid)
try {
await JobQueue.Instance.createJob(
@@ -146,7 +146,7 @@ export async function moveToFileSystemState (options: {
return true
} catch (err) {
- logger.error('Cannot add move to file system job', { err, ...lTags(video.uuid) })
+ logger.error('Cannot add move to file system job', { err })
return false
}
@@ -184,7 +184,7 @@ async function moveToPublishedState (options: {
const { video, transaction, previousVideoState } = options
const previousState = previousVideoState ?? video.state
- logger.info('Publishing video %s.', video.uuid, { previousState, ...lTags(video.uuid) })
+ logger.info('Publishing video %s.', video.uuid, { previousState })
const isNewVideo = !video.firstPublishedAt
diff --git a/server/core/lib/video-studio.ts b/server/core/lib/video-studio.ts
index 80287ed352..da39b60c59 100644
--- a/server/core/lib/video-studio.ts
+++ b/server/core/lib/video-studio.ts
@@ -1,7 +1,7 @@
import { buildAspectRatio } from '@peertube/peertube-core-utils'
import { getVideoStreamDuration } from '@peertube/peertube-ffmpeg'
import { VideoStudioEditionPayload, VideoStudioTask, VideoStudioTaskPayload } from '@peertube/peertube-models'
-import { logger, loggerTagsFactory } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { CONFIG } from '@server/initializers/config.js'
import { sequelizeTypescript } from '@server/initializers/database.js'
import { buildNonDuplicatedFederateVideoJob } from '@server/lib/activitypub/videos/federate.js'
@@ -19,7 +19,7 @@ import { buildNewFile, removeHLSPlaylist, removeWebVideoFile } from './video-fil
import { addRemoteStoryboardJobIfNeeded, buildLocalStoryboardJobIfNeeded } from './video-jobs.js'
import { VideoPathManager } from './video-path-manager.js'
-const lTags = loggerTagsFactory('video-studio')
+const logger = createLogger('studio')
export function buildTaskFileFieldname (indice: number, fieldName = 'file') {
return `tasks[${indice}][options][${fieldName}]`
@@ -34,7 +34,7 @@ export function getStudioTaskFilePath (filename: string) {
}
export async function safeCleanupStudioTMPFiles (tasks: VideoStudioTaskPayload[]) {
- logger.info('Removing TMP studio task files', { tasks, ...lTags() })
+ logger.info('Removing TMP studio task files', { tasks })
for (const task of tasks) {
try {
diff --git a/server/core/lib/webtorrent.ts b/server/core/lib/webtorrent.ts
index 3d5b8fede2..5c8ee96d84 100644
--- a/server/core/lib/webtorrent.ts
+++ b/server/core/lib/webtorrent.ts
@@ -16,11 +16,13 @@ import parseTorrent from 'parse-torrent'
import { dirname, join } from 'path'
import { pipeline } from 'stream'
import type { Instance, TorrentFile } from 'webtorrent'
-import { logger } from '../helpers/logger.js'
+import { createLogger } from '../helpers/logger.js'
import { generateVideoImportTmpPath } from '../helpers/utils.js'
import { extractVideo } from '../helpers/video.js'
import { CONFIG } from '../initializers/config.js'
+const logger = createLogger()
+
export async function downloadWebTorrentVideo (target: { uri: string, torrentPath: string | null }, timeout: number) {
const torrentId = target.uri || target.torrentPath
let timer
diff --git a/server/core/lib/worker/parent-process.ts b/server/core/lib/worker/parent-process.ts
index cdbf28089d..fc6bf40be9 100644
--- a/server/core/lib/worker/parent-process.ts
+++ b/server/core/lib/worker/parent-process.ts
@@ -1,4 +1,4 @@
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { JOB_CONCURRENCY, WORKER_THREADS } from '@server/initializers/constants.js'
import { join } from 'path'
import { Piscina } from 'piscina'
@@ -8,6 +8,8 @@ import type httpBroadcast from './workers/http-broadcast.js'
import type httpUnicast from './workers/http-unicast.js'
import type signJsonLDObject from './workers/sign-json-ld-object.js'
+const logger = createLogger()
+
// ---------------------------------------------------------------------------
let parallelHTTPBroadcastWorker: Piscina
diff --git a/server/core/lib/worker/workers/http-broadcast.ts b/server/core/lib/worker/workers/http-broadcast.ts
index 29895a00ae..e87787568c 100644
--- a/server/core/lib/worker/workers/http-broadcast.ts
+++ b/server/core/lib/worker/workers/http-broadcast.ts
@@ -1,8 +1,10 @@
import Bluebird from 'bluebird'
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { doRequest, PeerTubeRequestOptions } from '@server/helpers/requests.js'
import { BROADCAST_CONCURRENCY } from '@server/initializers/constants.js'
+const logger = createLogger()
+
async function httpBroadcast (payload: {
uris: string[]
requestOptions: PeerTubeRequestOptions
diff --git a/server/core/middlewares/activitypub.ts b/server/core/middlewares/activitypub.ts
index 8df6076b2d..1f1bf7b1ae 100644
--- a/server/core/middlewares/activitypub.ts
+++ b/server/core/middlewares/activitypub.ts
@@ -5,10 +5,12 @@ import { isHTTPSignatureVerified, parseHTTPSignature } from '@server/helpers/pee
import { getAPId } from '@server/lib/activitypub/activity.js'
import { wrapWithSpanAndContext } from '@server/lib/opentelemetry/tracing.js'
import { NextFunction, Request, Response } from 'express'
-import { logger } from '../helpers/logger.js'
+import { createLogger } from '../helpers/logger.js'
import { ACCEPT_HEADERS, ACTIVITY_PUB, HTTP_SIGNATURE } from '../initializers/constants.js'
import { getOrCreateAPActor, loadActorUrlOrGetFromWebfinger } from '../lib/activitypub/actors/index.js'
+const logger = createLogger()
+
export async function checkSignature (req: Request, res: Response, next: NextFunction) {
try {
const httpSignatureChecked = await checkHttpSignature(req, res)
diff --git a/server/core/middlewares/auth.ts b/server/core/middlewares/auth.ts
index d519af0c14..bc9c9e6099 100644
--- a/server/core/middlewares/auth.ts
+++ b/server/core/middlewares/auth.ts
@@ -4,9 +4,11 @@ import { UpdateTokenSessionScheduler } from '@server/lib/schedulers/update-token
import { RunnerModel } from '@server/models/runner/runner.js'
import express from 'express'
import { Socket } from 'socket.io'
-import { logger } from '../helpers/logger.js'
+import { addLoggerContextTags, createLogger } from '../helpers/logger.js'
import { handleOAuthAuthenticate } from '../lib/auth/oauth-handlers.js'
+const logger = createLogger()
+
export function authenticate (req: express.Request, res: express.Response, next: express.NextFunction) {
handleOAuthAuthenticate(req, res)
.then((token: any) => {
@@ -19,6 +21,9 @@ export function authenticate (req: express.Request, res: express.Response, next:
lastActivityDevice: req.header('user-agent')
})
+ // A global middleware create the context
+ addLoggerContextTags(token.User.username)
+
return next()
})
.catch(err => {
diff --git a/server/core/middlewares/cache/shared/api-cache.ts b/server/core/middlewares/cache/shared/api-cache.ts
index 5edca0512e..2e1b26d413 100644
--- a/server/core/middlewares/cache/shared/api-cache.ts
+++ b/server/core/middlewares/cache/shared/api-cache.ts
@@ -1,14 +1,16 @@
// Thanks: https://github.com/kwhitley/apicache
// We duplicated the library because it is unmaintened and prevent us to upgrade to recent NodeJS versions
-import express from 'express'
-import { OutgoingHttpHeaders } from 'http'
import { HttpStatusCodeType } from '@peertube/peertube-models'
import { isTestInstance } from '@peertube/peertube-node-utils'
import { parseDurationToMs } from '@server/helpers/core-utils.js'
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { Redis } from '@server/lib/redis.js'
import { asyncMiddleware } from '@server/middlewares/index.js'
+import express from 'express'
+import { OutgoingHttpHeaders } from 'http'
+
+const logger = createLogger()
export interface APICacheOptions {
headerBlacklist?: string[]
@@ -248,6 +250,8 @@ export class ApiCache {
}
Object.assign(headers, this.filterBlacklistedHeaders(cacheObject.headers || {}), {
+ 'x-request-id': response.getHeader('x-request-id'),
+
// Set properly decremented max-age header
// This ensures that max-age is in sync with the cache expiration
'cache-control': 'max-age=' +
diff --git a/server/core/middlewares/error.ts b/server/core/middlewares/error.ts
index 902a2d4dc0..f7c3e32880 100644
--- a/server/core/middlewares/error.ts
+++ b/server/core/middlewares/error.ts
@@ -1,8 +1,10 @@
import { HttpStatusCode } from '@peertube/peertube-models'
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import express from 'express'
import { ProblemDocument, ProblemDocumentExtension } from 'http-problem-details'
+const logger = createLogger()
+
function apiFailMiddleware (req: express.Request, res: express.Response, next: express.NextFunction) {
res.fail = options => {
const { status = HttpStatusCode.BAD_REQUEST_400, message, title, type, data, instance, tags, logLevel = 'debug' } = options
diff --git a/server/core/middlewares/index.ts b/server/core/middlewares/index.ts
index c554a33dac..8a9d3305b6 100644
--- a/server/core/middlewares/index.ts
+++ b/server/core/middlewares/index.ts
@@ -12,3 +12,4 @@ export * from './dnt.js'
export * from './error.js'
export * from './doc.js'
export * from './csp.js'
+export * from './logger-context.js'
diff --git a/server/core/middlewares/logger-context.ts b/server/core/middlewares/logger-context.ts
new file mode 100644
index 0000000000..8691df78c1
--- /dev/null
+++ b/server/core/middlewares/logger-context.ts
@@ -0,0 +1,13 @@
+import { buildSUUID } from '@peertube/peertube-node-utils'
+import express from 'express'
+import { inLoggerContext } from '../helpers/logger.js'
+
+// Tag every logger call happening while handling this request (including in async code) with a request id,
+// so related log lines can be grepped/correlated together
+export function requestLoggerContext (_req: express.Request, res: express.Response, next: express.NextFunction) {
+ const requestId = buildSUUID()
+
+ res.setHeader('X-Request-Id', requestId)
+
+ inLoggerContext([ 'req', requestId ], () => next())
+}
diff --git a/server/core/middlewares/rate-limiter.ts b/server/core/middlewares/rate-limiter.ts
index e539608f78..6838719c29 100644
--- a/server/core/middlewares/rate-limiter.ts
+++ b/server/core/middlewares/rate-limiter.ts
@@ -1,13 +1,13 @@
import { UserRole, UserRoleType } from '@peertube/peertube-models'
import { getAuthUser } from '@server/helpers/express-utils.js'
-import { logger, loggerTagsFactory } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { CONFIG } from '@server/initializers/config.js'
import { RunnerModel } from '@server/models/runner/runner.js'
import express from 'express'
import RateLimit, { ipKeyGenerator, Options as RateLimitHandlerOptions } from 'express-rate-limit'
import { optionalAuthenticate } from './auth.js'
-const lTags = loggerTagsFactory('rate-limit')
+const logger = createLogger('rate-limit')
const whitelistRoles = new Set<UserRoleType>([ UserRole.ADMINISTRATOR, UserRole.MODERATOR ])
@@ -78,7 +78,7 @@ export const activityPubRateLimiter = buildRateLimiter({
// ---------------------------------------------------------------------------
function sendRateLimited (req: express.Request, res: express.Response, options: RateLimitHandlerOptions) {
- logger.debug('Rate limit exceeded for route ' + req.originalUrl, { route: req.originalUrl, ip: req.ip, ...lTags() })
+ logger.debug('Rate limit exceeded for route ' + req.originalUrl, { route: req.originalUrl, ip: req.ip })
return res.status(options.statusCode).send(options.message)
}
diff --git a/server/core/middlewares/user-right.ts b/server/core/middlewares/user-right.ts
index dc554d4d37..8cf1bb4900 100644
--- a/server/core/middlewares/user-right.ts
+++ b/server/core/middlewares/user-right.ts
@@ -1,6 +1,8 @@
import express from 'express'
import { HttpStatusCode, UserRightType } from '@peertube/peertube-models'
-import { logger } from '../helpers/logger.js'
+import { createLogger } from '../helpers/logger.js'
+
+const logger = createLogger()
export function ensureUserHasRight (userRight: UserRightType) {
return function (req: express.Request, res: express.Response, next: express.NextFunction) {
diff --git a/server/core/middlewares/validators/abuse.ts b/server/core/middlewares/validators/abuse.ts
index a3b188d4cf..f43041c08b 100644
--- a/server/core/middlewares/validators/abuse.ts
+++ b/server/core/middlewares/validators/abuse.ts
@@ -15,10 +15,12 @@ import {
isAbuseVideoIsValid
} from '@server/helpers/custom-validators/abuses.js'
import { exists, isIdOrUUIDValid, isIdValid, toCompleteUUID, toIntOrNull } from '@server/helpers/custom-validators/misc.js'
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { AbuseMessageModel } from '@server/models/abuse/abuse-message.js'
import { areValidationErrors, doesAbuseExist, doesAccountIdExist, doesCommentIdExist, doesVideoExist } from './shared/index.js'
+const logger = createLogger()
+
const abuseReportValidator = [
body('account.id')
.optional()
diff --git a/server/core/middlewares/validators/activitypub/activity.ts b/server/core/middlewares/validators/activitypub/activity.ts
index 46349d62a4..6bacf249ae 100644
--- a/server/core/middlewares/validators/activitypub/activity.ts
+++ b/server/core/middlewares/validators/activitypub/activity.ts
@@ -3,7 +3,9 @@ import { HttpStatusCode } from '@peertube/peertube-models'
import { isLocalUrl } from '@server/lib/activitypub/url.js'
import { getServerActor } from '@server/models/application/application.js'
import { isRootActivityValid } from '../../../helpers/custom-validators/activitypub/activity.js'
-import { logger } from '../../../helpers/logger.js'
+import { createLogger } from '../../../helpers/logger.js'
+
+const logger = createLogger()
async function activityPubValidator (req: express.Request, res: express.Response, next: express.NextFunction) {
logger.debug('Checking activity pub parameters')
diff --git a/server/core/middlewares/validators/activitypub/signature.ts b/server/core/middlewares/validators/activitypub/signature.ts
index a318c9463b..440ec9939b 100644
--- a/server/core/middlewares/validators/activitypub/signature.ts
+++ b/server/core/middlewares/validators/activitypub/signature.ts
@@ -6,9 +6,11 @@ import {
isSignatureValueValid
} from '../../../helpers/custom-validators/activitypub/signature.js'
import { isDateValid } from '../../../helpers/custom-validators/misc.js'
-import { logger } from '../../../helpers/logger.js'
+import { createLogger } from '../../../helpers/logger.js'
import { areValidationErrors } from '../shared/index.js'
+const logger = createLogger()
+
const signatureValidator = [
body('signature.type')
.optional()
diff --git a/server/core/middlewares/validators/follows.ts b/server/core/middlewares/validators/follows.ts
index ed3efc58df..b8ceeaac97 100644
--- a/server/core/middlewares/validators/follows.ts
+++ b/server/core/middlewares/validators/follows.ts
@@ -10,12 +10,14 @@ import express from 'express'
import { body, param, query } from 'express-validator'
import { isActorTypeValid, isValidActorHandle } from '../../helpers/custom-validators/activitypub/actor.js'
import { isEachUniqueHostValid, isHostValid } from '../../helpers/custom-validators/servers.js'
-import { logger } from '../../helpers/logger.js'
+import { createLogger } from '../../helpers/logger.js'
import { WEBSERVER } from '../../initializers/constants.js'
import { ActorFollowModel } from '../../models/actor/actor-follow.js'
import { ActorModel } from '../../models/actor/actor.js'
import { areValidationErrors } from './shared/index.js'
+const logger = createLogger()
+
const listFollowsValidator = [
query('state')
.optional()
diff --git a/server/core/middlewares/validators/jobs.ts b/server/core/middlewares/validators/jobs.ts
index 53d34c8781..0ea49612aa 100644
--- a/server/core/middlewares/validators/jobs.ts
+++ b/server/core/middlewares/validators/jobs.ts
@@ -2,11 +2,10 @@ import { HttpStatusCode, JobType } from '@peertube/peertube-models'
import express from 'express'
import { param, query } from 'express-validator'
import { isValidJobState, isValidJobType } from '../../helpers/custom-validators/jobs.js'
-import { loggerTagsFactory } from '../../helpers/logger.js'
import { JobQueue } from '../../lib/job-queue/index.js'
import { areValidationErrors } from './shared/index.js'
-const lTags = loggerTagsFactory('validators', 'jobs')
+const tags = [ 'validators', 'jobs' ]
export const listJobsValidator = [
param('state')
@@ -18,7 +17,7 @@ export const listJobsValidator = [
.custom(isValidJobType),
(req: express.Request, res: express.Response, next: express.NextFunction) => {
- if (areValidationErrors(req, res, lTags())) return
+ if (areValidationErrors(req, res, { tags })) return
return next()
}
@@ -29,7 +28,7 @@ export const cancelJobValidator = [
param('jobId').isString().not().isEmpty(),
async (req: express.Request, res: express.Response, next: express.NextFunction) => {
- if (areValidationErrors(req, res, lTags())) return
+ if (areValidationErrors(req, res, { tags })) return
const jobType = req.params.jobType as JobType
const jobId = req.params.jobId
diff --git a/server/core/middlewares/validators/resumable-upload.ts b/server/core/middlewares/validators/resumable-upload.ts
index 43386931cb..857ad84bf9 100644
--- a/server/core/middlewares/validators/resumable-upload.ts
+++ b/server/core/middlewares/validators/resumable-upload.ts
@@ -1,9 +1,11 @@
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import express from 'express'
import { body, header } from 'express-validator'
import { areValidationErrors } from './shared/utils.js'
import { cleanUpReqFiles } from '@server/helpers/express-utils.js'
+const logger = createLogger()
+
export const resumableInitValidator = [
body('filename')
.exists(),
diff --git a/server/core/middlewares/validators/server.ts b/server/core/middlewares/validators/server.ts
index b8d7a8aa40..fbaaf2b274 100644
--- a/server/core/middlewares/validators/server.ts
+++ b/server/core/middlewares/validators/server.ts
@@ -3,12 +3,14 @@ import { body } from 'express-validator'
import { HttpStatusCode } from '@peertube/peertube-models'
import { isHostValid, isValidContactBody } from '../../helpers/custom-validators/servers.js'
import { isUserDisplayNameValid } from '../../helpers/custom-validators/users.js'
-import { logger } from '../../helpers/logger.js'
+import { createLogger } from '../../helpers/logger.js'
import { CONFIG, isEmailEnabled } from '../../initializers/config.js'
import { Redis } from '../../lib/redis.js'
import { ServerModel } from '../../models/server/server.js'
import { areValidationErrors } from './shared/index.js'
+const logger = createLogger()
+
const serverGetValidator = [
body('host').custom(isHostValid).withMessage('Should have a valid host'),
diff --git a/server/core/middlewares/validators/shared/utils.ts b/server/core/middlewares/validators/shared/utils.ts
index 7e0619cdb9..5d438b3396 100644
--- a/server/core/middlewares/validators/shared/utils.ts
+++ b/server/core/middlewares/validators/shared/utils.ts
@@ -1,7 +1,9 @@
+import { isIdOrUUIDValid, toCompleteUUID } from '@server/helpers/custom-validators/misc.js'
import express from 'express'
import { param, validationResult } from 'express-validator'
-import { isIdOrUUIDValid, toCompleteUUID } from '@server/helpers/custom-validators/misc.js'
-import { logger } from '../../../helpers/logger.js'
+import { createLogger } from '../../../helpers/logger.js'
+
+const logger = createLogger()
function areValidationErrors (
req: express.Request,
@@ -10,13 +12,15 @@ function areValidationErrors (
omitLog?: boolean
omitBodyLog?: boolean
tags?: (number | string)[]
- } = {}) {
+ } = {}
+) {
const { omitLog = false, omitBodyLog = false, tags = [] } = options
if (!omitLog) {
logger.debug(
'Checking %s - %s parameters',
- req.method, req.originalUrl,
+ req.method,
+ req.originalUrl,
{
body: omitBodyLog
? 'omitted'
@@ -64,6 +68,6 @@ function isValidPlaylistIdParam (paramName: string) {
export {
areValidationErrors,
- isValidVideoIdParam,
- isValidPlaylistIdParam
+ isValidPlaylistIdParam,
+ isValidVideoIdParam
}
diff --git a/server/core/middlewares/validators/static.ts b/server/core/middlewares/validators/static.ts
index 5dfb6b5b56..1751a263db 100644
--- a/server/core/middlewares/validators/static.ts
+++ b/server/core/middlewares/validators/static.ts
@@ -6,7 +6,7 @@ import {
isUUIDValid,
toBooleanOrNull
} from '@server/helpers/custom-validators/misc.js'
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { LRU_CACHE } from '@server/initializers/constants.js'
import { VideoFileModel } from '@server/models/video/video-file.js'
import { VideoModel } from '@server/models/video/video.js'
@@ -17,6 +17,8 @@ import { LRUCache } from 'lru-cache'
import { basename } from 'path'
import { areValidationErrors, checkCanAccessVideoStaticFiles, isValidVideoPasswordHeader } from './shared/index.js'
+const logger = createLogger()
+
type LRUValue = {
allowed: boolean
video?: MVideoWithBlacklist
diff --git a/server/core/middlewares/validators/users/user-email-verification.ts b/server/core/middlewares/validators/users/user-email-verification.ts
index af25768178..032eff5c51 100644
--- a/server/core/middlewares/validators/users/user-email-verification.ts
+++ b/server/core/middlewares/validators/users/user-email-verification.ts
@@ -6,11 +6,13 @@ import { UserModel } from '@server/models/user/user.js'
import express from 'express'
import { body, param } from 'express-validator'
import { isSecretEqual } from '../../../helpers/peertube-crypto.js'
-import { logger } from '../../../helpers/logger.js'
+import { createLogger } from '../../../helpers/logger.js'
import { Redis } from '../../../lib/redis.js'
import { areValidationErrors, checkUserIdExist } from '../shared/index.js'
import { checkRegistrationEmailExistPermissive, checkRegistrationIdExist } from './shared/user-registrations.js'
+const logger = createLogger()
+
export const usersAskSendUserVerifyEmailValidator = [
body('email').isEmail().not().isEmpty().withMessage('Should have a valid email'),
diff --git a/server/core/middlewares/validators/users/users.ts b/server/core/middlewares/validators/users/users.ts
index 4447d25787..de30ebba48 100644
--- a/server/core/middlewares/validators/users/users.ts
+++ b/server/core/middlewares/validators/users/users.ts
@@ -31,7 +31,7 @@ import {
isUserVideosHistoryEnabledValid
} from '../../../helpers/custom-validators/users.js'
import { isVideoChannelUsernameValid } from '../../../helpers/custom-validators/video-channels.js'
-import { logger } from '../../../helpers/logger.js'
+import { createLogger } from '../../../helpers/logger.js'
import { isSecretEqual } from '../../../helpers/peertube-crypto.js'
import { isThemeRegistered } from '../../../lib/plugins/theme-utils.js'
import { Redis } from '../../../lib/redis.js'
@@ -46,6 +46,8 @@ import {
isValidVideoIdParam
} from '../shared/index.js'
+const logger = createLogger()
+
export const usersListValidator = [
query('blocked')
.optional()
diff --git a/server/core/middlewares/validators/videos/shared/upload.ts b/server/core/middlewares/validators/videos/shared/upload.ts
index e94c354de0..d8f49ce2d3 100644
--- a/server/core/middlewares/validators/videos/shared/upload.ts
+++ b/server/core/middlewares/validators/videos/shared/upload.ts
@@ -1,8 +1,10 @@
import express from 'express'
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { ffprobePromise, getVideoStreamDuration } from '@peertube/peertube-ffmpeg'
import { HttpStatusCode } from '@peertube/peertube-models'
+const logger = createLogger()
+
export async function addDurationToVideoFileIfNeeded (options: {
res: express.Response
videoFile: { path: string, duration?: number }
diff --git a/server/core/middlewares/validators/videos/shared/video-validators.ts b/server/core/middlewares/validators/videos/shared/video-validators.ts
index 05f857c258..6271f575c4 100644
--- a/server/core/middlewares/validators/videos/shared/video-validators.ts
+++ b/server/core/middlewares/validators/videos/shared/video-validators.ts
@@ -1,7 +1,7 @@
import { canVideoFileBeEdited } from '@peertube/peertube-core-utils'
import { HttpStatusCode, ServerErrorCode, ServerFilterHookName, VideoState, VideoStateType } from '@peertube/peertube-models'
import { isVideoFileMimeTypeValid, isVideoFileSizeValid } from '@server/helpers/custom-validators/videos.js'
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { CONSTRAINTS_FIELDS, VIDEO_STATES } from '@server/initializers/constants.js'
import { isLocalVideoFileAccepted } from '@server/lib/moderation.js'
import { Hooks } from '@server/lib/plugins/hooks.js'
@@ -9,6 +9,8 @@ import { MUserId, MVideo } from '@server/types/models/index.js'
import express from 'express'
import { checkUserQuota } from '../../shared/index.js'
+const logger = createLogger()
+
export async function commonVideoFileChecks (options: {
req: express.Request
res: express.Response
diff --git a/server/core/middlewares/validators/videos/video-comments.ts b/server/core/middlewares/validators/videos/video-comments.ts
index b15ae853ae..c8f65a8f3c 100644
--- a/server/core/middlewares/validators/videos/video-comments.ts
+++ b/server/core/middlewares/validators/videos/video-comments.ts
@@ -16,7 +16,7 @@ import {
toIntOrNull
} from '../../../helpers/custom-validators/misc.js'
import { isValidVideoCommentText } from '../../../helpers/custom-validators/video-comments.js'
-import { logger } from '../../../helpers/logger.js'
+import { createLogger } from '../../../helpers/logger.js'
import { AcceptResult, isLocalVideoCommentReplyAccepted, isLocalVideoThreadAccepted } from '../../../lib/moderation.js'
import { Hooks } from '../../../lib/plugins/hooks.js'
import { MCommentOwnerVideoReply, MVideo, MVideoAccountLight } from '../../../types/models/video/index.js'
@@ -33,6 +33,8 @@ import {
isValidVideoPasswordHeader
} from '../shared/index.js'
+const logger = createLogger()
+
export const listAllVideoCommentsForAdminValidator = [
...getCommonVideoCommentsValidators(),
diff --git a/server/core/middlewares/validators/videos/video-imports.ts b/server/core/middlewares/validators/videos/video-imports.ts
index cc8b367ecd..3c99c4d2f6 100644
--- a/server/core/middlewares/validators/videos/video-imports.ts
+++ b/server/core/middlewares/validators/videos/video-imports.ts
@@ -10,12 +10,14 @@ import { isIdValid, toBooleanOrNull, toIntOrNull } from '../../../helpers/custom
import { isVideoImportTargetUrlValid, isVideoImportTorrentFile } from '../../../helpers/custom-validators/video-imports.js'
import { isValidPasswordProtectedPrivacy, isVideoMagnetUriValid, isVideoNameValid } from '../../../helpers/custom-validators/videos.js'
import { cleanUpReqFiles } from '../../../helpers/express-utils.js'
-import { logger } from '../../../helpers/logger.js'
+import { createLogger } from '../../../helpers/logger.js'
import { CONFIG } from '../../../initializers/config.js'
import { CONSTRAINTS_FIELDS } from '../../../initializers/constants.js'
import { areValidationErrors, checkCanManageVideo, doesChannelIdExist, doesVideoImportExist } from '../shared/index.js'
import { areErrorsInNSFW, getCommonVideoEditAttributes } from './videos.js'
+const logger = createLogger()
+
export const videoImportAddValidator = getCommonVideoEditAttributes().concat([
body('channelId')
.customSanitizer(toIntOrNull)
diff --git a/server/core/middlewares/validators/videos/video-live.ts b/server/core/middlewares/validators/videos/video-live.ts
index 83eb02e287..6410b035d3 100644
--- a/server/core/middlewares/validators/videos/video-live.ts
+++ b/server/core/middlewares/validators/videos/video-live.ts
@@ -21,7 +21,7 @@ import { body } from 'express-validator'
import { exists, isBooleanValid, isIdValid, toBooleanOrNull, toIntOrNull } from '../../../helpers/custom-validators/misc.js'
import { isValidPasswordProtectedPrivacy, isVideoNameValid, isVideoReplayPrivacyValid } from '../../../helpers/custom-validators/videos.js'
import { cleanUpReqFiles } from '../../../helpers/express-utils.js'
-import { logger } from '../../../helpers/logger.js'
+import { createLogger } from '../../../helpers/logger.js'
import { CONFIG } from '../../../initializers/config.js'
import {
areValidationErrors,
@@ -33,6 +33,8 @@ import {
} from '../shared/index.js'
import { areErrorsInNSFW, getCommonVideoEditAttributes } from './videos.js'
+const logger = createLogger()
+
export const videoLiveGetValidatorFactory = (loadType: Extract<VideoLoadType, 'with-rights' | 'full'>) => {
return [
isValidVideoIdParam('videoId'),
diff --git a/server/core/middlewares/validators/videos/video-view.ts b/server/core/middlewares/validators/videos/video-view.ts
index 77637108a5..c7b9b155bc 100644
--- a/server/core/middlewares/validators/videos/video-view.ts
+++ b/server/core/middlewares/validators/videos/video-view.ts
@@ -11,7 +11,9 @@ import express from 'express'
import { body, param } from 'express-validator'
import { isIdValid, toIntOrNull } from '../../../helpers/custom-validators/misc.js'
import { areValidationErrors, doesVideoExist, isValidVideoIdParam } from '../shared/index.js'
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
+
+const logger = createLogger()
const tags = [ 'views' ]
diff --git a/server/core/middlewares/validators/videos/videos.ts b/server/core/middlewares/validators/videos/videos.ts
index 192ed014e2..06bfe298f9 100644
--- a/server/core/middlewares/validators/videos/videos.ts
+++ b/server/core/middlewares/validators/videos/videos.ts
@@ -50,7 +50,7 @@ import {
isVideoSupportValid
} from '../../../helpers/custom-validators/videos.js'
import { cleanUpReqFiles } from '../../../helpers/express-utils.js'
-import { logger } from '../../../helpers/logger.js'
+import { createLogger } from '../../../helpers/logger.js'
import { getVideoWithAttributes } from '../../../helpers/video.js'
import { CONFIG } from '../../../initializers/config.js'
import { CONSTRAINTS_FIELDS, OVERVIEWS } from '../../../initializers/constants.js'
@@ -69,6 +69,8 @@ import {
} from '../shared/index.js'
import { addDurationToVideoFileIfNeeded, commonVideoFileChecks, isVideoFileAccepted } from './shared/index.js'
+const logger = createLogger()
+
const getVideoUploadCommonValidator = () => [
body('name')
.trim()
diff --git a/server/core/models/actor/actor-follow.ts b/server/core/models/actor/actor-follow.ts
index 06933052eb..3eb6a01927 100644
--- a/server/core/models/actor/actor-follow.ts
+++ b/server/core/models/actor/actor-follow.ts
@@ -31,7 +31,7 @@ import {
Table,
UpdatedAt
} from 'sequelize-typescript'
-import { logger } from '../../helpers/logger.js'
+import { createLogger } from '../../helpers/logger.js'
import {
ACTOR_FOLLOW_SCORE,
CONSTRAINTS_FIELDS,
@@ -49,6 +49,8 @@ import { ActorModel, unusedActorAttributesForAPI } from './actor.js'
import { InstanceListFollowersQueryBuilder, ListFollowersOptions } from './sql/instance-list-followers-query-builder.js'
import { InstanceListFollowingQueryBuilder, ListFollowingOptions } from './sql/instance-list-following-query-builder.js'
+const logger = createLogger()
+
@Table({
tableName: 'actorFollow',
indexes: [
diff --git a/server/core/models/actor/actor-image.ts b/server/core/models/actor/actor-image.ts
index e70cc78855..43ec497dee 100644
--- a/server/core/models/actor/actor-image.ts
+++ b/server/core/models/actor/actor-image.ts
@@ -5,12 +5,14 @@ import { remove } from 'fs-extra/esm'
import { join } from 'path'
import { Op, Transaction } from 'sequelize'
import { AfterDestroy, AllowNull, BelongsTo, Column, CreatedAt, Default, ForeignKey, Table, UpdatedAt } from 'sequelize-typescript'
-import { logger } from '../../helpers/logger.js'
+import { createLogger } from '../../helpers/logger.js'
import { CONFIG } from '../../initializers/config.js'
import { FILES_CACHE, LAZY_STATIC_PATHS, MIMETYPES, WEBSERVER } from '../../initializers/constants.js'
import { SequelizeModel, buildSQLAttributes } from '../shared/index.js'
import { ActorModel } from './actor.js'
+const logger = createLogger()
+
@Table({
tableName: 'actorImage',
indexes: [
diff --git a/server/core/models/application/upload-image.ts b/server/core/models/application/upload-image.ts
index d91e22c12e..03a44c07f5 100644
--- a/server/core/models/application/upload-image.ts
+++ b/server/core/models/application/upload-image.ts
@@ -15,11 +15,13 @@ import {
Table,
UpdatedAt
} from 'sequelize-typescript'
-import { logger } from '../../helpers/logger.js'
+import { createLogger } from '../../helpers/logger.js'
import { CONSTRAINTS_FIELDS, DIRECTORIES, STATIC_PATHS, WEBSERVER } from '../../initializers/constants.js'
import { ActorModel } from '../actor/actor.js'
import { SequelizeModel } from '../shared/index.js'
+const logger = createLogger()
+
// Image uploads that are not suitable for other tables actor images (avatars/banners)
// Can be used to store instance images like logos, favicons, etc.
diff --git a/server/core/models/oauth/oauth-token.ts b/server/core/models/oauth/oauth-token.ts
index 51a5c31808..1bc34a8162 100644
--- a/server/core/models/oauth/oauth-token.ts
+++ b/server/core/models/oauth/oauth-token.ts
@@ -17,13 +17,15 @@ import {
Table,
UpdatedAt
} from 'sequelize-typescript'
-import { logger } from '../../helpers/logger.js'
+import { createLogger } from '../../helpers/logger.js'
import { AccountModel } from '../account/account.js'
import { ActorModel } from '../actor/actor.js'
import { getSort, SequelizeModel } from '../shared/index.js'
import { UserModel } from '../user/user.js'
import { OAuthClientModel } from './oauth-client.js'
+const logger = createLogger()
+
export type OAuthTokenInfo = {
refreshToken: string
refreshTokenExpiresAt: Date
diff --git a/server/core/models/redundancy/video-redundancy.ts b/server/core/models/redundancy/video-redundancy.ts
index c2f5f066bb..13acce4137 100644
--- a/server/core/models/redundancy/video-redundancy.ts
+++ b/server/core/models/redundancy/video-redundancy.ts
@@ -27,7 +27,7 @@ import {
UpdatedAt
} from 'sequelize-typescript'
import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc.js'
-import { logger } from '../../helpers/logger.js'
+import { createLogger } from '../../helpers/logger.js'
import { CONFIG } from '../../initializers/config.js'
import { CONSTRAINTS_FIELDS } from '../../initializers/constants.js'
import { ActorModel } from '../actor/actor.js'
@@ -39,6 +39,8 @@ import { VideoStreamingPlaylistModel } from '../video/video-streaming-playlist.j
import { VideoModel } from '../video/video.js'
import { getAllPrivacies } from '@peertube/peertube-core-utils'
+const logger = createLogger()
+
export enum ScopeNames {
WITH_VIDEO = 'WITH_VIDEO'
}
diff --git a/server/core/models/shared/model-builder.ts b/server/core/models/shared/model-builder.ts
index 4c81297300..bce29c6ca8 100644
--- a/server/core/models/shared/model-builder.ts
+++ b/server/core/models/shared/model-builder.ts
@@ -1,8 +1,10 @@
import { arrayify } from '@peertube/peertube-core-utils'
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import isPlainObject from 'lodash-es/isPlainObject.js'
import { ModelStatic, Sequelize, Model as SequelizeModel } from 'sequelize'
+const logger = createLogger()
+
/**
* Build Sequelize models from sequelize raw query (that must use { nest: true } options)
*
diff --git a/server/core/models/shared/model-cache.ts b/server/core/models/shared/model-cache.ts
index 54fad6b216..daab13c10f 100644
--- a/server/core/models/shared/model-cache.ts
+++ b/server/core/models/shared/model-cache.ts
@@ -1,5 +1,7 @@
import { Model } from 'sequelize-typescript'
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
+
+const logger = createLogger()
type ModelCacheType =
'server-account'
diff --git a/server/core/models/user/user-export.ts b/server/core/models/user/user-export.ts
index 1e1820bd73..d79671e540 100644
--- a/server/core/models/user/user-export.ts
+++ b/server/core/models/user/user-export.ts
@@ -1,5 +1,5 @@
import { FileStorage, UserExportState, type FileStorageType, type UserExport, type UserExportStateType } from '@peertube/peertube-models'
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { CONFIG } from '@server/initializers/config.js'
import {
DOWNLOAD_PATHS,
@@ -21,6 +21,8 @@ import { SequelizeModel } from '../shared/sequelize-type.js'
import { getSort } from '../shared/sort.js'
import { UserModel } from './user.js'
+const logger = createLogger()
+
@Table({
tableName: 'userExport',
indexes: [
diff --git a/server/core/models/video/storyboard.ts b/server/core/models/video/storyboard.ts
index 513b0dcdc6..8424a09e54 100644
--- a/server/core/models/video/storyboard.ts
+++ b/server/core/models/video/storyboard.ts
@@ -5,11 +5,13 @@ import { remove } from 'fs-extra/esm'
import { join } from 'path'
import { Op, Transaction } from 'sequelize'
import { AfterDestroy, AllowNull, BelongsTo, Column, CreatedAt, DataType, ForeignKey, Table, UpdatedAt } from 'sequelize-typescript'
-import { logger } from '../../helpers/logger.js'
+import { createLogger } from '../../helpers/logger.js'
import { CONSTRAINTS_FIELDS, FILES_CACHE, LAZY_STATIC_PATHS, WEBSERVER } from '../../initializers/constants.js'
import { SequelizeModel } from '../shared/index.js'
import { VideoModel } from './video.js'
+const logger = createLogger()
+
@Table({
tableName: 'storyboard',
indexes: [
diff --git a/server/core/models/video/thumbnail.ts b/server/core/models/video/thumbnail.ts
index 8f9ff7445b..9f428b2ea8 100644
--- a/server/core/models/video/thumbnail.ts
+++ b/server/core/models/video/thumbnail.ts
@@ -18,13 +18,15 @@ import {
Table,
UpdatedAt
} from 'sequelize-typescript'
-import { logger } from '../../helpers/logger.js'
+import { createLogger } from '../../helpers/logger.js'
import { CONSTRAINTS_FIELDS, FILES_CACHE, LAZY_STATIC_PATHS, MIMETYPES, WEBSERVER } from '../../initializers/constants.js'
import { SequelizeModel } from '../shared/sequelize-type.js'
import { buildSQLAttributes } from '../shared/table.js'
import { VideoPlaylistModel } from './video-playlist.js'
import { VideoModel } from './video.js'
+const logger = createLogger()
+
// A thumbnail always belongs to a video or to a playlist, never to both
type ThumbnailOwner =
| { videoId: number, videoPlaylistId?: never }
diff --git a/server/core/models/video/video-caption.ts b/server/core/models/video/video-caption.ts
index 30b13dcce5..1460eeee6d 100644
--- a/server/core/models/video/video-caption.ts
+++ b/server/core/models/video/video-caption.ts
@@ -34,13 +34,15 @@ import {
UpdatedAt
} from 'sequelize-typescript'
import { isVideoCaptionLanguageValid } from '../../helpers/custom-validators/video-captions.js'
-import { logger } from '../../helpers/logger.js'
+import { createLogger } from '../../helpers/logger.js'
import { CONFIG } from '../../initializers/config.js'
import { CONSTRAINTS_FIELDS, FILES_CACHE, LAZY_STATIC_PATHS, VIDEO_TEXT_LANGUAGES, WEBSERVER } from '../../initializers/constants.js'
import { SequelizeModel, buildWhereIdOrUUID, doesExist, throwIfNotValid } from '../shared/index.js'
import { VideoStreamingPlaylistModel } from './video-streaming-playlist.js'
import { VideoModel } from './video.js'
+const logger = createLogger()
+
export enum ScopeNames {
CAPTION_WITH_VIDEO = 'CAPTION_WITH_VIDEO'
}
diff --git a/server/core/models/video/video-comment.ts b/server/core/models/video/video-comment.ts
index d6afb31c43..b998e33734 100644
--- a/server/core/models/video/video-comment.ts
+++ b/server/core/models/video/video-comment.ts
@@ -8,7 +8,7 @@ import {
VideoCommentObject
} from '@peertube/peertube-models'
import { afterCommitIfTransaction, retryTransactionWrapper } from '@server/helpers/database-utils.js'
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { extractLocalMentions } from '@server/helpers/mentions.js'
import { sequelizeTypescript } from '@server/initializers/database.js'
import { getLocalApproveReplyActivityPubUrl } from '@server/lib/activitypub/url.js'
@@ -56,6 +56,8 @@ import { ListVideoCommentsOptions, VideoCommentListQueryBuilder } from './sql/co
import { VideoChannelModel } from './video-channel.js'
import { VideoModel } from './video.js'
+const logger = createLogger()
+
export enum ScopeNames {
WITH_ACCOUNT = 'WITH_ACCOUNT',
WITH_IN_REPLY_TO = 'WITH_IN_REPLY_TO',
diff --git a/server/core/models/video/video-file.ts b/server/core/models/video/video-file.ts
index a01bdfdd62..15d1db3660 100644
--- a/server/core/models/video/video-file.ts
+++ b/server/core/models/video/video-file.ts
@@ -8,7 +8,7 @@ import {
type VideoFileStreamType,
VideoResolution
} from '@peertube/peertube-models'
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { extractVideo } from '@server/helpers/video.js'
import { CONFIG } from '@server/initializers/config.js'
import { buildRemoteUrl } from '@server/lib/activitypub/url.js'
@@ -55,6 +55,8 @@ import { VideoInfohashModel } from './video-infohash.js'
import { VideoStreamingPlaylistModel } from './video-streaming-playlist.js'
import { VideoModel } from './video.js'
+const logger = createLogger()
+
export enum ScopeNames {
WITH_VIDEO = 'WITH_VIDEO',
WITH_METADATA = 'WITH_METADATA',
diff --git a/server/core/models/video/video-infohash.ts b/server/core/models/video/video-infohash.ts
index 5c0ae91fbc..5246de9cf3 100644
--- a/server/core/models/video/video-infohash.ts
+++ b/server/core/models/video/video-infohash.ts
@@ -1,4 +1,4 @@
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { MInfohash } from '@server/types/models/video/video-infohash.js'
import memoizee from 'memoizee'
import { Op, Transaction } from 'sequelize'
@@ -8,6 +8,8 @@ import { SequelizeModel, doesExist } from '../shared/index.js'
import { VideoFileModel } from './video-file.js'
import { VideoStreamingPlaylistModel } from './video-streaming-playlist.js'
+const logger = createLogger()
+
@Table({
tableName: 'videoInfohash',
timestamps: false,
diff --git a/server/core/models/video/video-streaming-playlist.ts b/server/core/models/video/video-streaming-playlist.ts
index 2c80d13a9d..381c32ae89 100644
--- a/server/core/models/video/video-streaming-playlist.ts
+++ b/server/core/models/video/video-streaming-playlist.ts
@@ -8,7 +8,7 @@ import {
type VideoStreamingPlaylistType_Type
} from '@peertube/peertube-models'
import { generateP2PMediaLoaderHash } from '@peertube/peertube-node-utils'
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { CONFIG } from '@server/initializers/config.js'
import { sequelizeTypescript } from '@server/initializers/database.js'
import {
@@ -37,6 +37,8 @@ import { SequelizeModel, doesExist } from '../shared/index.js'
import { VideoInfohashModel } from './video-infohash.js'
import { VideoModel } from './video.js'
+const logger = createLogger()
+
@Table({
tableName: 'videoStreamingPlaylist',
indexes: [
diff --git a/server/core/models/video/video.ts b/server/core/models/video/video.ts
index 9cf1e57fdc..14f5790758 100644
--- a/server/core/models/video/video.ts
+++ b/server/core/models/video/video.ts
@@ -81,7 +81,7 @@ import {
isVideoStateValid,
isVideoSupportValid
} from '../../helpers/custom-validators/videos.js'
-import { logger, loggerTagsFactory } from '../../helpers/logger.js'
+import { createLogger } from '../../helpers/logger.js'
import { CONFIG } from '../../initializers/config.js'
import { ACTIVITY_PUB, CONSTRAINTS_FIELDS, WEBSERVER } from '../../initializers/constants.js'
import { sendDeleteVideo } from '../../lib/activitypub/send/index.js'
@@ -171,7 +171,7 @@ import { VideoSourceModel } from './video-source.js'
import { VideoStreamingPlaylistModel } from './video-streaming-playlist.js'
import { VideoTagModel } from './video-tag.js'
-const lTags = loggerTagsFactory('video')
+const logger = createLogger('video')
const videoSummaryAttributes = [
'id',
@@ -853,16 +853,18 @@ export class VideoModel extends SequelizeModel<VideoModel> {
// ---------------------------------------------------------------------------
@BeforeDestroy
- static async beforeDestroyHook (instance: VideoModel, options: { transaction: Transaction }) {
- // We need infohashes to save the magnet URIs of the video in its abuses
- const video = await this.loadAP(instance.id, options.transaction)
+ static beforeDestroyHook (instance: VideoModel, options: { transaction: Transaction }) {
+ return logger.withContext([ instance.uuid ], async () => {
+ // We need infohashes to save the magnet URIs of the video in its abuses
+ const video = await this.loadAP(instance.id, options.transaction)
- this.stopLiveIfNeeded(video)
- this.invalidateCache(video)
+ this.stopLiveIfNeeded(video)
+ this.invalidateCache(video)
- await this.sendDelete(video, options.transaction)
- await this.saveEssentialDataToAbuses(video, options.transaction)
- await this.removeFiles(video, options.transaction)
+ await this.sendDelete(video, options.transaction)
+ await this.saveEssentialDataToAbuses(video, options.transaction)
+ await this.removeFiles(video, options.transaction)
+ })
}
static stopLiveIfNeeded (instance: MVideo) {
@@ -2188,7 +2190,7 @@ export class VideoModel extends SequelizeModel<VideoModel> {
promises.push(removeWebVideoObjectStorage(videoFile))
}
- logger.debug(`Removing files associated to web video ${videoFile.filename}`, { videoFile, ...lTags(this.uuid) })
+ logger.debug(`Removing files associated to web video ${videoFile.filename}`, { videoFile })
return Promise.all(promises)
}
@@ -2235,7 +2237,7 @@ export class VideoModel extends SequelizeModel<VideoModel> {
} catch (err) {
logger.error(
`Cannot remove caption ${caption.filename} (${caption.language}) playlist files associated to video ${this.name}`,
- { video: this, ...lTags(this.uuid) }
+ { video: this }
)
}
}
@@ -2260,10 +2262,7 @@ export class VideoModel extends SequelizeModel<VideoModel> {
}
}
- logger.debug(
- `Removing files associated to streaming playlist of video ${this.url}`,
- { playlist, isRedundancy, ...lTags(this.uuid) }
- )
+ logger.debug(`Removing files associated to streaming playlist of video ${this.url}`, { playlist, isRedundancy })
}
async removeStreamingPlaylistVideoFile (streamingPlaylist: MStreamingPlaylist, videoFile: MVideoFile) {
@@ -2279,10 +2278,7 @@ export class VideoModel extends SequelizeModel<VideoModel> {
await removeHLSFileObjectStorageByFilename(this, resolutionFilename)
}
- logger.debug(
- `Removing files associated to streaming playlist video file ${videoFile.filename}`,
- { streamingPlaylist, ...lTags(this.uuid) }
- )
+ logger.debug(`Removing files associated to streaming playlist video file ${videoFile.filename}`, { streamingPlaylist })
}
async removeStreamingPlaylistFile (streamingPlaylist: MStreamingPlaylist, filename: string) {
@@ -2293,7 +2289,7 @@ export class VideoModel extends SequelizeModel<VideoModel> {
await removeHLSFileObjectStorageByFilename(this, filename)
}
- logger.debug(`Removing streaming playlist file ${filename}`, lTags(this.uuid))
+ logger.debug(`Removing streaming playlist file ${filename}`)
}
async removeOriginalFile (videoSource: MVideoSource) {
@@ -2306,7 +2302,7 @@ export class VideoModel extends SequelizeModel<VideoModel> {
await removeOriginalFileObjectStorage(videoSource)
}
- logger.debug(`Removing original video file ${videoSource.keptOriginalFilename}`, lTags(this.uuid))
+ logger.debug(`Removing original video file ${videoSource.keptOriginalFilename}`)
}
// ---------------------------------------------------------------------------
diff --git a/server/core/models/watched-words/watched-words-list.ts b/server/core/models/watched-words/watched-words-list.ts
index 006ec93ff2..b8b0057e10 100644
--- a/server/core/models/watched-words/watched-words-list.ts
+++ b/server/core/models/watched-words/watched-words-list.ts
@@ -1,5 +1,5 @@
import { WatchedWordsList } from '@peertube/peertube-models'
-import { logger } from '@server/helpers/logger.js'
+import { createLogger } from '@server/helpers/logger.js'
import { wordsToRegExp } from '@server/helpers/regexp.js'
import { MAccountId, MWatchedWordsList } from '@server/types/models/index.js'
import { LRUCache } from 'lru-cache'
@@ -10,6 +10,8 @@ import { AccountModel } from '../account/account.js'
import { SequelizeModel, getSort } from '../shared/index.js'
import { WatchedWordsSubscriptionModel } from './watched-words-subscription.js'
+const logger = createLogger()
+
@Table({
tableName: 'watchedWordsList',
indexes: [
diff --git a/server/server.ts b/server/server.ts
index 6ad6d010b7..f705a299fa 100644
--- a/server/server.ts
+++ b/server/server.ts
@@ -8,10 +8,12 @@ import { checkFFmpeg, checkMissedConfig, checkNodeVersion } from './core/initial
// Do not use barrels because we don't want to load all modules here (we need to initialize database first)
import { initI18n, useI18n } from '@server/helpers/i18n.js'
-import { logger } from './core/helpers/logger.js'
+import { createLogger } from './core/helpers/logger.js'
import { CONFIG } from './core/initializers/config.js'
import { API_VERSION, WEBSERVER, loadLanguages } from './core/initializers/constants.js'
+const logger = createLogger()
+
const missed = checkMissedConfig()
if (missed.length !== 0) {
logger.error('Your configuration files miss keys: ' + missed)
@@ -75,6 +77,10 @@ const app = express().disable('x-powered-by')
// Trust our proxy (IP forwarding...)
app.set('trust proxy', CONFIG.TRUST_PROXY)
+// Tag every logger call made while handling a request with a request id, first so every other middleware benefits from it
+import { requestLoggerContext } from './core/middlewares/logger-context.js'
+app.use(requestLoggerContext)
+
app.use((_req, res, next) => {
// OpenTelemetry
res.locals.requestStart = Date.now()
@@ -173,7 +179,7 @@ cli
if (isTestOrDevInstance()) {
app.use(cors({
origin: '*',
- exposedHeaders: 'Retry-After'
+ exposedHeaders: [ 'Retry-After', 'X-Request-Id' ]
}))
}