@prairielearn/logger 1.0.0
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/.turbo/turbo-build.log +0 -0
- package/README.md +28 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +25 -0
- package/dist/index.js.map +1 -0
- package/package.json +19 -0
- package/src/index.ts +26 -0
- package/tsconfig.json +8 -0
|
File without changes
|
package/README.md
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# `@prairielearn/logger`
|
|
2
|
+
|
|
3
|
+
Provides a shared [Winston](https://github.com/winstonjs/winston) instance for all logging.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
import { logger, addFileLogging } from '@prairielearn/logger';
|
|
9
|
+
|
|
10
|
+
// Log all messages to a file.
|
|
11
|
+
addFileLogging({ filename: '/path/to/file.log' });
|
|
12
|
+
|
|
13
|
+
// Log all errors to another file.
|
|
14
|
+
addFileLogging({ filename: '/path/to/errors.log', level: 'error' });
|
|
15
|
+
|
|
16
|
+
logger.debug('verbose');
|
|
17
|
+
logger.verbose('verbose');
|
|
18
|
+
logger.info('info');
|
|
19
|
+
logger.warn('warn');
|
|
20
|
+
|
|
21
|
+
try {
|
|
22
|
+
await mightError();
|
|
23
|
+
} catch (err) {
|
|
24
|
+
// When logging an error, ensure that the first argument is a string. You can
|
|
25
|
+
// pass the error object as the second argument if desired.
|
|
26
|
+
logger.error('An error occurred', err);
|
|
27
|
+
}
|
|
28
|
+
```
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.addFileLogging = exports.logger = void 0;
|
|
7
|
+
const winston_1 = __importDefault(require("winston"));
|
|
8
|
+
const logform_1 = require("logform");
|
|
9
|
+
exports.logger = winston_1.default.createLogger({
|
|
10
|
+
transports: [
|
|
11
|
+
new winston_1.default.transports.Console({
|
|
12
|
+
level: 'info',
|
|
13
|
+
format: logform_1.format.combine(logform_1.format.colorize(), logform_1.format.simple()),
|
|
14
|
+
}),
|
|
15
|
+
],
|
|
16
|
+
});
|
|
17
|
+
function addFileLogging(options) {
|
|
18
|
+
exports.logger.add(new winston_1.default.transports.File({
|
|
19
|
+
filename: options.filename,
|
|
20
|
+
level: options.level ?? 'debug',
|
|
21
|
+
format: logform_1.format.combine(logform_1.format.timestamp(), logform_1.format.json()),
|
|
22
|
+
}));
|
|
23
|
+
}
|
|
24
|
+
exports.addFileLogging = addFileLogging;
|
|
25
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,sDAA8B;AAC9B,qCAAiC;AAEpB,QAAA,MAAM,GAAG,iBAAO,CAAC,YAAY,CAAC;IACzC,UAAU,EAAE;QACV,IAAI,iBAAO,CAAC,UAAU,CAAC,OAAO,CAAC;YAC7B,KAAK,EAAE,MAAM;YACb,MAAM,EAAE,gBAAM,CAAC,OAAO,CAAC,gBAAM,CAAC,QAAQ,EAAE,EAAE,gBAAM,CAAC,MAAM,EAAE,CAAC;SAC3D,CAAC;KACH;CACF,CAAC,CAAC;AAOH,SAAgB,cAAc,CAAC,OAA8B;IAC3D,cAAM,CAAC,GAAG,CACR,IAAI,iBAAO,CAAC,UAAU,CAAC,IAAI,CAAC;QAC1B,QAAQ,EAAE,OAAO,CAAC,QAAQ;QAC1B,KAAK,EAAE,OAAO,CAAC,KAAK,IAAI,OAAO;QAC/B,MAAM,EAAE,gBAAM,CAAC,OAAO,CAAC,gBAAM,CAAC,SAAS,EAAE,EAAE,gBAAM,CAAC,IAAI,EAAE,CAAC;KAC1D,CAAC,CACH,CAAC;AACJ,CAAC;AARD,wCAQC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@prairielearn/logger",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"main": "./dist/index.js",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"build": "tsc",
|
|
7
|
+
"dev": "tsc --watch --preserveWatchOutput"
|
|
8
|
+
},
|
|
9
|
+
"devDependencies": {
|
|
10
|
+
"@prairielearn/tsconfig": "*",
|
|
11
|
+
"@types/node": "^18.11.18",
|
|
12
|
+
"typescript": "^4.9.4"
|
|
13
|
+
},
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"logform": "^2.5.1",
|
|
16
|
+
"winston": "^3.8.2",
|
|
17
|
+
"zod": "^3.20.2"
|
|
18
|
+
}
|
|
19
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import winston from 'winston';
|
|
2
|
+
import { format } from 'logform';
|
|
3
|
+
|
|
4
|
+
export const logger = winston.createLogger({
|
|
5
|
+
transports: [
|
|
6
|
+
new winston.transports.Console({
|
|
7
|
+
level: 'info',
|
|
8
|
+
format: format.combine(format.colorize(), format.simple()),
|
|
9
|
+
}),
|
|
10
|
+
],
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
interface AddFileLoggingOptions {
|
|
14
|
+
filename: string;
|
|
15
|
+
level?: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function addFileLogging(options: AddFileLoggingOptions) {
|
|
19
|
+
logger.add(
|
|
20
|
+
new winston.transports.File({
|
|
21
|
+
filename: options.filename,
|
|
22
|
+
level: options.level ?? 'debug',
|
|
23
|
+
format: format.combine(format.timestamp(), format.json()),
|
|
24
|
+
})
|
|
25
|
+
);
|
|
26
|
+
}
|