mirror of
				https://github.com/immich-app/immich.git
				synced 2025-10-30 18:35:00 -04:00 
			
		
		
		
	refactor: logging (#1318)
This commit is contained in:
		
							parent
							
								
									92ca447f33
								
							
						
					
					
						commit
						ba04b753de
					
				| @ -10,11 +10,14 @@ import { SERVER_VERSION } from './constants/server_version.constant'; | |||||||
| import { RedisIoAdapter } from './middlewares/redis-io.adapter.middleware'; | import { RedisIoAdapter } from './middlewares/redis-io.adapter.middleware'; | ||||||
| import { json } from 'body-parser'; | import { json } from 'body-parser'; | ||||||
| import { patchOpenAPI } from './utils/patch-open-api.util'; | import { patchOpenAPI } from './utils/patch-open-api.util'; | ||||||
|  | import { getLogLevels } from '@app/common'; | ||||||
| 
 | 
 | ||||||
| const logger = new Logger('ImmichServer'); | const logger = new Logger('ImmichServer'); | ||||||
| 
 | 
 | ||||||
| async function bootstrap() { | async function bootstrap() { | ||||||
|   const app = await NestFactory.create<NestExpressApplication>(AppModule); |   const app = await NestFactory.create<NestExpressApplication>(AppModule, { | ||||||
|  |     logger: getLogLevels(), | ||||||
|  |   }); | ||||||
| 
 | 
 | ||||||
|   app.set('trust proxy'); |   app.set('trust proxy'); | ||||||
|   app.set('etag', 'strong'); |   app.set('etag', 'strong'); | ||||||
|  | |||||||
| @ -1,13 +1,16 @@ | |||||||
| import { Logger } from '@nestjs/common'; | import { Logger } from '@nestjs/common'; | ||||||
| import { NestFactory } from '@nestjs/core'; | import { NestFactory } from '@nestjs/core'; | ||||||
| import { SERVER_VERSION } from 'apps/immich/src/constants/server_version.constant'; | import { SERVER_VERSION } from 'apps/immich/src/constants/server_version.constant'; | ||||||
|  | import { getLogLevels } from '@app/common'; | ||||||
| import { RedisIoAdapter } from '../../immich/src/middlewares/redis-io.adapter.middleware'; | import { RedisIoAdapter } from '../../immich/src/middlewares/redis-io.adapter.middleware'; | ||||||
| import { MicroservicesModule } from './microservices.module'; | import { MicroservicesModule } from './microservices.module'; | ||||||
| 
 | 
 | ||||||
| const logger = new Logger('ImmichMicroservice'); | const logger = new Logger('ImmichMicroservice'); | ||||||
| 
 | 
 | ||||||
| async function bootstrap() { | async function bootstrap() { | ||||||
|   const app = await NestFactory.create(MicroservicesModule); |   const app = await NestFactory.create(MicroservicesModule, { | ||||||
|  |     logger: getLogLevels(), | ||||||
|  |   }); | ||||||
| 
 | 
 | ||||||
|   const redisIoAdapter = new RedisIoAdapter(app); |   const redisIoAdapter = new RedisIoAdapter(app); | ||||||
|   await redisIoAdapter.connectToRedis(); |   await redisIoAdapter.connectToRedis(); | ||||||
|  | |||||||
| @ -1,4 +1,3 @@ | |||||||
| import { ImmichLogLevel } from '@app/common/constants/log-level.constant'; |  | ||||||
| import { AssetEntity, ExifEntity } from '@app/infra'; | import { AssetEntity, ExifEntity } from '@app/infra'; | ||||||
| import { | import { | ||||||
|   IExifExtractionProcessor, |   IExifExtractionProcessor, | ||||||
| @ -76,8 +75,8 @@ export type GeoData = { | |||||||
| 
 | 
 | ||||||
| @Processor(QueueNameEnum.METADATA_EXTRACTION) | @Processor(QueueNameEnum.METADATA_EXTRACTION) | ||||||
| export class MetadataExtractionProcessor { | export class MetadataExtractionProcessor { | ||||||
|  |   private logger = new Logger(MetadataExtractionProcessor.name); | ||||||
|   private isGeocodeInitialized = false; |   private isGeocodeInitialized = false; | ||||||
|   private logLevel: ImmichLogLevel; |  | ||||||
| 
 | 
 | ||||||
|   constructor( |   constructor( | ||||||
|     @InjectRepository(AssetEntity) |     @InjectRepository(AssetEntity) | ||||||
| @ -86,10 +85,10 @@ export class MetadataExtractionProcessor { | |||||||
|     @InjectRepository(ExifEntity) |     @InjectRepository(ExifEntity) | ||||||
|     private exifRepository: Repository<ExifEntity>, |     private exifRepository: Repository<ExifEntity>, | ||||||
| 
 | 
 | ||||||
|     private configService: ConfigService, |     configService: ConfigService, | ||||||
|   ) { |   ) { | ||||||
|     if (!configService.get('DISABLE_REVERSE_GEOCODING')) { |     if (!configService.get('DISABLE_REVERSE_GEOCODING')) { | ||||||
|       Logger.log('Initialising Reverse Geocoding'); |       this.logger.log('Initializing Reverse Geocoding'); | ||||||
|       geocoderInit({ |       geocoderInit({ | ||||||
|         // eslint-disable-next-line @typescript-eslint/ban-ts-comment
 |         // eslint-disable-next-line @typescript-eslint/ban-ts-comment
 | ||||||
|         // @ts-ignore
 |         // @ts-ignore
 | ||||||
| @ -108,8 +107,6 @@ export class MetadataExtractionProcessor { | |||||||
|         Logger.log('Reverse Geocoding Initialised'); |         Logger.log('Reverse Geocoding Initialised'); | ||||||
|       }); |       }); | ||||||
|     } |     } | ||||||
| 
 |  | ||||||
|     this.logLevel = this.configService.get('LOG_LEVEL') || ImmichLogLevel.SIMPLE; |  | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   private async reverseGeocodeExif( |   private async reverseGeocodeExif( | ||||||
| @ -260,12 +257,8 @@ export class MetadataExtractionProcessor { | |||||||
|       } |       } | ||||||
| 
 | 
 | ||||||
|       await this.exifRepository.save(newExif); |       await this.exifRepository.save(newExif); | ||||||
|     } catch (e) { |     } catch (error: any) { | ||||||
|       Logger.error(`Error extracting EXIF ${String(e)}`, 'extractExif'); |       this.logger.error(`Error extracting EXIF ${error}`, error?.stack); | ||||||
| 
 |  | ||||||
|       if (this.logLevel === ImmichLogLevel.VERBOSE) { |  | ||||||
|         console.trace('Error extracting EXIF', e); |  | ||||||
|       } |  | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -27,6 +27,6 @@ export const immichAppConfig: ConfigModuleOptions = { | |||||||
|     JWT_SECRET: Joi.string().required().custom(jwtSecretValidator), |     JWT_SECRET: Joi.string().required().custom(jwtSecretValidator), | ||||||
|     DISABLE_REVERSE_GEOCODING: Joi.boolean().optional().valid(true, false).default(false), |     DISABLE_REVERSE_GEOCODING: Joi.boolean().optional().valid(true, false).default(false), | ||||||
|     REVERSE_GEOCODING_PRECISION: Joi.number().optional().valid(0, 1, 2, 3).default(3), |     REVERSE_GEOCODING_PRECISION: Joi.number().optional().valid(0, 1, 2, 3).default(3), | ||||||
|     LOG_LEVEL: Joi.string().optional().valid('simple', 'verbose').default('simple'), |     LOG_LEVEL: Joi.string().optional().valid('simple', 'verbose', 'debug', 'log', 'warn', 'error').default('log'), | ||||||
|   }), |   }), | ||||||
| }; | }; | ||||||
|  | |||||||
| @ -1,4 +0,0 @@ | |||||||
| export enum ImmichLogLevel { |  | ||||||
|   SIMPLE = 'simple', |  | ||||||
|   VERBOSE = 'verbose', |  | ||||||
| } |  | ||||||
| @ -1,3 +1,15 @@ | |||||||
|  | import { LogLevel } from '@nestjs/common'; | ||||||
|  | 
 | ||||||
| export * from './time-utils'; | export * from './time-utils'; | ||||||
| export * from './asset-utils'; | export * from './asset-utils'; | ||||||
| export * from './user-utils'; | export * from './user-utils'; | ||||||
|  | 
 | ||||||
|  | export function getLogLevels() { | ||||||
|  |   const LOG_LEVELS: LogLevel[] = ['verbose', 'debug', 'log', 'warn', 'error']; | ||||||
|  |   let logLevel = process.env.LOG_LEVEL || 'log'; | ||||||
|  |   if (logLevel === 'simple') { | ||||||
|  |     logLevel = 'log'; | ||||||
|  |   } | ||||||
|  |   const logLevelIndex = LOG_LEVELS.indexOf(logLevel as LogLevel); | ||||||
|  |   return logLevelIndex === -1 ? [] : LOG_LEVELS.slice(logLevelIndex); | ||||||
|  | } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user