Skip to content

Commit

Permalink
Build sin funcion, yarn.lock inmutable y añadido log_file de nuevo. C…
Browse files Browse the repository at this point in the history
…loses #112
  • Loading branch information
Carlota de la Vega committed Jan 5, 2024
1 parent 24296ff commit 2906e80
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ WORKDIR /app
COPY package.json ./

RUN yarn config set cache-folder /app/.yarn_cache && \
yarn install --ignore-optional
yarn install --immutable --immutable-cache --check-cache

ENV PATH $PATH:/app/node_modules/.bin

Expand Down
3 changes: 2 additions & 1 deletion config.env
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
LOG_LEVEL=info
LOG_LEVEL=info
LOG_FILE_PATH=./logs.log
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"@nestjs/testing": "^10.3.0"
},
"scripts": {
"build": "tsc",
"build": "echo 'Building...'",
"check": "tsc --noEmit src/*.ts",
"test": "jest"
},
Expand All @@ -22,7 +22,6 @@
"dotenv": "^16.3.1",
"pino": "^8.17.1",
"pino-pretty": "^10.3.0",
"reflect-metadata": "0.1.14",
"rxjs": "^7.8.1"
"reflect-metadata": "0.1.14"
}
}
20 changes: 14 additions & 6 deletions src/logger.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pino from 'pino';
import { Configuracion } from './configuracion';
import * as fs from 'fs';

export class Logger {
private logger: pino.Logger;
Expand All @@ -10,16 +11,23 @@ export class Logger {
*/
constructor(configuracion: Configuracion) {
const logLevel = configuracion.get('LOG_LEVEL');
const logFilePath = configuracion.get('LOG_FILE_PATH');

if (!logLevel) {
throw new Error('Nivel de registro no configurado correctamente.');
if (!logLevel || !logFilePath) {
throw new Error('Nivel de registro o ruta del archivo de registro no configurados correctamente.');
}

const streams = [
{ level: logLevel, stream: process.stdout },
{ level: logLevel, stream: fs.createWriteStream(logFilePath, { flags: 'a' }) },
];

this.logger = pino({
level: logLevel,
});
}, pino.multistream(streams));
}


/**
* Registrar un mensaje de debug.
* @param message Mensaje a registrar.
Expand Down Expand Up @@ -58,6 +66,6 @@ export class Logger {
}

export const LoggerConfig = {
logger: new Logger(new Configuracion()),
config: new Configuracion(),
};
logger: new Logger(new Configuracion()),
config: new Configuracion(),
};
4 changes: 1 addition & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
"module": "commonjs",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true,
"noEmit": true
"strict": true
},
"include": [
"src/**/*.ts"
Expand Down

0 comments on commit 2906e80

Please sign in to comment.