@volontariapp/logger 0.2.5 → 0.2.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/README.md +23 -23
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @volontariapp/logger
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Un utilitaire de log cross-platform qui fonctionne parfaitement sur NodeJS, NestJS et React Native. Il génère des logs JSON structurés ou des logs texte colorés selon l'environnement d'exécution.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -8,13 +8,13 @@ A cross-platform logging utility that works seamlessly in NodeJS, NestJS, and Re
|
|
|
8
8
|
npm install @volontariapp/logger
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
##
|
|
11
|
+
## Configuration & Mise en place
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
Ce logger est très polyvalent et supporte différentes stratégies d'instanciation en fonction de la plateforme ciblée.
|
|
14
14
|
|
|
15
|
-
### 1. NodeJS
|
|
15
|
+
### 1. Projet NodeJS
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
Pour une application ou un script NodeJS classique, vous pouvez instancier le logger directement. Nous recommandons d'utiliser le format `text` pour le développement local et `json` en production.
|
|
18
18
|
|
|
19
19
|
```typescript
|
|
20
20
|
import { Logger } from '@volontariapp/logger';
|
|
@@ -25,22 +25,22 @@ const logger = new Logger({
|
|
|
25
25
|
minLevel: 'info', // 'debug' | 'info' | 'warn' | 'error' | 'fatal'
|
|
26
26
|
});
|
|
27
27
|
|
|
28
|
-
logger.info('Worker
|
|
29
|
-
logger.error('
|
|
28
|
+
logger.info('Worker initialisé avec succès.');
|
|
29
|
+
logger.error('Échec de synchronisation des données.', new Error('Connection timeout'));
|
|
30
30
|
```
|
|
31
31
|
|
|
32
|
-
### 2. NestJS
|
|
32
|
+
### 2. Projet NestJS
|
|
33
33
|
|
|
34
|
-
|
|
34
|
+
Le logger respecte l'interface `LoggerService` de NestJS de manière native (`log`, `error`, `warn`, `debug`, `verbose`). Vous pouvez l'utiliser comme logger global de l'application ou via l'injection de dépendances.
|
|
35
35
|
|
|
36
|
-
**Application
|
|
36
|
+
**Initialisation de l'Application** (`main.ts`) :
|
|
37
37
|
```typescript
|
|
38
38
|
import { NestFactory } from '@nestjs/core';
|
|
39
39
|
import { AppModule } from './app.module';
|
|
40
40
|
import { Logger } from '@volontariapp/logger';
|
|
41
41
|
|
|
42
42
|
async function bootstrap() {
|
|
43
|
-
//
|
|
43
|
+
// Utilise le format JSON pour des logs structurés dans les applications NestJS
|
|
44
44
|
const appLogger = new Logger({ format: 'json', context: 'NestApplication' });
|
|
45
45
|
|
|
46
46
|
const app = await NestFactory.create(AppModule, {
|
|
@@ -52,7 +52,7 @@ async function bootstrap() {
|
|
|
52
52
|
bootstrap();
|
|
53
53
|
```
|
|
54
54
|
|
|
55
|
-
**
|
|
55
|
+
**Module d'Injection de Dépendances** (`logger.module.ts`) :
|
|
56
56
|
```typescript
|
|
57
57
|
import { Module, Global } from '@nestjs/common';
|
|
58
58
|
import { Logger } from '@volontariapp/logger';
|
|
@@ -72,34 +72,34 @@ const customLogger = new Logger({ format: 'json', context: 'RequestScope' });
|
|
|
72
72
|
export class LoggerModule {}
|
|
73
73
|
```
|
|
74
74
|
|
|
75
|
-
### 3. React Native
|
|
75
|
+
### 3. Projet React Native
|
|
76
76
|
|
|
77
|
-
|
|
77
|
+
Sur React Native, il est souvent plus simple de lire des logs texte dans la console Metro Bundler plutôt qu'un objet JSON complet. Vous pouvez l'instancier localement pour un composant spécifique ou en Singleton pour toute l'application.
|
|
78
78
|
|
|
79
79
|
```typescript
|
|
80
80
|
import { Logger } from '@volontariapp/logger';
|
|
81
81
|
|
|
82
82
|
export const logger = new Logger({
|
|
83
83
|
context: 'MobileApp',
|
|
84
|
-
format: 'text', //
|
|
84
|
+
format: 'text', // Recommandé pour la console metro bundler de react native
|
|
85
85
|
minLevel: 'debug',
|
|
86
86
|
});
|
|
87
87
|
|
|
88
|
-
//
|
|
88
|
+
// À l'intérieur d'un composant React
|
|
89
89
|
export const HomeScreen = () => {
|
|
90
|
-
logger.debug('HomeScreen
|
|
90
|
+
logger.debug('HomeScreen monté', { timestamp: Date.now() });
|
|
91
91
|
|
|
92
92
|
const handlePress = () => {
|
|
93
|
-
logger.info('
|
|
93
|
+
logger.info('Bouton cliqué');
|
|
94
94
|
};
|
|
95
95
|
|
|
96
96
|
return <Action handlePress={handlePress} />;
|
|
97
97
|
};
|
|
98
98
|
```
|
|
99
99
|
|
|
100
|
-
##
|
|
100
|
+
## Fonctionnalités
|
|
101
101
|
|
|
102
|
-
- **JSON &
|
|
103
|
-
- **Log
|
|
104
|
-
- **NestJS
|
|
105
|
-
- **Micro-metadata
|
|
102
|
+
- **Sortie JSON & Texte** : Changez de format selon l'environnement (`json` pour Grafana/ELK, `text` pour le dev local).
|
|
103
|
+
- **Niveaux de Log** : Niveaux standards (`debug`, `info`, `warn`, `error`, `fatal`).
|
|
104
|
+
- **Compatible NestJS** : Les méthodes `log` et `verbose` garantissent la compatibilité avec l'interface NestJS.
|
|
105
|
+
- **Micro-metadata** : Passez facilement des objets de métadonnées. `logger.info('User Login', { userId: 1 })`.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@volontariapp/logger",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.7",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public",
|
|
6
6
|
"provenance": true
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"@jest/globals": "^30.3.0",
|
|
38
38
|
"@types/jest": "^30.0.0",
|
|
39
39
|
"@types/node": "^25.5.2",
|
|
40
|
-
"@volontariapp/testing": "1.0.
|
|
40
|
+
"@volontariapp/testing": "1.0.3",
|
|
41
41
|
"jest": "^30.3.0",
|
|
42
42
|
"ts-jest": "^29.4.9",
|
|
43
43
|
"typescript": "5.7.3"
|