@villedemontreal/logger 6.5.1
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/LICENSE +22 -0
- package/README.md +164 -0
- package/dist/src/config/configs.d.ts +118 -0
- package/dist/src/config/configs.js +167 -0
- package/dist/src/config/configs.js.map +1 -0
- package/dist/src/config/constants.d.ts +60 -0
- package/dist/src/config/constants.js +60 -0
- package/dist/src/config/constants.js.map +1 -0
- package/dist/src/consoleStream.d.ts +8 -0
- package/dist/src/consoleStream.js +29 -0
- package/dist/src/consoleStream.js.map +1 -0
- package/dist/src/index.d.ts +3 -0
- package/dist/src/index.js +16 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/lazyLogger.d.ts +21 -0
- package/dist/src/lazyLogger.js +46 -0
- package/dist/src/lazyLogger.js.map +1 -0
- package/dist/src/logger.d.ts +169 -0
- package/dist/src/logger.js +501 -0
- package/dist/src/logger.js.map +1 -0
- package/dist/src/logger.test.d.ts +8 -0
- package/dist/src/logger.test.js +564 -0
- package/dist/src/logger.test.js.map +1 -0
- package/package.json +67 -0
- package/src/config/configs.ts +195 -0
- package/src/config/constants.ts +78 -0
- package/src/consoleStream.ts +29 -0
- package/src/index.ts +3 -0
- package/src/lazyLogger.ts +50 -0
- package/src/logger.test.ts +673 -0
- package/src/logger.ts +551 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
|
|
2
|
+
MIT License
|
|
3
|
+
|
|
4
|
+
Copyright (c) Ville de Montréal and other contributors
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
# @villedemontreal/logger
|
|
2
|
+
|
|
3
|
+
Logger pour applications Node.
|
|
4
|
+
|
|
5
|
+
Ajoute automatiquement aux logs des informations pertinentes telles que les Correlation Ids, le
|
|
6
|
+
nom de l'application, etc.
|
|
7
|
+
|
|
8
|
+
_Important_ : La configuration `correlationIdProvider` est requise! Votre application
|
|
9
|
+
(ou API) _doit_ passer le provider à utiliser...
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
```shell
|
|
15
|
+
npm install @villedemontreal/logger
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Usage
|
|
19
|
+
|
|
20
|
+
1. Nous suggérons de créer, dans votre projet, un fichier "`src/utils/logger.ts`" initialisant la librairie du Logger.
|
|
21
|
+
Puis créer une function exportée `createLogger` que vous utiliserez dans vos divers composants, pour
|
|
22
|
+
créer un Logger associé. Le but de cette indirection est de s'assurer que les Loggers créés sont bien configurés.
|
|
23
|
+
|
|
24
|
+
```typescript
|
|
25
|
+
import { correlationIdService } from '@villemontreal/core-correlation-id-nodejs-lib';
|
|
26
|
+
import {
|
|
27
|
+
createLogger as createLoggerBase,
|
|
28
|
+
ILogger,
|
|
29
|
+
initLogger,
|
|
30
|
+
LoggerConfigs
|
|
31
|
+
} from '@villemontreal/core-utils-logger-nodejs-lib';
|
|
32
|
+
import { configs } from '../../config/configs';
|
|
33
|
+
|
|
34
|
+
let loggerLibInitialised = false;
|
|
35
|
+
|
|
36
|
+
function initLoggerConfigs() {
|
|
37
|
+
const loggerConfig: LoggerConfigs = new LoggerConfigs(() => correlationIdService.getId());
|
|
38
|
+
loggerConfig.setLogDirectory(configs.logging.dir);
|
|
39
|
+
loggerConfig.setLogLevel(configs.logging.level);
|
|
40
|
+
loggerConfig.setSlowerLogToFileToo(configs.logging.logToFile);
|
|
41
|
+
loggerConfig.setLogHumanReadableinConsole(configs.logging.humanReadableInConsole);
|
|
42
|
+
loggerConfig.setAddStackTraceToErrorMessagesInDev(configs.logging.addStackTraceToErrorMessagesInDev);
|
|
43
|
+
loggerConfig.setLogSource(configs.logging.logSource);
|
|
44
|
+
loggerConfig.setLogRotateFilesNbr(configs.logging.logRotateFilesNbr);
|
|
45
|
+
loggerConfig.setLogRotateThresholdMB(configs.logging.logRotateThresholdMB);
|
|
46
|
+
loggerConfig.setLogRotateMaxTotalSizeMB(configs.logging.logRotateMaxTotalSizeMB);
|
|
47
|
+
|
|
48
|
+
initLogger(loggerConfig);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function createLogger(name: string): ILogger {
|
|
52
|
+
if (!loggerLibInitialised) {
|
|
53
|
+
initLoggerConfigs();
|
|
54
|
+
loggerLibInitialised = true;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return createLoggerBase(name);
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
2. Si c'est une _librairie_ que vous développer (voir [core-nodejs-lib-template](https://bitbucket.org/villemontreal/core-nodejs-lib-template)), vous aurez aussi ce fichier "`src/utils/logger.ts`"
|
|
62
|
+
mais il ne fera qu'utiliser le "`Logger Creator`" que vous aurez _vous-mêmes_ reçu en configuration! :
|
|
63
|
+
|
|
64
|
+
```typescript
|
|
65
|
+
import { LoggerConfigs, ILogger, Logger, LazyLogger, LogLevel } from '@villemontreal/core-utils-logger-nodejs-lib';
|
|
66
|
+
import { configs } from '../config/configs';
|
|
67
|
+
|
|
68
|
+
export function createLogger(name: string): ILogger {
|
|
69
|
+
return new LazyLogger(name, (name: string) => {
|
|
70
|
+
return configs.loggerCreator(name);
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Notez ici l'utilisation de `LazyLogger` et non de `Logger`... Ceci est requis car votre propre librairie
|
|
76
|
+
pourrait ne pas encore avoir été configurée lorsque le premier appel à "_`let logger = createLogger("someName")`_"! Le `LazyLogger` ne va valider les configurations que _lors du premier log_.
|
|
77
|
+
|
|
78
|
+
## Logger dans un fichier
|
|
79
|
+
|
|
80
|
+
En appelant "`setSlowerLogToFileToo(true)`", vous faites en sorte que les logs se feront dans un fichier en plus de se faire sur le "stdout" standard (la "console"). Vous pouvez spécifier
|
|
81
|
+
le répertoire où les logs autont lieu en utilisant "`setLogDirectory(...)`", qui a la valeur "`./log`" par défaut).
|
|
82
|
+
|
|
83
|
+
Notez que de logger dans un fichier ne devrait être fait qu'en _local_. Sur les autres environnements, nous utilisong Graylog qui utilise ce qui est écrit _dans la console_ pour ses logs!
|
|
84
|
+
|
|
85
|
+
## Changer le niveau de log sans redémarrer l'application
|
|
86
|
+
|
|
87
|
+
```
|
|
88
|
+
import { LogLevel } from '@villemontreal/core-utils-general-nodejs-lib';
|
|
89
|
+
import { setGlobalLogLevel } from '@villemontreal/core-utils-logger-nodejs-lib';
|
|
90
|
+
|
|
91
|
+
setGlobalLogLevel(LogLevel.DEBUG);
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
# Builder le projet
|
|
95
|
+
|
|
96
|
+
**Note**: Sur Linux/Mac assurz-vous que le fichier `run` est exécutable. Autrement, lancez `chmod +x ./run`.
|
|
97
|
+
|
|
98
|
+
Pour lancer le build :
|
|
99
|
+
|
|
100
|
+
- > `run compile` ou `./run compile` (sur Linux/Mac)
|
|
101
|
+
|
|
102
|
+
Pour lancer les tests :
|
|
103
|
+
|
|
104
|
+
- > `run test` ou `./run test` (sur Linux/Mac)
|
|
105
|
+
|
|
106
|
+
# Mode Watch
|
|
107
|
+
|
|
108
|
+
Lors du développement, il est possible de lancer `run watch` (ou `./run watch` sur Linux/mac) dans un terminal
|
|
109
|
+
externe pour démarrer la compilation incrémentale. Il est alors possible de lancer certaines _launch configuration_
|
|
110
|
+
comme `Debug current tests file - fast` dans VsCode et ainsi déboguer le fichier de tests présentement ouvert sans
|
|
111
|
+
avoir à (re)compiler au préalable (la compilation incrémentale s'en sera chargé).
|
|
112
|
+
|
|
113
|
+
Notez que, par défaut, des _notifications desktop_ sont activées pour indiquer visuellement si la compilation
|
|
114
|
+
incrémentale est un succès ou si une erreur a été trouvée. Vous pouvez désactiver ces notifications en utilisant
|
|
115
|
+
`run watch --dn` (`d`isable `n`otifications).
|
|
116
|
+
|
|
117
|
+
# Déboguer le projet
|
|
118
|
+
|
|
119
|
+
Trois "_launch configurations_" sont founies pour déboguer le projet dans VSCode :
|
|
120
|
+
|
|
121
|
+
- "`Debug all tests`", la launch configuration par défaut. Lance les tests en mode debug. Vous pouvez mettre
|
|
122
|
+
des breakpoints et ils seront respectés.
|
|
123
|
+
|
|
124
|
+
- "`Debug a test file`". Lance _un_ fichier de tests en mode debug. Vous pouvez mettre
|
|
125
|
+
des breakpoints et ils seront respectés. Pour changer le fichier de tests à être exécuté, vous devez modifier la ligne appropriée dans le fichier "`.vscode/launch.json`".
|
|
126
|
+
|
|
127
|
+
- "`Debug current tests file`". Lance le fichier de tests _présentement ouvert_ dans VSCode en mode debug. Effectue la compîlation au préalable.
|
|
128
|
+
|
|
129
|
+
- "`Debug current tests file - fast`". Lance le fichier de tests _présentement ouvert_ dans VSCode en mode debug. Aucune compilation
|
|
130
|
+
n'est effectuée au préalable. Cette launch configuration doit être utilisée lorsque la compilation incrémentale roule (voir la section "`Mode Watch`" plus haut)
|
|
131
|
+
|
|
132
|
+
## Artifact Nexus privé, lors du développement
|
|
133
|
+
|
|
134
|
+
Lors du développement d'une nouvelle fonctionnalité, sur une branche `feature`, il peut parfois être
|
|
135
|
+
utile de déployer une version temporaire de la librairie dans Nexus. Ceci permet de bien tester
|
|
136
|
+
l'utilisation de la librairie modifiée dans un vrai projet, ou même dans une autre librairie
|
|
137
|
+
elle-même par la suite utilisée dans un vrai projet.
|
|
138
|
+
|
|
139
|
+
Si le code à tester est terminé et prêt à être mis en commun avec d'autres développeurs, la solution
|
|
140
|
+
de base, comme spécifiée à la section précédante, est de merger sur `develop`: ceci créera
|
|
141
|
+
automatiquement un artifact "`-pre-build`" dans Nexus. Cependant, si le code est encore en développement
|
|
142
|
+
et vous désirez éviter de polluer la branche commune `develop` avec du code temporaire, il y a une
|
|
143
|
+
solution permettant de générer un artifact "`[votre prénom]-pre-build`" temporaire dans Nexus,
|
|
144
|
+
à partir d'une branche `feature` directement:
|
|
145
|
+
|
|
146
|
+
1. Checkoutez votre branche `feature` dans une branche nommée "`nexus`". Ce nom est
|
|
147
|
+
important et correspond à une entrée dans le `Jenkinsfile`.
|
|
148
|
+
2. Une fois sur la branche `nexus`, ajoutez un suffixe "`-[votre prénom]`" à
|
|
149
|
+
la version dans le `package.json`, par exemple: "`5.15.0-roger`".
|
|
150
|
+
Ceci permet d'éviter tout conflit dans Nexus et exprime clairement qu'il
|
|
151
|
+
s'agit d'une version temporaire pour votre développement privé.
|
|
152
|
+
3. Commitez et poussez la branche `nexus`.
|
|
153
|
+
4. Une fois le build Jenkins terminé, un artifact pour votre version aura été
|
|
154
|
+
déployé dans Nexus.
|
|
155
|
+
|
|
156
|
+
**Notez** que, lors du développement dans une branche `feature`, l'utilisation d'un simple
|
|
157
|
+
`npm link` local peut souvent être suffisant! Mais cette solution a ses limites, par exemple si
|
|
158
|
+
vous désirez tester la librairie modifiée _dans un container Docker_.
|
|
159
|
+
|
|
160
|
+
# Aide / Contributions
|
|
161
|
+
|
|
162
|
+
Pour obtenir de l'aide avec cette librairie, vous pouvez poster sur la salle Google Chat [dev-discussions](https://chat.google.com/room/AAAASmiQveI).
|
|
163
|
+
|
|
164
|
+
Notez que les contributions sous forme de pull requests sont bienvenues.
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { LogLevel } from '../logger';
|
|
2
|
+
/**
|
|
3
|
+
* Logger Config
|
|
4
|
+
*/
|
|
5
|
+
export declare class LoggerConfigs {
|
|
6
|
+
/**
|
|
7
|
+
* The correlation id provider.
|
|
8
|
+
* To set this is required.
|
|
9
|
+
*/
|
|
10
|
+
private correlationIdProvider;
|
|
11
|
+
/**
|
|
12
|
+
* Enable logging to a file.
|
|
13
|
+
* Default to false.
|
|
14
|
+
*/
|
|
15
|
+
private logToFile;
|
|
16
|
+
/**
|
|
17
|
+
* The directory where the potential
|
|
18
|
+
* log file will be written.
|
|
19
|
+
* Default to "./log".
|
|
20
|
+
*/
|
|
21
|
+
private logDir;
|
|
22
|
+
/**
|
|
23
|
+
* Log rotation file nb
|
|
24
|
+
*/
|
|
25
|
+
private logRotateFilesNbr;
|
|
26
|
+
/**
|
|
27
|
+
* Log rotation threshhold in MB
|
|
28
|
+
*/
|
|
29
|
+
private logRotateThresholdMB;
|
|
30
|
+
/**
|
|
31
|
+
* Log maximum total size in MB
|
|
32
|
+
*/
|
|
33
|
+
private logRotateMaxTotalSizeMB;
|
|
34
|
+
/**
|
|
35
|
+
* Logging level (info, debug, warning, error)
|
|
36
|
+
*
|
|
37
|
+
* Default value : DEBUG in DEV or WARNING otherwise.
|
|
38
|
+
*/
|
|
39
|
+
private logLevel;
|
|
40
|
+
/**
|
|
41
|
+
* Log in human readable form in the console.
|
|
42
|
+
*/
|
|
43
|
+
private logHumanReadableinConsole;
|
|
44
|
+
/**
|
|
45
|
+
* Add the stack trace to the error log in development
|
|
46
|
+
*/
|
|
47
|
+
private addStackTraceToErrorMessagesInDev;
|
|
48
|
+
/**
|
|
49
|
+
* Log the source of the error in the log message
|
|
50
|
+
*/
|
|
51
|
+
private logSource;
|
|
52
|
+
/**
|
|
53
|
+
* The Correlation Id provider is required.
|
|
54
|
+
*/
|
|
55
|
+
constructor(correlationIdProvider: () => string);
|
|
56
|
+
/**
|
|
57
|
+
* The current Correlation Id.
|
|
58
|
+
*/
|
|
59
|
+
get correlationId(): string;
|
|
60
|
+
/**
|
|
61
|
+
* Logging to a file?
|
|
62
|
+
*/
|
|
63
|
+
isLogToFile(): boolean;
|
|
64
|
+
/**
|
|
65
|
+
* Get the directory where the log files should be written
|
|
66
|
+
*/
|
|
67
|
+
getLogDirectory(): string;
|
|
68
|
+
/**
|
|
69
|
+
* Get the current logging level
|
|
70
|
+
*/
|
|
71
|
+
getLogLevel(): LogLevel;
|
|
72
|
+
isLogHumanReadableinConsole(): boolean;
|
|
73
|
+
isAddStackTraceToErrorMessagesInDev(): boolean;
|
|
74
|
+
isLogSource(): boolean;
|
|
75
|
+
getLogRotateFilesNbr(): number;
|
|
76
|
+
getLogRotateThresholdMB(): number;
|
|
77
|
+
getLogRotateMaxTotalSizeMB(): number;
|
|
78
|
+
/**
|
|
79
|
+
* Enable logging to a file in addition to
|
|
80
|
+
* logging to the standard output.
|
|
81
|
+
* This should probably be let to FALSE in our
|
|
82
|
+
* current network where Graylog is used : no
|
|
83
|
+
* log files are indeed required!
|
|
84
|
+
*/
|
|
85
|
+
setSlowerLogToFileToo(logToFile: boolean): void;
|
|
86
|
+
/**
|
|
87
|
+
* Set the directory where the log files should be written
|
|
88
|
+
*/
|
|
89
|
+
setLogDirectory(logDir: string): void;
|
|
90
|
+
/**
|
|
91
|
+
* Set the logging level
|
|
92
|
+
*/
|
|
93
|
+
setLogLevel(loglevel: LogLevel): void;
|
|
94
|
+
/**
|
|
95
|
+
* Set the logs in the console to be human readable
|
|
96
|
+
*/
|
|
97
|
+
setLogHumanReadableinConsole(logHumanReadableinConsole: boolean): void;
|
|
98
|
+
/**
|
|
99
|
+
* Set the stack trace to be logged in development environment
|
|
100
|
+
*/
|
|
101
|
+
setAddStackTraceToErrorMessagesInDev(addStackTraceToErrorMessagesInDev: boolean): void;
|
|
102
|
+
/**
|
|
103
|
+
* Set if the source of the error should be logged
|
|
104
|
+
*/
|
|
105
|
+
setLogSource(logSource: boolean): void;
|
|
106
|
+
/**
|
|
107
|
+
* Set the number of log files to rotate
|
|
108
|
+
*/
|
|
109
|
+
setLogRotateFilesNbr(logRotateFilesNb: number): void;
|
|
110
|
+
/**
|
|
111
|
+
* Set the log rotation threshhold.
|
|
112
|
+
*/
|
|
113
|
+
setLogRotateThresholdMB(logRotateThresholdMB: number): void;
|
|
114
|
+
/**
|
|
115
|
+
* Set the maximum total size of the logfile
|
|
116
|
+
*/
|
|
117
|
+
setLogRotateMaxTotalSizeMB(logRotateMaxTotalSizeMB: number): void;
|
|
118
|
+
}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LoggerConfigs = void 0;
|
|
4
|
+
const general_utils_1 = require("@villedemontreal/general-utils");
|
|
5
|
+
const logger_1 = require("../logger");
|
|
6
|
+
/**
|
|
7
|
+
* Logger Config
|
|
8
|
+
*/
|
|
9
|
+
class LoggerConfigs {
|
|
10
|
+
/**
|
|
11
|
+
* The Correlation Id provider is required.
|
|
12
|
+
*/
|
|
13
|
+
constructor(correlationIdProvider) {
|
|
14
|
+
/**
|
|
15
|
+
* The correlation id provider.
|
|
16
|
+
* To set this is required.
|
|
17
|
+
*/
|
|
18
|
+
this.correlationIdProvider = null;
|
|
19
|
+
/**
|
|
20
|
+
* Enable logging to a file.
|
|
21
|
+
* Default to false.
|
|
22
|
+
*/
|
|
23
|
+
this.logToFile = false;
|
|
24
|
+
/**
|
|
25
|
+
* The directory where the potential
|
|
26
|
+
* log file will be written.
|
|
27
|
+
* Default to "./log".
|
|
28
|
+
*/
|
|
29
|
+
this.logDir = './log';
|
|
30
|
+
/**
|
|
31
|
+
* Log rotation file nb
|
|
32
|
+
*/
|
|
33
|
+
this.logRotateFilesNbr = 30;
|
|
34
|
+
/**
|
|
35
|
+
* Log rotation threshhold in MB
|
|
36
|
+
*/
|
|
37
|
+
this.logRotateThresholdMB = 100;
|
|
38
|
+
/**
|
|
39
|
+
* Log maximum total size in MB
|
|
40
|
+
*/
|
|
41
|
+
this.logRotateMaxTotalSizeMB = 1000;
|
|
42
|
+
/**
|
|
43
|
+
* Logging level (info, debug, warning, error)
|
|
44
|
+
*
|
|
45
|
+
* Default value : DEBUG in DEV or WARNING otherwise.
|
|
46
|
+
*/
|
|
47
|
+
this.logLevel = process.env.NODE_ENV === general_utils_1.globalConstants.Environments.DEV ? logger_1.LogLevel.DEBUG : logger_1.LogLevel.WARNING;
|
|
48
|
+
/**
|
|
49
|
+
* Log in human readable form in the console.
|
|
50
|
+
*/
|
|
51
|
+
this.logHumanReadableinConsole = false;
|
|
52
|
+
/**
|
|
53
|
+
* Add the stack trace to the error log in development
|
|
54
|
+
*/
|
|
55
|
+
this.addStackTraceToErrorMessagesInDev = process.env.NODE_ENV === general_utils_1.globalConstants.Environments.DEV ? true : false;
|
|
56
|
+
/**
|
|
57
|
+
* Log the source of the error in the log message
|
|
58
|
+
*/
|
|
59
|
+
this.logSource = true;
|
|
60
|
+
if (!correlationIdProvider) {
|
|
61
|
+
throw new Error(`The Correlation Id provider is required.`);
|
|
62
|
+
}
|
|
63
|
+
this.correlationIdProvider = correlationIdProvider;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* The current Correlation Id.
|
|
67
|
+
*/
|
|
68
|
+
get correlationId() {
|
|
69
|
+
return this.correlationIdProvider();
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Logging to a file?
|
|
73
|
+
*/
|
|
74
|
+
isLogToFile() {
|
|
75
|
+
return this.logToFile;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Get the directory where the log files should be written
|
|
79
|
+
*/
|
|
80
|
+
getLogDirectory() {
|
|
81
|
+
return this.logDir;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Get the current logging level
|
|
85
|
+
*/
|
|
86
|
+
getLogLevel() {
|
|
87
|
+
return this.logLevel;
|
|
88
|
+
}
|
|
89
|
+
isLogHumanReadableinConsole() {
|
|
90
|
+
return this.logHumanReadableinConsole;
|
|
91
|
+
}
|
|
92
|
+
isAddStackTraceToErrorMessagesInDev() {
|
|
93
|
+
return this.addStackTraceToErrorMessagesInDev;
|
|
94
|
+
}
|
|
95
|
+
isLogSource() {
|
|
96
|
+
return this.logSource;
|
|
97
|
+
}
|
|
98
|
+
getLogRotateFilesNbr() {
|
|
99
|
+
return this.logRotateFilesNbr;
|
|
100
|
+
}
|
|
101
|
+
getLogRotateThresholdMB() {
|
|
102
|
+
return this.logRotateThresholdMB;
|
|
103
|
+
}
|
|
104
|
+
getLogRotateMaxTotalSizeMB() {
|
|
105
|
+
return this.logRotateMaxTotalSizeMB;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Enable logging to a file in addition to
|
|
109
|
+
* logging to the standard output.
|
|
110
|
+
* This should probably be let to FALSE in our
|
|
111
|
+
* current network where Graylog is used : no
|
|
112
|
+
* log files are indeed required!
|
|
113
|
+
*/
|
|
114
|
+
setSlowerLogToFileToo(logToFile) {
|
|
115
|
+
this.logToFile = logToFile;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Set the directory where the log files should be written
|
|
119
|
+
*/
|
|
120
|
+
setLogDirectory(logDir) {
|
|
121
|
+
this.logDir = logDir;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Set the logging level
|
|
125
|
+
*/
|
|
126
|
+
setLogLevel(loglevel) {
|
|
127
|
+
this.logLevel = loglevel;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Set the logs in the console to be human readable
|
|
131
|
+
*/
|
|
132
|
+
setLogHumanReadableinConsole(logHumanReadableinConsole) {
|
|
133
|
+
this.logHumanReadableinConsole = logHumanReadableinConsole;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Set the stack trace to be logged in development environment
|
|
137
|
+
*/
|
|
138
|
+
setAddStackTraceToErrorMessagesInDev(addStackTraceToErrorMessagesInDev) {
|
|
139
|
+
this.addStackTraceToErrorMessagesInDev = addStackTraceToErrorMessagesInDev;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Set if the source of the error should be logged
|
|
143
|
+
*/
|
|
144
|
+
setLogSource(logSource) {
|
|
145
|
+
this.logSource = logSource;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Set the number of log files to rotate
|
|
149
|
+
*/
|
|
150
|
+
setLogRotateFilesNbr(logRotateFilesNb) {
|
|
151
|
+
this.logRotateFilesNbr = logRotateFilesNb;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Set the log rotation threshhold.
|
|
155
|
+
*/
|
|
156
|
+
setLogRotateThresholdMB(logRotateThresholdMB) {
|
|
157
|
+
this.logRotateThresholdMB = logRotateThresholdMB;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Set the maximum total size of the logfile
|
|
161
|
+
*/
|
|
162
|
+
setLogRotateMaxTotalSizeMB(logRotateMaxTotalSizeMB) {
|
|
163
|
+
this.logRotateMaxTotalSizeMB = logRotateMaxTotalSizeMB;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
exports.LoggerConfigs = LoggerConfigs;
|
|
167
|
+
//# sourceMappingURL=configs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"configs.js","sourceRoot":"","sources":["../../../src/config/configs.ts"],"names":[],"mappings":";;;AAAA,kEAAiE;AACjE,sCAAqC;AAErC;;GAEG;AACH,MAAa,aAA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,sCA4LC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Library constants
|
|
3
|
+
*/
|
|
4
|
+
export declare class Constants {
|
|
5
|
+
/**
|
|
6
|
+
* The library root. When this library is used
|
|
7
|
+
* as a dependency in a project, the "libRoot"
|
|
8
|
+
* will be the path to the dependency folder,
|
|
9
|
+
* inside the "node_modules".
|
|
10
|
+
*/
|
|
11
|
+
libRoot: string;
|
|
12
|
+
/**
|
|
13
|
+
* The app root. When this library is used
|
|
14
|
+
* as a dependency in a project, the "appRoot"
|
|
15
|
+
* will be the path to the root project!
|
|
16
|
+
*/
|
|
17
|
+
appRoot: string;
|
|
18
|
+
constructor();
|
|
19
|
+
/**
|
|
20
|
+
* Logging constants
|
|
21
|
+
*/
|
|
22
|
+
get logging(): {
|
|
23
|
+
/**
|
|
24
|
+
* The properties that can be added to a log entry.
|
|
25
|
+
*/
|
|
26
|
+
properties: {
|
|
27
|
+
/**
|
|
28
|
+
* The type of log. Those types are specified in
|
|
29
|
+
* the following "logType" section.
|
|
30
|
+
*/
|
|
31
|
+
LOG_TYPE: string;
|
|
32
|
+
/**
|
|
33
|
+
* The version of the log type.
|
|
34
|
+
*/
|
|
35
|
+
LOG_TYPE_VERSION: string;
|
|
36
|
+
/**
|
|
37
|
+
* "Nom du composant logiciel"
|
|
38
|
+
*/
|
|
39
|
+
APP_NAME: string;
|
|
40
|
+
/**
|
|
41
|
+
* "Version du composant logiciel"
|
|
42
|
+
*/
|
|
43
|
+
APP_VERSION: string;
|
|
44
|
+
/**
|
|
45
|
+
* Correlation id
|
|
46
|
+
*/
|
|
47
|
+
CORRELATION_ID: string;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* The types of logs
|
|
51
|
+
*/
|
|
52
|
+
logType: {
|
|
53
|
+
/**
|
|
54
|
+
* The type for our Ville de Montréal logs.
|
|
55
|
+
*/
|
|
56
|
+
MONTREAL: string;
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
export declare let constants: Constants;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.constants = exports.Constants = void 0;
|
|
4
|
+
const app_root_path_1 = require("app-root-path");
|
|
5
|
+
const path = require("path");
|
|
6
|
+
/**
|
|
7
|
+
* Library constants
|
|
8
|
+
*/
|
|
9
|
+
class Constants {
|
|
10
|
+
constructor() {
|
|
11
|
+
// From the "dist/src/config" folder
|
|
12
|
+
this.libRoot = path.normalize(__dirname + '/../../..');
|
|
13
|
+
this.appRoot = app_root_path_1.path;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Logging constants
|
|
17
|
+
*/
|
|
18
|
+
get logging() {
|
|
19
|
+
return {
|
|
20
|
+
/**
|
|
21
|
+
* The properties that can be added to a log entry.
|
|
22
|
+
*/
|
|
23
|
+
properties: {
|
|
24
|
+
/**
|
|
25
|
+
* The type of log. Those types are specified in
|
|
26
|
+
* the following "logType" section.
|
|
27
|
+
*/
|
|
28
|
+
LOG_TYPE: 'logType',
|
|
29
|
+
/**
|
|
30
|
+
* The version of the log type.
|
|
31
|
+
*/
|
|
32
|
+
LOG_TYPE_VERSION: 'logTypeVersion',
|
|
33
|
+
/**
|
|
34
|
+
* "Nom du composant logiciel"
|
|
35
|
+
*/
|
|
36
|
+
APP_NAME: 'app',
|
|
37
|
+
/**
|
|
38
|
+
* "Version du composant logiciel"
|
|
39
|
+
*/
|
|
40
|
+
APP_VERSION: 'version',
|
|
41
|
+
/**
|
|
42
|
+
* Correlation id
|
|
43
|
+
*/
|
|
44
|
+
CORRELATION_ID: 'cid'
|
|
45
|
+
},
|
|
46
|
+
/**
|
|
47
|
+
* The types of logs
|
|
48
|
+
*/
|
|
49
|
+
logType: {
|
|
50
|
+
/**
|
|
51
|
+
* The type for our Ville de Montréal logs.
|
|
52
|
+
*/
|
|
53
|
+
MONTREAL: 'mtl'
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
exports.Constants = Constants;
|
|
59
|
+
exports.constants = new Constants();
|
|
60
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/config/constants.ts"],"names":[],"mappings":";;;AAAA,iDAAgD;AAChD,6BAA6B;AAE7B;;GAEG;AACH,MAAa,SAAS;IAgBpB;QACE,oCAAoC;QACpC,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,SAAS,GAAG,WAAW,CAAC,CAAC;QACvD,IAAI,CAAC,OAAO,GAAG,oBAAO,CAAC;IACzB,CAAC;IAED;;OAEG;IACH,IAAI,OAAO;QACT,OAAO;YACL;;eAEG;YACH,UAAU,EAAE;gBACV;;;mBAGG;gBACH,QAAQ,EAAE,SAAS;gBAEnB;;mBAEG;gBACH,gBAAgB,EAAE,gBAAgB;gBAElC;;mBAEG;gBACH,QAAQ,EAAE,KAAK;gBAEf;;mBAEG;gBACH,WAAW,EAAE,SAAS;gBAEtB;;mBAEG;gBACH,cAAc,EAAE,KAAK;aACtB;YAED;;eAEG;YACH,OAAO,EAAE;gBACP;;mBAEG;gBACH,QAAQ,EAAE,KAAK;aAChB;SACF,CAAC;IACJ,CAAC;CACF;AArED,8BAqEC;AAEU,QAAA,SAAS,GAAc,IAAI,SAAS,EAAE,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ConsoleStream = void 0;
|
|
4
|
+
const stream_1 = require("stream");
|
|
5
|
+
const prettyStream = require('bunyan-prettystream-circularsafe');
|
|
6
|
+
class ConsoleStream extends stream_1.Stream {
|
|
7
|
+
constructor(isLogHumanReadableinConsole) {
|
|
8
|
+
super();
|
|
9
|
+
this.isLogHumanReadableinConsole = isLogHumanReadableinConsole;
|
|
10
|
+
this.prettyStdOut = new prettyStream();
|
|
11
|
+
this.prettyStdOut.pipe(process.stdout);
|
|
12
|
+
}
|
|
13
|
+
write(data) {
|
|
14
|
+
// Using human readable format?
|
|
15
|
+
if (this.isLogHumanReadableinConsole) {
|
|
16
|
+
this.prettyStdOut.write(data);
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
let dataClean = data;
|
|
20
|
+
if (typeof dataClean !== 'string') {
|
|
21
|
+
dataClean = JSON.stringify(dataClean);
|
|
22
|
+
}
|
|
23
|
+
dataClean += '\n';
|
|
24
|
+
process.stdout.write(dataClean);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.ConsoleStream = ConsoleStream;
|
|
29
|
+
//# sourceMappingURL=consoleStream.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consoleStream.js","sourceRoot":"","sources":["../../src/consoleStream.ts"],"names":[],"mappings":";;;AAAA,mCAAgC;AAChC,MAAM,YAAY,GAAG,OAAO,CAAC,kCAAkC,CAAC,CAAC;AAEjE,MAAa,aAAc,SAAQ,eAAM;IAIvC,YAAY,2BAAoC;QAC9C,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,2BAA2B,GAAG,2BAA2B,CAAC;QAC/D,IAAI,CAAC,YAAY,GAAG,IAAI,YAAY,EAAE,CAAC;QACvC,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IACzC,CAAC;IAEM,KAAK,CAAC,IAAS;QACpB,+BAA+B;QAC/B,IAAI,IAAI,CAAC,2BAA2B,EAAE;YACpC,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;SAC/B;aAAM;YACL,IAAI,SAAS,GAAG,IAAI,CAAC;YACrB,IAAI,OAAO,SAAS,KAAK,QAAQ,EAAE;gBACjC,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;aACvC;YACD,SAAS,IAAI,IAAI,CAAC;YAElB,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;SACjC;IACH,CAAC;CACF;AAzBD,sCAyBC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
__exportStar(require("./config/configs"), exports);
|
|
14
|
+
__exportStar(require("./logger"), exports);
|
|
15
|
+
__exportStar(require("./lazyLogger"), exports);
|
|
16
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,mDAAiC;AACjC,2CAAyB;AACzB,+CAA6B"}
|