@celljs/logger 3.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/LICENSE +21 -0
- package/README.md +1 -0
- package/cell.yml +1 -0
- package/lib/common/index.d.ts +3 -0
- package/lib/common/index.d.ts.map +1 -0
- package/lib/common/index.js +19 -0
- package/lib/common/index.js.map +1 -0
- package/lib/common/module.d.ts +4 -0
- package/lib/common/module.d.ts.map +1 -0
- package/lib/common/module.js +6 -0
- package/lib/common/module.js.map +1 -0
- package/lib/common/winston-logger-protocol.d.ts +8 -0
- package/lib/common/winston-logger-protocol.d.ts.map +1 -0
- package/lib/common/winston-logger-protocol.js +6 -0
- package/lib/common/winston-logger-protocol.js.map +1 -0
- package/lib/common/winston-logger.d.ts +15 -0
- package/lib/common/winston-logger.d.ts.map +1 -0
- package/lib/common/winston-logger.js +70 -0
- package/lib/common/winston-logger.js.map +1 -0
- package/lib/package.spec.d.ts +1 -0
- package/lib/package.spec.d.ts.map +1 -0
- package/lib/package.spec.js +4 -0
- package/lib/package.spec.js.map +1 -0
- package/package.json +44 -0
- package/src/common/index.ts +2 -0
- package/src/common/module.ts +4 -0
- package/src/common/winston-logger-protocol.ts +13 -0
- package/src/common/winston-logger.ts +62 -0
- package/src/package.spec.ts +4 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019 Cellbang
|
|
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/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# Cell - Logger Component with winston
|
package/cell.yml
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/common/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,2BAA2B,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./winston-logger"), exports);
|
|
18
|
+
__exportStar(require("./winston-logger-protocol"), exports);
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/common/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,mDAAiC;AACjC,4DAA0C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../../src/common/module.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,CAAC;;AAGjB,wBAA0B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module.js","sourceRoot":"","sources":["../../src/common/module.ts"],"names":[],"mappings":";;AAAA,mBAAiB;AACjB,uCAAwC;AAExC,kBAAe,IAAA,eAAQ,GAAE,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Logger, LoggerOptions } from 'winston';
|
|
2
|
+
export declare const RawWinstonLogger: unique symbol;
|
|
3
|
+
export declare const WinstonConfig: unique symbol;
|
|
4
|
+
export interface WinstonConfig extends LoggerOptions {
|
|
5
|
+
}
|
|
6
|
+
export interface RawWinstonLogger extends Logger {
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=winston-logger-protocol.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"winston-logger-protocol.d.ts","sourceRoot":"","sources":["../../src/common/winston-logger-protocol.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAEhD,eAAO,MAAM,gBAAgB,eAA0B,CAAC;AAExD,eAAO,MAAM,aAAa,eAA0B,CAAC;AAErD,MAAM,WAAW,aAAc,SAAQ,aAAa;CAEnD;AAED,MAAM,WAAW,gBAAiB,SAAQ,MAAM;CAE/C"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WinstonConfig = exports.RawWinstonLogger = void 0;
|
|
4
|
+
exports.RawWinstonLogger = Symbol('WinstonLogger');
|
|
5
|
+
exports.WinstonConfig = Symbol('WinstonConfig');
|
|
6
|
+
//# sourceMappingURL=winston-logger-protocol.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"winston-logger-protocol.js","sourceRoot":"","sources":["../../src/common/winston-logger-protocol.ts"],"names":[],"mappings":";;;AAEa,QAAA,gBAAgB,GAAG,MAAM,CAAC,eAAe,CAAC,CAAC;AAE3C,QAAA,aAAa,GAAG,MAAM,CAAC,eAAe,CAAC,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { AbstractLogger } from '@celljs/core';
|
|
2
|
+
import { WinstonConfig, RawWinstonLogger } from './winston-logger-protocol';
|
|
3
|
+
export declare class WinstonLogger extends AbstractLogger {
|
|
4
|
+
protected readonly winstonConfig?: WinstonConfig;
|
|
5
|
+
protected readonly winstonConfig2?: WinstonConfig;
|
|
6
|
+
protected logger: RawWinstonLogger;
|
|
7
|
+
protected init(): void;
|
|
8
|
+
getLogger(): RawWinstonLogger;
|
|
9
|
+
error(message: string, context?: string): void;
|
|
10
|
+
warn(message: string, context?: string): void;
|
|
11
|
+
info(message: string, context?: string): void;
|
|
12
|
+
debug(message: string, context?: string): void;
|
|
13
|
+
protected call(logFn: (...args: any[]) => void, message: any, context?: string): void;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=winston-logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"winston-logger.d.ts","sourceRoot":"","sources":["../../src/common/winston-logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgE,cAAc,EAAwB,MAAM,cAAc,CAAC;AAClI,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAG5E,qBACa,aAAc,SAAQ,cAAc;IAG7C,SAAS,CAAC,QAAQ,CAAC,aAAa,CAAC,EAAE,aAAa,CAAC;IAIjD,SAAS,CAAC,QAAQ,CAAC,cAAc,CAAC,EAAE,aAAa,CAAC;IAIlD,SAAS,CAAC,MAAM,EAAE,gBAAgB,CAAC;IAGnC,SAAS,CAAC,IAAI;IAed,SAAS;IAIT,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM;IAIvC,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM;IAItC,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM;IAItC,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM;cAIpB,IAAI,CAAC,KAAK,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI;CAOjG"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.WinstonLogger = void 0;
|
|
13
|
+
const core_1 = require("@celljs/core");
|
|
14
|
+
const winston_logger_protocol_1 = require("./winston-logger-protocol");
|
|
15
|
+
const winston_1 = require("winston");
|
|
16
|
+
let WinstonLogger = class WinstonLogger extends core_1.AbstractLogger {
|
|
17
|
+
init() {
|
|
18
|
+
if (!this.logger) {
|
|
19
|
+
this.logger = (0, winston_1.createLogger)(Object.assign(Object.assign({ level: this.level, format: winston_1.format.combine(winston_1.format.timestamp(), winston_1.format.printf(({ level, message, timestamp }) => `${timestamp} [${level}] ${message}`)), transports: [new winston_1.transports.Console()] }, this.winstonConfig), this.winstonConfig2));
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
getLogger() {
|
|
23
|
+
return this.logger;
|
|
24
|
+
}
|
|
25
|
+
error(message, context) {
|
|
26
|
+
this.call(this.logger.error.bind(this.logger), message, context);
|
|
27
|
+
}
|
|
28
|
+
warn(message, context) {
|
|
29
|
+
this.call(this.logger.warn.bind(this.logger), message, context);
|
|
30
|
+
}
|
|
31
|
+
info(message, context) {
|
|
32
|
+
this.call(this.logger.info.bind(this.logger), message, context);
|
|
33
|
+
}
|
|
34
|
+
debug(message, context) {
|
|
35
|
+
this.call(this.logger.debug.bind(this.logger), message, context);
|
|
36
|
+
}
|
|
37
|
+
call(logFn, message, context) {
|
|
38
|
+
var _a;
|
|
39
|
+
context = context !== null && context !== void 0 ? context : this.context;
|
|
40
|
+
const traceId = (_a = this.traceIdProvider) === null || _a === void 0 ? void 0 : _a.provide();
|
|
41
|
+
const traceStr = traceId ? ` [trace: ${traceId}]` : '';
|
|
42
|
+
const contextStr = this.context ? ` [${this.context}]` : '';
|
|
43
|
+
logFn(`${traceStr}${contextStr} ${message}`);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
__decorate([
|
|
47
|
+
(0, core_1.Value)(`${core_1.LOGGER_CONFIG}.winstonConfig`),
|
|
48
|
+
__metadata("design:type", Object)
|
|
49
|
+
], WinstonLogger.prototype, "winstonConfig", void 0);
|
|
50
|
+
__decorate([
|
|
51
|
+
(0, core_1.Autowired)(winston_logger_protocol_1.WinstonConfig),
|
|
52
|
+
(0, core_1.Optional)(),
|
|
53
|
+
__metadata("design:type", Object)
|
|
54
|
+
], WinstonLogger.prototype, "winstonConfig2", void 0);
|
|
55
|
+
__decorate([
|
|
56
|
+
(0, core_1.Autowired)(winston_logger_protocol_1.RawWinstonLogger),
|
|
57
|
+
(0, core_1.Optional)(),
|
|
58
|
+
__metadata("design:type", Object)
|
|
59
|
+
], WinstonLogger.prototype, "logger", void 0);
|
|
60
|
+
__decorate([
|
|
61
|
+
(0, core_1.PostConstruct)(),
|
|
62
|
+
__metadata("design:type", Function),
|
|
63
|
+
__metadata("design:paramtypes", []),
|
|
64
|
+
__metadata("design:returntype", void 0)
|
|
65
|
+
], WinstonLogger.prototype, "init", null);
|
|
66
|
+
WinstonLogger = __decorate([
|
|
67
|
+
(0, core_1.Component)({ id: core_1.Logger, rebind: true, scope: core_1.Scope.Transient })
|
|
68
|
+
], WinstonLogger);
|
|
69
|
+
exports.WinstonLogger = WinstonLogger;
|
|
70
|
+
//# sourceMappingURL=winston-logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"winston-logger.js","sourceRoot":"","sources":["../../src/common/winston-logger.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=package.spec.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"package.spec.d.ts","sourceRoot":"","sources":["../src/package.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"package.spec.js","sourceRoot":"","sources":["../src/package.spec.ts"],"names":[],"mappings":"AAAA,QAAQ,CAAC,gBAAgB,EAAE,GAAG,EAAE;IAE5B,EAAE,CAAC,kCAAkC,EAAE,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;AACrD,CAAC,CAAC,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@celljs/logger",
|
|
3
|
+
"version": "3.0.0",
|
|
4
|
+
"description": "logger component for pino",
|
|
5
|
+
"main": "lib/common/index.js",
|
|
6
|
+
"typings": "lib/common/index.d.ts",
|
|
7
|
+
"dependencies": {
|
|
8
|
+
"@celljs/core": "3.0.0",
|
|
9
|
+
"@celljs/web": "3.0.0",
|
|
10
|
+
"winston": "^3.10.0"
|
|
11
|
+
},
|
|
12
|
+
"publishConfig": {
|
|
13
|
+
"access": "public"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"cell-component"
|
|
17
|
+
],
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "https://github.com/cellbang/cell.git"
|
|
22
|
+
},
|
|
23
|
+
"bugs": {
|
|
24
|
+
"url": "https://github.com/cellbang/cell/issues"
|
|
25
|
+
},
|
|
26
|
+
"homepage": "https://github.com/cellbang/cell",
|
|
27
|
+
"files": [
|
|
28
|
+
"lib",
|
|
29
|
+
"src",
|
|
30
|
+
"cell.yml",
|
|
31
|
+
"cell-local.yml"
|
|
32
|
+
],
|
|
33
|
+
"scripts": {
|
|
34
|
+
"lint": "cell-component lint",
|
|
35
|
+
"build": "cell-component build",
|
|
36
|
+
"watch": "cell-component watch",
|
|
37
|
+
"clean": "cell-component clean",
|
|
38
|
+
"test": "cell-component test:js"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@celljs/component": "3.0.0"
|
|
42
|
+
},
|
|
43
|
+
"gitHead": "c0ef8d269e33a795406bcbb240cac4b845c6c24c"
|
|
44
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Logger, LoggerOptions } from 'winston';
|
|
2
|
+
|
|
3
|
+
export const RawWinstonLogger = Symbol('WinstonLogger');
|
|
4
|
+
|
|
5
|
+
export const WinstonConfig = Symbol('WinstonConfig');
|
|
6
|
+
|
|
7
|
+
export interface WinstonConfig extends LoggerOptions {
|
|
8
|
+
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface RawWinstonLogger extends Logger {
|
|
12
|
+
|
|
13
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { Logger, LOGGER_CONFIG, Value, Component, Autowired, Optional, AbstractLogger, PostConstruct, Scope } from '@celljs/core';
|
|
2
|
+
import { WinstonConfig, RawWinstonLogger } from './winston-logger-protocol';
|
|
3
|
+
import { createLogger, transports, format } from 'winston';
|
|
4
|
+
|
|
5
|
+
@Component({ id: Logger, rebind: true, scope: Scope.Transient })
|
|
6
|
+
export class WinstonLogger extends AbstractLogger {
|
|
7
|
+
|
|
8
|
+
@Value(`${LOGGER_CONFIG}.winstonConfig`)
|
|
9
|
+
protected readonly winstonConfig?: WinstonConfig;
|
|
10
|
+
|
|
11
|
+
@Autowired(WinstonConfig)
|
|
12
|
+
@Optional()
|
|
13
|
+
protected readonly winstonConfig2?: WinstonConfig;
|
|
14
|
+
|
|
15
|
+
@Autowired(RawWinstonLogger)
|
|
16
|
+
@Optional()
|
|
17
|
+
protected logger: RawWinstonLogger;
|
|
18
|
+
|
|
19
|
+
@PostConstruct()
|
|
20
|
+
protected init() {
|
|
21
|
+
if (!this.logger) {
|
|
22
|
+
this.logger = createLogger({
|
|
23
|
+
level: this.level,
|
|
24
|
+
format: format.combine(
|
|
25
|
+
format.timestamp(),
|
|
26
|
+
format.printf(({ level, message, timestamp }) => `${timestamp} [${level}] ${message}`)
|
|
27
|
+
),
|
|
28
|
+
transports: [new transports.Console()],
|
|
29
|
+
...this.winstonConfig,
|
|
30
|
+
...this.winstonConfig2,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
getLogger() {
|
|
36
|
+
return this.logger;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
error(message: string, context?: string) {
|
|
40
|
+
this.call(this.logger.error.bind(this.logger), message, context);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
warn(message: string, context?: string) {
|
|
44
|
+
this.call(this.logger.warn.bind(this.logger), message, context);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
info(message: string, context?: string) {
|
|
48
|
+
this.call(this.logger.info.bind(this.logger), message, context);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
debug(message: string, context?: string) {
|
|
52
|
+
this.call(this.logger.debug.bind(this.logger), message, context);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
protected override call(logFn: (...args: any[]) => void, message: any, context?: string): void {
|
|
56
|
+
context = context ?? this.context;
|
|
57
|
+
const traceId = this.traceIdProvider?.provide();
|
|
58
|
+
const traceStr = traceId ? ` [trace: ${traceId}]` : '';
|
|
59
|
+
const contextStr = this.context ? ` [${this.context}]` : '';
|
|
60
|
+
logFn(`${traceStr}${contextStr} ${message}`);
|
|
61
|
+
}
|
|
62
|
+
}
|