@orion-js/logger 3.1.0-alpha.9
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 +21 -0
- package/jest.config.js +8 -0
- package/lib/formats.d.ts +6 -0
- package/lib/formats.js +38 -0
- package/lib/helpers/getFileName.d.ts +3 -0
- package/lib/helpers/getFileName.js +23 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +14 -0
- package/lib/index.test.d.ts +1 -0
- package/lib/index.test.js +11 -0
- package/lib/logger.d.ts +16 -0
- package/lib/logger.js +65 -0
- package/lib/types/index.d.ts +0 -0
- package/lib/types/index.js +0 -0
- package/package.json +29 -0
- package/tsconfig.json +15 -0
- package/yarn-error.log +2688 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 Orionjs Team
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/jest.config.js
ADDED
package/lib/formats.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { transports } from 'winston';
|
|
2
|
+
export declare const sentryFormat: import("logform").FormatWrap;
|
|
3
|
+
export declare const textConsoleFormat: import("logform").Format;
|
|
4
|
+
export declare const textConsoleTransport: transports.ConsoleTransportInstance;
|
|
5
|
+
export declare const jsonConsoleFormat: import("logform").Format;
|
|
6
|
+
export declare const jsonConsoleTransport: transports.ConsoleTransportInstance;
|
package/lib/formats.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
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.jsonConsoleTransport = exports.jsonConsoleFormat = exports.textConsoleTransport = exports.textConsoleFormat = exports.sentryFormat = void 0;
|
|
7
|
+
const winston_1 = require("winston");
|
|
8
|
+
const util_1 = __importDefault(require("util"));
|
|
9
|
+
const { metadata, timestamp, json, colorize, combine, printf } = winston_1.format;
|
|
10
|
+
const metaError = (0, winston_1.format)(info => {
|
|
11
|
+
if (info.metadata && info.metadata.error && info.metadata.error instanceof Error) {
|
|
12
|
+
info.stack = info.metadata.error.stack;
|
|
13
|
+
info.metadata.error = info.metadata.error.message;
|
|
14
|
+
}
|
|
15
|
+
return info;
|
|
16
|
+
});
|
|
17
|
+
exports.sentryFormat = (0, winston_1.format)(info => {
|
|
18
|
+
const { path, label, ...extra } = info;
|
|
19
|
+
return {
|
|
20
|
+
...extra,
|
|
21
|
+
tags: {
|
|
22
|
+
path: path || '',
|
|
23
|
+
request_id: label
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
});
|
|
27
|
+
exports.textConsoleFormat = combine(colorize(), metadata({ fillExcept: ['fileName', 'level', 'message', 'stack'] }), metaError(), timestamp(), printf(info => {
|
|
28
|
+
return `[${info.level}] [${info.timestamp}] ${info.fileName ? `[${info.fileName}]` : ''} ${info.message} ${info.stack ? `\n${info.stack}` : ''} ${util_1.default.inspect(info.metadata)}`;
|
|
29
|
+
}));
|
|
30
|
+
exports.textConsoleTransport = new winston_1.transports.Console({
|
|
31
|
+
handleExceptions: true,
|
|
32
|
+
format: exports.textConsoleFormat
|
|
33
|
+
});
|
|
34
|
+
exports.jsonConsoleFormat = combine(metadata({ fillExcept: ['fileName', 'level', 'message'] }), metaError(), timestamp(), json({ replacer: null, space: 2 }));
|
|
35
|
+
exports.jsonConsoleTransport = new winston_1.transports.Console({
|
|
36
|
+
handleExceptions: true,
|
|
37
|
+
format: exports.jsonConsoleFormat
|
|
38
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.setFileName = exports.improveFileName = exports.getFileName = void 0;
|
|
4
|
+
const getFileName = () => {
|
|
5
|
+
const stack = new Error().stack;
|
|
6
|
+
const lines = stack.split('\n');
|
|
7
|
+
const filePath = lines[4].split('(')[1].split(')')[0];
|
|
8
|
+
return (0, exports.improveFileName)(filePath);
|
|
9
|
+
};
|
|
10
|
+
exports.getFileName = getFileName;
|
|
11
|
+
const improveFileName = (path) => {
|
|
12
|
+
if (path.includes('orionjs/packages')) {
|
|
13
|
+
return path.replace(/^.+\/orionjs\/packages\//, '@orion-js/');
|
|
14
|
+
}
|
|
15
|
+
return path;
|
|
16
|
+
};
|
|
17
|
+
exports.improveFileName = improveFileName;
|
|
18
|
+
const setFileName = (metadata) => {
|
|
19
|
+
if (metadata.fileName)
|
|
20
|
+
return;
|
|
21
|
+
metadata.fileName = (0, exports.getFileName)();
|
|
22
|
+
};
|
|
23
|
+
exports.setFileName = setFileName;
|
package/lib/index.d.ts
ADDED
package/lib/index.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
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" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
__exportStar(require("./formats"), exports);
|
|
14
|
+
__exportStar(require("./logger"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const logger_1 = require("./logger");
|
|
4
|
+
(0, logger_1.setLogLevel)('debug');
|
|
5
|
+
describe('Log', () => {
|
|
6
|
+
test('Test logs', () => {
|
|
7
|
+
logger_1.logger.debug('debug');
|
|
8
|
+
logger_1.logger.info('info');
|
|
9
|
+
logger_1.logger.warn('warn');
|
|
10
|
+
});
|
|
11
|
+
});
|
package/lib/logger.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import winston from 'winston';
|
|
3
|
+
export declare const winstonLogger: winston.Logger;
|
|
4
|
+
export declare const configureLogger: (options: winston.LoggerOptions) => void;
|
|
5
|
+
export declare const setLogLevel: (level: string) => string;
|
|
6
|
+
export declare const addTransport: (transport: winston.transport) => winston.Logger;
|
|
7
|
+
export declare const getLogger: (context: string) => winston.Logger;
|
|
8
|
+
export declare const logger: {
|
|
9
|
+
debug: (message: string, metadata?: any) => winston.Logger;
|
|
10
|
+
info: (message: string, metadata?: any) => winston.Logger;
|
|
11
|
+
warn: (message: string, metadata?: any) => winston.Logger;
|
|
12
|
+
error: (message: string, error: Error, metadata?: any) => winston.Logger;
|
|
13
|
+
addContext: (module: NodeJS.Module) => any;
|
|
14
|
+
addMetadata: (metadata: any) => any;
|
|
15
|
+
};
|
|
16
|
+
export declare const addModuleContext: (moduleName: string, metadata: any) => void;
|
package/lib/logger.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.addModuleContext = exports.logger = exports.getLogger = exports.addTransport = exports.setLogLevel = exports.configureLogger = exports.winstonLogger = void 0;
|
|
4
|
+
const winston_1 = require("winston");
|
|
5
|
+
const formats_1 = require("./formats");
|
|
6
|
+
const getFileName_1 = require("./helpers/getFileName");
|
|
7
|
+
const transports = [
|
|
8
|
+
process.env.ORION_DEV ? formats_1.textConsoleTransport : formats_1.jsonConsoleTransport
|
|
9
|
+
];
|
|
10
|
+
exports.winstonLogger = (0, winston_1.createLogger)({
|
|
11
|
+
levels: winston_1.config.npm.levels,
|
|
12
|
+
handleExceptions: true,
|
|
13
|
+
format: winston_1.format.errors({ stack: true }),
|
|
14
|
+
transports: transports
|
|
15
|
+
});
|
|
16
|
+
const configureLogger = (options) => {
|
|
17
|
+
return exports.winstonLogger.configure(options);
|
|
18
|
+
};
|
|
19
|
+
exports.configureLogger = configureLogger;
|
|
20
|
+
const setLogLevel = (level) => {
|
|
21
|
+
return (exports.winstonLogger.level = level);
|
|
22
|
+
};
|
|
23
|
+
exports.setLogLevel = setLogLevel;
|
|
24
|
+
const addTransport = (transport) => {
|
|
25
|
+
return exports.winstonLogger.add(transport);
|
|
26
|
+
};
|
|
27
|
+
exports.addTransport = addTransport;
|
|
28
|
+
const getLogger = (context) => {
|
|
29
|
+
return exports.winstonLogger.child({ context });
|
|
30
|
+
};
|
|
31
|
+
exports.getLogger = getLogger;
|
|
32
|
+
const createLogger = (logger) => {
|
|
33
|
+
return {
|
|
34
|
+
debug: (message, metadata = {}) => {
|
|
35
|
+
(0, getFileName_1.setFileName)(metadata);
|
|
36
|
+
return logger.debug(message, metadata);
|
|
37
|
+
},
|
|
38
|
+
info: (message, metadata = {}) => {
|
|
39
|
+
(0, getFileName_1.setFileName)(metadata);
|
|
40
|
+
return logger.info(message, metadata);
|
|
41
|
+
},
|
|
42
|
+
warn: (message, metadata = {}) => {
|
|
43
|
+
(0, getFileName_1.setFileName)(metadata);
|
|
44
|
+
return logger.warn(message, metadata);
|
|
45
|
+
},
|
|
46
|
+
error: (message, error, metadata = {}) => {
|
|
47
|
+
(0, getFileName_1.setFileName)(metadata);
|
|
48
|
+
return logger.error(message, { error, ...metadata });
|
|
49
|
+
},
|
|
50
|
+
addContext: (module) => {
|
|
51
|
+
if (module.id) {
|
|
52
|
+
const split = String(module.id).split('.orion/build/');
|
|
53
|
+
const fileName = split.length > 1 ? split[1] : split[0];
|
|
54
|
+
return createLogger(logger.child({ fileName }));
|
|
55
|
+
}
|
|
56
|
+
return createLogger(logger.child({}));
|
|
57
|
+
},
|
|
58
|
+
addMetadata: (metadata) => {
|
|
59
|
+
return createLogger(logger.child(metadata));
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
exports.logger = createLogger(exports.winstonLogger);
|
|
64
|
+
const addModuleContext = (moduleName, metadata) => { };
|
|
65
|
+
exports.addModuleContext = addModuleContext;
|
|
File without changes
|
|
File without changes
|
package/package.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@orion-js/logger",
|
|
3
|
+
"version": "3.1.0-alpha.9",
|
|
4
|
+
"main": "lib/index.js",
|
|
5
|
+
"author": "nicolaslopezj",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"test": "ORION_DEV=1 jest",
|
|
9
|
+
"prepare": "yarn run build",
|
|
10
|
+
"clean": "rm -rf ./lib",
|
|
11
|
+
"build": "yarn run clean && tsc",
|
|
12
|
+
"watch": "tsc -w",
|
|
13
|
+
"upgrade-interactive": "yarn upgrade-interactive"
|
|
14
|
+
},
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"object-hash": "^2.2.0",
|
|
17
|
+
"winston": "^3.6.0"
|
|
18
|
+
},
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"@types/jest": "^27.0.2",
|
|
21
|
+
"jest": "27.3.1",
|
|
22
|
+
"ts-jest": "27.0.7",
|
|
23
|
+
"typescript": "^4.4.4"
|
|
24
|
+
},
|
|
25
|
+
"publishConfig": {
|
|
26
|
+
"access": "public"
|
|
27
|
+
},
|
|
28
|
+
"gitHead": "65ebf7047a46aa5e93e9066d82ca70f81d69f10c"
|
|
29
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"strict": false,
|
|
4
|
+
"outDir": "./lib",
|
|
5
|
+
"rootDir": "./src",
|
|
6
|
+
"module": "commonjs",
|
|
7
|
+
"target": "es2020",
|
|
8
|
+
"moduleResolution": "node",
|
|
9
|
+
"lib": ["es2020"],
|
|
10
|
+
"declaration": true,
|
|
11
|
+
"esModuleInterop": true,
|
|
12
|
+
"skipLibCheck": true,
|
|
13
|
+
"forceConsistentCasingInFileNames": true
|
|
14
|
+
}
|
|
15
|
+
}
|