@fonoster/logger 0.3.12 → 0.3.16-alpha.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/dist/envs.d.ts +6 -0
- package/dist/envs.js +44 -0
- package/dist/index.d.ts +5 -2
- package/dist/index.js +28 -3
- package/dist/logger.d.ts +1 -14
- package/dist/logger.js +6 -33
- package/dist/new_logger.d.ts +6 -0
- package/dist/new_logger.js +45 -0
- package/dist/types.d.ts +12 -0
- package/dist/types.js +27 -0
- package/dist/user_logger.d.ts +3 -0
- package/dist/user_logger.js +33 -0
- package/package.json +2 -2
package/dist/envs.d.ts
ADDED
package/dist/envs.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
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.fluent = exports.transports = exports.level = exports.format = void 0;
|
|
7
|
+
/*
|
|
8
|
+
* Copyright (C) 2022 by Fonoster Inc (https://fonoster.com)
|
|
9
|
+
* http://github.com/fonoster/fonoster
|
|
10
|
+
*
|
|
11
|
+
* This file is part of Fonoster
|
|
12
|
+
*
|
|
13
|
+
* Licensed under the MIT License (the "License");
|
|
14
|
+
* you may not use this file except in compliance with
|
|
15
|
+
* the License. You may obtain a copy of the License at
|
|
16
|
+
*
|
|
17
|
+
* https://opensource.org/licenses/MIT
|
|
18
|
+
*
|
|
19
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
20
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
21
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
22
|
+
* See the License for the specific language governing permissions and
|
|
23
|
+
* limitations under the License.
|
|
24
|
+
*/
|
|
25
|
+
const winston_1 = __importDefault(require("winston"));
|
|
26
|
+
const fluent_logger_1 = __importDefault(require("fluent-logger"));
|
|
27
|
+
const fluentTransport = fluent_logger_1.default.support.winstonTransport();
|
|
28
|
+
const fluent = new fluentTransport(`${process.env.LOG_OPT_TAG_PREFIX}.fonoster`, {
|
|
29
|
+
host: process.env.LOGS_DRIVER_HOST,
|
|
30
|
+
port: process.env.LOGS_DRIVER_PORT,
|
|
31
|
+
timeout: 3.0,
|
|
32
|
+
requireAckResponse: true
|
|
33
|
+
});
|
|
34
|
+
exports.fluent = fluent;
|
|
35
|
+
const format = process.env.LOGS_FORMAT === "json"
|
|
36
|
+
? winston_1.default.format.combine(winston_1.default.format.timestamp(), winston_1.default.format.json())
|
|
37
|
+
: winston_1.default.format.combine(winston_1.default.format.colorize(), winston_1.default.format.simple());
|
|
38
|
+
exports.format = format;
|
|
39
|
+
const level = process.env.LOGS_LEVEL ? process.env.LOGS_LEVEL : "info";
|
|
40
|
+
exports.level = level;
|
|
41
|
+
const transports = process.env.LOGS_TRANSPORT === "fluent"
|
|
42
|
+
? [fluent]
|
|
43
|
+
: [new winston_1.default.transports.Console()];
|
|
44
|
+
exports.transports = transports;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import { ULogType } from "./types";
|
|
2
|
+
import Logger from "./new_logger";
|
|
3
|
+
import ulogger from "./user_logger";
|
|
4
|
+
import logger, { mute, unmute } from "./logger";
|
|
5
|
+
export { logger as default, Logger, ulogger, ULogType, mute, unmute };
|
package/dist/index.js
CHANGED
|
@@ -18,11 +18,36 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
18
18
|
__setModuleDefault(result, mod);
|
|
19
19
|
return result;
|
|
20
20
|
};
|
|
21
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
22
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
|
+
};
|
|
21
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
-
exports.unmute = exports.mute = exports.ULogType = exports.ulogger = exports.default = void 0;
|
|
25
|
+
exports.unmute = exports.mute = exports.ULogType = exports.ulogger = exports.Logger = exports.default = void 0;
|
|
26
|
+
/*
|
|
27
|
+
* Copyright (C) 2022 by Fonoster Inc (https://fonoster.com)
|
|
28
|
+
* http://github.com/fonoster/fonoster
|
|
29
|
+
*
|
|
30
|
+
* This file is part of Fonoster
|
|
31
|
+
*
|
|
32
|
+
* Licensed under the MIT License (the "License");
|
|
33
|
+
* you may not use this file except in compliance with
|
|
34
|
+
* the License. You may obtain a copy of the License at
|
|
35
|
+
*
|
|
36
|
+
* https://opensource.org/licenses/MIT
|
|
37
|
+
*
|
|
38
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
39
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
40
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
41
|
+
* See the License for the specific language governing permissions and
|
|
42
|
+
* limitations under the License.
|
|
43
|
+
*/
|
|
44
|
+
const types_1 = require("./types");
|
|
45
|
+
Object.defineProperty(exports, "ULogType", { enumerable: true, get: function () { return types_1.ULogType; } });
|
|
46
|
+
const new_logger_1 = __importDefault(require("./new_logger"));
|
|
47
|
+
exports.Logger = new_logger_1.default;
|
|
48
|
+
const user_logger_1 = __importDefault(require("./user_logger"));
|
|
49
|
+
exports.ulogger = user_logger_1.default;
|
|
23
50
|
const logger_1 = __importStar(require("./logger"));
|
|
24
51
|
exports.default = logger_1.default;
|
|
25
|
-
Object.defineProperty(exports, "ulogger", { enumerable: true, get: function () { return logger_1.ulogger; } });
|
|
26
|
-
Object.defineProperty(exports, "ULogType", { enumerable: true, get: function () { return logger_1.ULogType; } });
|
|
27
52
|
Object.defineProperty(exports, "mute", { enumerable: true, get: function () { return logger_1.mute; } });
|
|
28
53
|
Object.defineProperty(exports, "unmute", { enumerable: true, get: function () { return logger_1.unmute; } });
|
package/dist/logger.d.ts
CHANGED
|
@@ -1,18 +1,5 @@
|
|
|
1
1
|
import winston from "winston";
|
|
2
|
-
export declare enum ULogType {
|
|
3
|
-
APP = "app",
|
|
4
|
-
CALL = "call",
|
|
5
|
-
SIP = "sip"
|
|
6
|
-
}
|
|
7
|
-
export interface ULog {
|
|
8
|
-
accessKeyId: string;
|
|
9
|
-
eventType: ULogType;
|
|
10
|
-
level: "info" | "error" | "verbose" | "warn";
|
|
11
|
-
message: string;
|
|
12
|
-
body?: Record<string, unknown>;
|
|
13
|
-
}
|
|
14
2
|
declare const logger: winston.Logger;
|
|
15
3
|
declare const mute: () => void;
|
|
16
4
|
declare const unmute: () => void;
|
|
17
|
-
|
|
18
|
-
export { logger as default, ulogger, mute, unmute };
|
|
5
|
+
export { logger as default, mute, unmute };
|
package/dist/logger.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.unmute = exports.mute = exports.
|
|
6
|
+
exports.unmute = exports.mute = exports.default = void 0;
|
|
7
7
|
/*
|
|
8
8
|
* Copyright (C) 2022 by Fonoster Inc (https://fonoster.com)
|
|
9
9
|
* http://github.com/fonoster/fonoster
|
|
@@ -23,45 +23,18 @@ exports.unmute = exports.mute = exports.ulogger = exports.default = exports.ULog
|
|
|
23
23
|
* limitations under the License.
|
|
24
24
|
*/
|
|
25
25
|
const winston_1 = __importDefault(require("winston"));
|
|
26
|
-
const
|
|
27
|
-
var ULogType;
|
|
28
|
-
(function (ULogType) {
|
|
29
|
-
ULogType["APP"] = "app";
|
|
30
|
-
ULogType["CALL"] = "call";
|
|
31
|
-
ULogType["SIP"] = "sip";
|
|
32
|
-
})(ULogType = exports.ULogType || (exports.ULogType = {}));
|
|
33
|
-
const fluentTransport = fluent_logger_1.default.support.winstonTransport();
|
|
34
|
-
const fluent = new fluentTransport(`${process.env.LOG_OPT_TAG_PREFIX}.fonoster`, {
|
|
35
|
-
host: process.env.LOGS_DRIVER_HOST,
|
|
36
|
-
port: process.env.LOGS_DRIVER_PORT,
|
|
37
|
-
timeout: 3.0,
|
|
38
|
-
requireAckResponse: true
|
|
39
|
-
});
|
|
40
|
-
const format = process.env.LOGS_FORMAT === "json"
|
|
41
|
-
? winston_1.default.format.json()
|
|
42
|
-
: winston_1.default.format.combine(winston_1.default.format.colorize(), winston_1.default.format.simple());
|
|
43
|
-
const level = process.env.LOGS_LEVEL ? process.env.LOGS_LEVEL : "info";
|
|
44
|
-
const transports = process.env.LOGS_TRANSPORT === "fluent"
|
|
45
|
-
? [fluent]
|
|
46
|
-
: [new winston_1.default.transports.Console()];
|
|
26
|
+
const envs_1 = require("./envs");
|
|
47
27
|
const logger = winston_1.default.createLogger({
|
|
48
28
|
levels: winston_1.default.config.npm.levels,
|
|
49
|
-
format,
|
|
50
|
-
transports,
|
|
51
|
-
level
|
|
29
|
+
format: envs_1.format,
|
|
30
|
+
transports: envs_1.transports,
|
|
31
|
+
level: envs_1.level
|
|
52
32
|
});
|
|
53
33
|
exports.default = logger;
|
|
54
34
|
logger.on("finish", () => {
|
|
55
|
-
fluent.sender.end("end", {}, () => { });
|
|
35
|
+
envs_1.fluent.sender.end("end", {}, () => { });
|
|
56
36
|
});
|
|
57
37
|
const mute = () => logger.transports.forEach((t) => (t.silent = true));
|
|
58
38
|
exports.mute = mute;
|
|
59
39
|
const unmute = () => logger.transports.forEach((t) => (t.silent = false));
|
|
60
40
|
exports.unmute = unmute;
|
|
61
|
-
const ulogger = (log) => logger[log.level](log.message, {
|
|
62
|
-
eventType: log.eventType,
|
|
63
|
-
body: log.body,
|
|
64
|
-
level: log.level,
|
|
65
|
-
accessKeyId: log.accessKeyId
|
|
66
|
-
});
|
|
67
|
-
exports.ulogger = ulogger;
|
|
@@ -0,0 +1,45 @@
|
|
|
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.default = exports.Logger = void 0;
|
|
7
|
+
/*
|
|
8
|
+
* Copyright (C) 2022 by Fonoster Inc (https://fonoster.com)
|
|
9
|
+
* http://github.com/fonoster/fonoster
|
|
10
|
+
*
|
|
11
|
+
* This file is part of Fonoster
|
|
12
|
+
*
|
|
13
|
+
* Licensed under the MIT License (the "License");
|
|
14
|
+
* you may not use this file except in compliance with
|
|
15
|
+
* the License. You may obtain a copy of the License at
|
|
16
|
+
*
|
|
17
|
+
* https://opensource.org/licenses/MIT
|
|
18
|
+
*
|
|
19
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
20
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
21
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
22
|
+
* See the License for the specific language governing permissions and
|
|
23
|
+
* limitations under the License.
|
|
24
|
+
*/
|
|
25
|
+
const winston_1 = __importDefault(require("winston"));
|
|
26
|
+
const path_1 = require("path");
|
|
27
|
+
const envs_1 = require("./envs");
|
|
28
|
+
const Logger = (config) => {
|
|
29
|
+
const file = config.filePath.replace((0, path_1.resolve)("./"), "");
|
|
30
|
+
const humanFormat = winston_1.default.format.combine(winston_1.default.format.timestamp({
|
|
31
|
+
format: "YYYY-MM-dd HH:mm:ss.SSS"
|
|
32
|
+
}), winston_1.default.format.printf(({ level, message, timestamp, ...metadata }) => `${timestamp} [${level}]: ${config.service ? `(${config.service})` : ''} ${file} ${message} ${JSON.stringify(metadata)}`));
|
|
33
|
+
const logger = winston_1.default.createLogger({
|
|
34
|
+
levels: winston_1.default.config.npm.levels,
|
|
35
|
+
format: humanFormat,
|
|
36
|
+
transports: envs_1.transports,
|
|
37
|
+
level: envs_1.level
|
|
38
|
+
});
|
|
39
|
+
logger.on("finish", () => {
|
|
40
|
+
envs_1.fluent.sender.end("end", {}, () => { });
|
|
41
|
+
});
|
|
42
|
+
return logger;
|
|
43
|
+
};
|
|
44
|
+
exports.Logger = Logger;
|
|
45
|
+
exports.default = exports.Logger;
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare enum ULogType {
|
|
2
|
+
APP = "app",
|
|
3
|
+
CALL = "call",
|
|
4
|
+
SIP = "sip"
|
|
5
|
+
}
|
|
6
|
+
export interface ULog {
|
|
7
|
+
accessKeyId: string;
|
|
8
|
+
eventType: ULogType;
|
|
9
|
+
level: "info" | "error" | "verbose" | "warn";
|
|
10
|
+
message: string;
|
|
11
|
+
body?: Record<string, unknown>;
|
|
12
|
+
}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ULogType = void 0;
|
|
4
|
+
/*
|
|
5
|
+
* Copyright (C) 2022 by Fonoster Inc (https://fonoster.com)
|
|
6
|
+
* http://github.com/fonoster/fonoster
|
|
7
|
+
*
|
|
8
|
+
* This file is part of Fonoster
|
|
9
|
+
*
|
|
10
|
+
* Licensed under the MIT License (the "License");
|
|
11
|
+
* you may not use this file except in compliance with
|
|
12
|
+
* the License. You may obtain a copy of the License at
|
|
13
|
+
*
|
|
14
|
+
* https://opensource.org/licenses/MIT
|
|
15
|
+
*
|
|
16
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
17
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
18
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
19
|
+
* See the License for the specific language governing permissions and
|
|
20
|
+
* limitations under the License.
|
|
21
|
+
*/
|
|
22
|
+
var ULogType;
|
|
23
|
+
(function (ULogType) {
|
|
24
|
+
ULogType["APP"] = "app";
|
|
25
|
+
ULogType["CALL"] = "call";
|
|
26
|
+
ULogType["SIP"] = "sip";
|
|
27
|
+
})(ULogType = exports.ULogType || (exports.ULogType = {}));
|
|
@@ -0,0 +1,33 @@
|
|
|
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.default = void 0;
|
|
7
|
+
/*
|
|
8
|
+
* Copyright (C) 2022 by Fonoster Inc (https://fonoster.com)
|
|
9
|
+
* http://github.com/fonoster/fonoster
|
|
10
|
+
*
|
|
11
|
+
* This file is part of Fonoster
|
|
12
|
+
*
|
|
13
|
+
* Licensed under the MIT License (the "License");
|
|
14
|
+
* you may not use this file except in compliance with
|
|
15
|
+
* the License. You may obtain a copy of the License at
|
|
16
|
+
*
|
|
17
|
+
* https://opensource.org/licenses/MIT
|
|
18
|
+
*
|
|
19
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
20
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
21
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
22
|
+
* See the License for the specific language governing permissions and
|
|
23
|
+
* limitations under the License.
|
|
24
|
+
*/
|
|
25
|
+
const logger_1 = __importDefault(require("./logger"));
|
|
26
|
+
// Special logger function for User specific events
|
|
27
|
+
const ulogger = (log) => logger_1.default[log.level](log.message, {
|
|
28
|
+
eventType: log.eventType,
|
|
29
|
+
body: log.body,
|
|
30
|
+
level: log.level,
|
|
31
|
+
accessKeyId: log.accessKeyId
|
|
32
|
+
});
|
|
33
|
+
exports.default = ulogger;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fonoster/logger",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.16-alpha.1",
|
|
4
4
|
"description": "Logger module",
|
|
5
5
|
"author": "Pedro Sanders <psanders@fonoster.com>",
|
|
6
6
|
"homepage": "https://github.com/fonoster/fonoster#readme",
|
|
@@ -35,5 +35,5 @@
|
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"rimraf": "^3.0.2"
|
|
37
37
|
},
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "5d47c2daa7b09ed3b5feb32886400d4e27543673"
|
|
39
39
|
}
|