mirror of
https://github.com/immich-app/immich.git
synced 2025-12-25 01:11:43 +03:00
refactor: logging repository (#15540)
This commit is contained in:
@@ -7,9 +7,8 @@ import { SystemConfig, defaults } from 'src/config';
|
||||
import { SystemConfigDto } from 'src/dtos/system-config.dto';
|
||||
import { SystemMetadataKey } from 'src/enum';
|
||||
import { DatabaseLock } from 'src/interfaces/database.interface';
|
||||
import { ILoggerRepository } from 'src/interfaces/logger.interface';
|
||||
import { ISystemMetadataRepository } from 'src/interfaces/system-metadata.interface';
|
||||
import { DeepPartial, IConfigRepository } from 'src/types';
|
||||
import { DeepPartial, IConfigRepository, ILoggingRepository } from 'src/types';
|
||||
import { getKeysDeep, unsetDeep } from 'src/utils/misc';
|
||||
|
||||
export type SystemConfigValidator = (config: SystemConfig, newConfig: SystemConfig) => void | Promise<void>;
|
||||
@@ -17,7 +16,7 @@ export type SystemConfigValidator = (config: SystemConfig, newConfig: SystemConf
|
||||
type RepoDeps = {
|
||||
configRepo: IConfigRepository;
|
||||
metadataRepo: ISystemMetadataRepository;
|
||||
logger: ILoggerRepository;
|
||||
logger: ILoggingRepository;
|
||||
};
|
||||
|
||||
const asyncLock = new AsyncLock();
|
||||
|
||||
@@ -4,8 +4,8 @@ import { access, constants } from 'node:fs/promises';
|
||||
import { basename, extname, isAbsolute } from 'node:path';
|
||||
import { promisify } from 'node:util';
|
||||
import { CacheControl } from 'src/enum';
|
||||
import { ILoggerRepository } from 'src/interfaces/logger.interface';
|
||||
import { ImmichReadStream } from 'src/interfaces/storage.interface';
|
||||
import { ILoggingRepository } from 'src/types';
|
||||
import { isConnectionAborted } from 'src/utils/misc';
|
||||
|
||||
export function getFileNameWithoutExtension(path: string): string {
|
||||
@@ -37,7 +37,7 @@ export const sendFile = async (
|
||||
res: Response,
|
||||
next: NextFunction,
|
||||
handler: () => Promise<ImmichFileResponse>,
|
||||
logger: ILoggerRepository,
|
||||
logger: ILoggingRepository,
|
||||
): Promise<void> => {
|
||||
const _sendFile = (path: string, options: SendFileOptions) =>
|
||||
promisify<string, SendFileOptions>(res.sendFile).bind(res)(path, options);
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { HttpException } from '@nestjs/common';
|
||||
import { ILoggerRepository } from 'src/interfaces/logger.interface';
|
||||
import { ILoggingRepository } from 'src/types';
|
||||
import { TypeORMError } from 'typeorm';
|
||||
|
||||
export const logGlobalError = (logger: ILoggerRepository, error: Error) => {
|
||||
export const logGlobalError = (logger: ILoggingRepository, error: Error) => {
|
||||
if (error instanceof HttpException) {
|
||||
const status = error.getStatus();
|
||||
const response = error.getResponse();
|
||||
|
||||
@@ -13,7 +13,7 @@ import path from 'node:path';
|
||||
import { SystemConfig } from 'src/config';
|
||||
import { CLIP_MODEL_INFO, serverVersion } from 'src/constants';
|
||||
import { ImmichCookie, ImmichHeader, MetadataKey } from 'src/enum';
|
||||
import { ILoggerRepository } from 'src/interfaces/logger.interface';
|
||||
import { ILoggingRepository } from 'src/types';
|
||||
|
||||
export class ImmichStartupError extends Error {}
|
||||
export const isStartUpError = (error: unknown): error is ImmichStartupError => error instanceof ImmichStartupError;
|
||||
@@ -96,7 +96,7 @@ export const isFaceImportEnabled = (metadata: SystemConfig['metadata']) => metad
|
||||
|
||||
export const isConnectionAborted = (error: Error | any) => error.code === 'ECONNABORTED';
|
||||
|
||||
export const handlePromiseError = <T>(promise: Promise<T>, logger: ILoggerRepository): void => {
|
||||
export const handlePromiseError = <T>(promise: Promise<T>, logger: ILoggingRepository): void => {
|
||||
promise.catch((error: Error | any) => logger.error(`Promise error: ${error}`, error?.stack));
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user