// ----------- Core checker -----------
import { checkMissedConfig, checkFFmpeg, checkConfig } from './server/initializers/checker'
+// Do not use barrels because we don't want to load all modules here (we need to initialize database first)
+import { logger } from './server/helpers/logger'
+import { ACCEPT_HEADERS, API_VERSION, CONFIG, STATIC_PATHS } from './server/initializers/constants'
+
const missed = checkMissedConfig()
if (missed.length !== 0) {
- throw new Error('Your configuration files miss keys: ' + missed)
+ logger.error('Your configuration files miss keys: ' + missed)
+ process.exit(-1)
}
-import { ACCEPT_HEADERS, API_VERSION, CONFIG, STATIC_PATHS } from './server/initializers/constants'
checkFFmpeg(CONFIG)
+ .catch(err => {
+ logger.error('Error in ffmpeg check.', { err })
+ process.exit(-1)
+ })
const errorMessage = checkConfig()
if (errorMessage !== null) {
}
// ----------- Database -----------
-// Do not use barrels because we don't want to load all modules here (we need to initialize database first)
-import { logger } from './server/helpers/logger'
// Initialize database and models
import { initDatabaseModels } from './server/initializers/database'
return retryTransactionWrapper(follow, options)
})
- .catch(err => logger.warn('Cannot follow server %s.', sanitizedHost, err))
+ .catch(err => logger.warn('Cannot follow server %s.', sanitizedHost, { err }))
tasks.push(p)
}
// Don't make the client wait the tasks
Promise.all(tasks)
- .catch(err => logger.error('Error in follow.', err))
+ .catch(err => logger.error('Error in follow.', { err }))
return res.status(204).end()
}
// This could be long so don't wait this task
const following = follow.ActorFollowing
following.destroy()
- .catch(err => logger.error('Cannot destroy actor that we do not follow anymore %s.', following.url, err))
+ .catch(err => logger.error('Cannot destroy actor that we do not follow anymore %s.', following.url, { err }))
return res.status(204).end()
}
return res.sendStatus(204)
} catch (err) {
- logger.error('Some error while removing video %s from blacklist.', res.locals.video.uuid, err)
+ logger.error('Some error while removing video %s from blacklist.', res.locals.video.uuid, { err })
throw err
}
}
})
setAsyncActorKeys(videoChannelCreated.Actor)
- .catch(err => logger.error('Cannot set async actor keys for account %s.', videoChannelCreated.Actor.uuid, err))
+ .catch(err => logger.error('Cannot set async actor keys for account %s.', videoChannelCreated.Actor.uuid, { err }))
logger.info('Video channel with uuid %s created.', videoChannelCreated.Actor.uuid)
logger.info('Video channel with name %s and uuid %s updated.', videoChannelInstance.name, videoChannelInstance.Actor.uuid)
} catch (err) {
- logger.debug('Cannot update the video channel.', err)
+ logger.debug('Cannot update the video channel.', { err })
// Force fields we want to update
// If the transaction is retried, sequelize will think the object has not changed
.catch(err => callback(err))
})
.catch(err => {
- logger.error(options.errorMessage, err)
+ logger.error(options.errorMessage, { err })
throw err
})
}
const destination = join(folder, imageName)
await processImage({ path: pendingImagePath }, destination, size)
} catch (err) {
- logger.error('Cannot generate image from video %s.', fromPath, err)
+ logger.error('Cannot generate image from video %s.', fromPath, { err })
try {
await unlinkPromise(pendingImagePath)
} catch (err) {
- logger.debug('Cannot remove pending image path after generation error.', err)
+ logger.debug('Cannot remove pending image path after generation error.', { err })
}
}
}
label: true
}
function keysExcluder (key, value) {
- return excludedKeys[key] === true ? undefined : value
+ if (excludedKeys[key] === true) return undefined
+
+ if (key === 'err') return value.stack
+
+ return value
}
const consoleLoggerFormat = winston.format.printf(info => {
return `[${info.label}] ${info.timestamp} ${info.level}: ${info.message}${additionalInfos}`
})
-const jsonLoggerFormat = winston.format.printf(info => {
- if (info.message && info.message.stack !== undefined) info.message = info.message.stack
+const jsonLoggerFormat = winston.format.printf(infoArg => {
+ let info = infoArg.err
+ ? Object.assign({}, infoArg, { err: infoArg.err.stack })
+ : infoArg
+
+ if (infoArg.message && infoArg.message.stack !== undefined) {
+ info = Object.assign({}, info, { message: infoArg.message.stack })
+ }
return JSON.stringify(info)
})
return jsig.promises.verify(signedDocument, options)
.catch(err => {
- logger.error('Cannot check signature.', err)
+ logger.error('Cannot check signature.', { err })
return false
})
}
try {
randomString = await generateRandomString(16)
} catch (err) {
- logger.error('Cannot generate random string for file name.', err)
+ logger.error('Cannot generate random string for file name.', { err })
randomString = 'fake-random-string'
}
await createOAuthClientIfNotExist()
await createOAuthAdminIfNotExist()
} catch (err) {
- logger.error('Cannot install application.', err)
+ logger.error('Cannot install application.', { err })
process.exit(-1)
}
}
try {
await executeMigration(actualVersion, migrationScript)
} catch (err) {
- logger.error('Cannot execute migration %s.', migrationScript.version, err)
+ logger.error('Cannot execute migration %s.', migrationScript.version, { err })
process.exit(-1)
}
}
return actor.save()
})
.catch(err => {
- logger.error('Cannot set public/private keys of actor %d.', actor.uuid, err)
+ logger.error('Cannot set public/private keys of actor %d.', actor.uuid, { err })
return actor
})
}
try {
await actorInstance.Avatar.destroy({ transaction: t })
} catch (err) {
- logger.error('Cannot remove old avatar of actor %s.', actorInstance.url, err)
+ logger.error('Cannot remove old avatar of actor %s.', actorInstance.url, { err })
}
}
const { body } = await doRequest(options)
return body.totalItems ? body.totalItems : 0
} catch (err) {
- logger.warn('Cannot fetch remote actor count %s.', url, err)
+ logger.warn('Cannot fetch remote actor count %s.', url, { err })
return 0
}
}
return actor
})
} catch (err) {
- logger.warn('Cannot refresh actor.', err)
+ logger.warn('Cannot refresh actor.', { err })
return actor
}
}
// Don't block on request
generateThumbnailFromUrl(videoInstance, videoAttributesToUpdate.icon)
- .catch(err => logger.warn('Cannot generate thumbnail of %s.', videoAttributesToUpdate.id, err))
+ .catch(err => logger.warn('Cannot generate thumbnail of %s.', videoAttributesToUpdate.id, { err }))
// Remove old video files
const videoFileDestroyTasks: Bluebird<void>[] = []
}
// This is just a debug because we will retry the insert
- logger.debug('Cannot update the remote video.', err)
+ logger.debug('Cannot update the remote video.', { err })
throw err
}
}
}
// This is just a debug because we will retry the insert
- logger.debug('Cannot update the remote account.', err)
+ logger.debug('Cannot update the remote account.', { err })
throw err
}
}
return { video, parents: comments }
} catch (err) {
- logger.debug('Cannot get or create account and video and channel for reply %s, fetch comment', url, err)
+ logger.debug('Cannot get or create account and video and channel for reply %s, fetch comment', url, { err })
if (comments.length > ACTIVITY_PUB.MAX_RECURSION_COMMENTS) {
throw new Error('Recursion limit reached when resolving a thread')
// Don't block on request
generateThumbnailFromUrl(video, videoObject.icon)
- .catch(err => logger.warn('Cannot generate thumbnail of %s.', videoObject.id, err))
+ .catch(err => logger.warn('Cannot generate thumbnail of %s.', videoObject.id, { err }))
const videoCreated = await video.save(sequelizeOptions)
}
private dieOnConnectionFailure (err?: Error) {
- logger.error('Failed to connect to SMTP %s:%d.', CONFIG.SMTP.HOSTNAME, CONFIG.SMTP.PORT, err)
+ logger.error('Failed to connect to SMTP %s:%d.', CONFIG.SMTP.HOSTNAME, CONFIG.SMTP.PORT, { err })
process.exit(-1)
}
this.jobQueue.setMaxListeners(15)
this.jobQueue.on('error', err => {
- logger.error('Error in job queue.', err)
+ logger.error('Error in job queue.', { err })
process.exit(-1)
})
this.jobQueue.watchStuckJobs(5000)
const now = new Date().getTime()
kue.Job.rangeByState('complete', 0, -1, 'asc', (err, jobs) => {
if (err) {
- logger.error('Cannot get jobs when removing old jobs.', err)
+ logger.error('Cannot get jobs when removing old jobs.', { err })
return
}
})
this.client.on('error', err => {
- logger.error('Error in Redis client.', err)
+ logger.error('Error in Redis client.', { err })
process.exit(-1)
})
try {
await ActorFollowModel.removeBadActorFollows()
} catch (err) {
- logger.error('Error in bad actor follows scheduler.', err)
+ logger.error('Error in bad actor follows scheduler.', { err })
}
}
try {
actor = await getOrCreateActorAndServerAndModel(creator)
} catch (err) {
- logger.error('Cannot create remote actor and check signature.', err)
+ logger.error('Cannot create remote actor and check signature.', { err })
return res.sendStatus(403)
}
try {
duration = await getDurationFromVideoFile(videoFile.path)
} catch (err) {
- logger.error('Invalid input file in videosAddValidator.', err)
+ logger.error('Invalid input file in videosAddValidator.', { err })
res.status(400)
.json({ error: 'Invalid input file.' })
.end()
if (goodInboxes.length !== 0) {
ActorFollowModel.incrementScores(goodInboxes, ACTOR_FOLLOW_SCORE.BONUS, t)
- .catch(err => logger.error('Cannot increment scores of good actor follows.', err))
+ .catch(err => logger.error('Cannot increment scores of good actor follows.', { err }))
}
if (badInboxes.length !== 0) {
ActorFollowModel.incrementScores(badInboxes, ACTOR_FOLLOW_SCORE.PENALTY, t)
- .catch(err => logger.error('Cannot decrement scores of bad actor follows.', err))
+ .catch(err => logger.error('Cannot decrement scores of bad actor follows.', { err }))
}
}
} as OAuthTokenInfo
})
.catch(err => {
- logger.info('getRefreshToken error.', err)
+ logger.info('getRefreshToken error.', { err })
throw err
})
}
return Promise.all(tasks)
.catch(err => {
- logger.error('Some errors when removing files of video %s in after destroy hook.', instance.uuid, err)
+ logger.error('Some errors when removing files of video %s in after destroy hook.', instance.uuid, { err })
})
}
} catch (err) {
// Auto destruction...
- this.destroy().catch(err => logger.error('Cannot destruct video after transcoding failure.', err))
+ this.destroy().catch(err => logger.error('Cannot destruct video after transcoding failure.', { err }))
throw err
}