chore(server): proper log context formatting (#22173)

* Fix log formatting for logger.error(..., error)

Rewrite it to avoid printing error msg in [context]

* Fix log formatting for logger.warn(..., error?.stack)

Rewrite it to avoid printing stack in [context]

* Fix log formatting for logger.debug(..., error.message);

Rewrite it to avoid printing error msg in [context]

* Print error msg instead of literal "Error"
This commit is contained in:
Sergey Katsubo 2025-09-19 02:56:05 +03:00 committed by GitHub
parent b8a17c3c26
commit 78516a97b3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 15 additions and 15 deletions

View File

@ -57,28 +57,28 @@ export class MediaRepository {
const buffer = await exiftool.extractBinaryTagToBuffer('JpgFromRaw2', input); const buffer = await exiftool.extractBinaryTagToBuffer('JpgFromRaw2', input);
return { buffer, format: RawExtractedFormat.Jpeg }; return { buffer, format: RawExtractedFormat.Jpeg };
} catch (error: any) { } catch (error: any) {
this.logger.debug('Could not extract JpgFromRaw2 buffer from image, trying JPEG from RAW next', error.message); this.logger.debug(`Could not extract JpgFromRaw2 buffer from image, trying JPEG from RAW next: ${error}`);
} }
try { try {
const buffer = await exiftool.extractBinaryTagToBuffer('JpgFromRaw', input); const buffer = await exiftool.extractBinaryTagToBuffer('JpgFromRaw', input);
return { buffer, format: RawExtractedFormat.Jpeg }; return { buffer, format: RawExtractedFormat.Jpeg };
} catch (error: any) { } catch (error: any) {
this.logger.debug('Could not extract JPEG buffer from image, trying PreviewJXL next', error.message); this.logger.debug(`Could not extract JPEG buffer from image, trying PreviewJXL next: ${error}`);
} }
try { try {
const buffer = await exiftool.extractBinaryTagToBuffer('PreviewJXL', input); const buffer = await exiftool.extractBinaryTagToBuffer('PreviewJXL', input);
return { buffer, format: RawExtractedFormat.Jxl }; return { buffer, format: RawExtractedFormat.Jxl };
} catch (error: any) { } catch (error: any) {
this.logger.debug('Could not extract PreviewJXL buffer from image, trying PreviewImage next', error.message); this.logger.debug(`Could not extract PreviewJXL buffer from image, trying PreviewImage next: ${error}`);
} }
try { try {
const buffer = await exiftool.extractBinaryTagToBuffer('PreviewImage', input); const buffer = await exiftool.extractBinaryTagToBuffer('PreviewImage', input);
return { buffer, format: RawExtractedFormat.Jpeg }; return { buffer, format: RawExtractedFormat.Jpeg };
} catch (error: any) { } catch (error: any) {
this.logger.debug('Could not extract preview buffer from image', error.message); this.logger.debug(`Could not extract preview buffer from image: ${error}`);
return null; return null;
} }
} }

View File

@ -103,7 +103,7 @@ export class MetadataRepository {
readTags(path: string): Promise<ImmichTags> { readTags(path: string): Promise<ImmichTags> {
return this.exiftool.read(path).catch((error) => { return this.exiftool.read(path).catch((error) => {
this.logger.warn(`Error reading exif data (${path}): ${error}`, error?.stack); this.logger.warn(`Error reading exif data (${path}): ${error}\n${error?.stack}`);
return {}; return {};
}) as Promise<ImmichTags>; }) as Promise<ImmichTags>;
} }

View File

@ -344,7 +344,7 @@ export class AuthService extends BaseService {
await this.jobRepository.queue({ name: JobName.FileDelete, data: { files: [oldPath] } }); await this.jobRepository.queue({ name: JobName.FileDelete, data: { files: [oldPath] } });
} }
} catch (error: Error | any) { } catch (error: Error | any) {
this.logger.warn(`Unable to sync oauth profile picture: ${error}`, error?.stack); this.logger.warn(`Unable to sync oauth profile picture: ${error}\n${error?.stack}`);
} }
} }

View File

@ -132,12 +132,12 @@ export class BackupService extends BaseService {
gzip.stdout.pipe(fileStream); gzip.stdout.pipe(fileStream);
pgdump.on('error', (err) => { pgdump.on('error', (err) => {
this.logger.error('Backup failed with error', err); this.logger.error(`Backup failed with error: ${err}`);
reject(err); reject(err);
}); });
gzip.on('error', (err) => { gzip.on('error', (err) => {
this.logger.error('Gzip failed with error', err); this.logger.error(`Gzip failed with error: ${err}`);
reject(err); reject(err);
}); });
@ -175,10 +175,10 @@ export class BackupService extends BaseService {
}); });
await this.storageRepository.rename(backupFilePath, backupFilePath.replace('.tmp', '')); await this.storageRepository.rename(backupFilePath, backupFilePath.replace('.tmp', ''));
} catch (error) { } catch (error) {
this.logger.error('Database Backup Failure', error); this.logger.error(`Database Backup Failure: ${error}`);
await this.storageRepository await this.storageRepository
.unlink(backupFilePath) .unlink(backupFilePath)
.catch((error) => this.logger.error('Failed to delete failed backup file', error)); .catch((error) => this.logger.error(`Failed to delete failed backup file: ${error}`));
throw error; throw error;
} }

View File

@ -245,7 +245,7 @@ export class LibraryService extends BaseService {
job.paths.map((path) => job.paths.map((path) =>
this.processEntity(path, library.ownerId, job.libraryId) this.processEntity(path, library.ownerId, job.libraryId)
.then((asset) => assetImports.push(asset)) .then((asset) => assetImports.push(asset))
.catch((error: any) => this.logger.error(`Error processing ${path} for library ${job.libraryId}`, error)), .catch((error: any) => this.logger.error(`Error processing ${path} for library ${job.libraryId}: ${error}`)),
), ),
); );

View File

@ -40,7 +40,7 @@ export class MemoryService extends BaseService {
try { try {
await Promise.all(users.map((owner, i) => this.createOnThisDayMemories(owner.id, usersIds[i], target))); await Promise.all(users.map((owner, i) => this.createOnThisDayMemories(owner.id, usersIds[i], target)));
} catch (error) { } catch (error) {
this.logger.error(`Failed to create memories for ${target.toISO()}`, error); this.logger.error(`Failed to create memories for ${target.toISO()}: ${error}`);
} }
// update system metadata even when there is an error to minimize the chance of duplicates // update system metadata even when there is an error to minimize the chance of duplicates
await this.systemMetadataRepository.set(SystemMetadataKey.MemoriesState, { await this.systemMetadataRepository.set(SystemMetadataKey.MemoriesState, {

View File

@ -338,7 +338,7 @@ export class StorageTemplateService extends BaseService {
return destination; return destination;
} catch (error: any) { } catch (error: any) {
this.logger.error(`Unable to get template path for ${filename}`, error); this.logger.error(`Unable to get template path for ${filename}: ${error}`);
return asset.originalPath; return asset.originalPath;
} }
} }

View File

@ -95,7 +95,7 @@ export class VersionService extends BaseService {
this.eventRepository.clientBroadcast('on_new_release', asNotification(metadata)); this.eventRepository.clientBroadcast('on_new_release', asNotification(metadata));
} }
} catch (error: Error | any) { } catch (error: Error | any) {
this.logger.warn(`Unable to run version check: ${error}`, error?.stack); this.logger.warn(`Unable to run version check: ${error}\n${error?.stack}`);
return JobStatus.Failed; return JobStatus.Failed;
} }

View File

@ -73,7 +73,7 @@ export const sendFile = async (
// log non-http errors // log non-http errors
if (error instanceof HttpException === false) { if (error instanceof HttpException === false) {
logger.error(`Unable to send file: ${error.name}`, error.stack); logger.error(`Unable to send file: ${error}`, error.stack);
} }
res.header('Cache-Control', 'none'); res.header('Cache-Control', 'none');