@drift-labs/common 1.0.57 → 1.0.59
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/lib/utils/logger.d.ts
CHANGED
|
@@ -1,5 +1 @@
|
|
|
1
|
-
import { Logger as WinstonLogger } from 'winston';
|
|
2
|
-
export declare const logger: WinstonLogger;
|
|
3
|
-
export declare const setLogLevel: (logLevel: string) => void;
|
|
4
|
-
export type Logger = WinstonLogger;
|
|
5
1
|
export declare const allEnvDlog: (key: string, message: any, ...optionalParams: any[]) => void;
|
package/lib/utils/logger.js
CHANGED
|
@@ -1,84 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.allEnvDlog =
|
|
7
|
-
const winston_1 = require("winston");
|
|
8
|
-
const winston_slack_webhook_transport_1 = __importDefault(require("winston-slack-webhook-transport"));
|
|
9
|
-
const bypassAlert = process.env.RUNNING_LOCAL === 'true';
|
|
10
|
-
// Cache for log message templates to reduce string concatenation overhead
|
|
11
|
-
const logTemplateCache = new Map();
|
|
12
|
-
const MAX_TEMPLATE_CACHE_SIZE = 100;
|
|
13
|
-
// Optimized log formatter that caches common template patterns
|
|
14
|
-
function formatLogMessage(timestamp, level, message) {
|
|
15
|
-
const upperLevel = level.toUpperCase();
|
|
16
|
-
const templateKey = `${upperLevel}_template`;
|
|
17
|
-
if (logTemplateCache.has(templateKey)) {
|
|
18
|
-
const template = logTemplateCache.get(templateKey);
|
|
19
|
-
return template
|
|
20
|
-
.replace('{{timestamp}}', timestamp)
|
|
21
|
-
.replace('{{message}}', message);
|
|
22
|
-
}
|
|
23
|
-
const template = '[{{timestamp}}] ' + upperLevel + ': {{message}}';
|
|
24
|
-
if (logTemplateCache.size < MAX_TEMPLATE_CACHE_SIZE) {
|
|
25
|
-
logTemplateCache.set(templateKey, template);
|
|
26
|
-
}
|
|
27
|
-
return template
|
|
28
|
-
.replace('{{timestamp}}', timestamp)
|
|
29
|
-
.replace('{{message}}', message);
|
|
30
|
-
}
|
|
31
|
-
const loggerTransports = [
|
|
32
|
-
new winston_1.transports.Console({
|
|
33
|
-
level: 'info',
|
|
34
|
-
}),
|
|
35
|
-
];
|
|
36
|
-
if (!bypassAlert) {
|
|
37
|
-
loggerTransports.push(new winston_slack_webhook_transport_1.default({
|
|
38
|
-
webhookUrl: process.env.WEBHOOK_URL,
|
|
39
|
-
level: 'alert',
|
|
40
|
-
formatter: ({ timestamp, level, message }) => {
|
|
41
|
-
return {
|
|
42
|
-
text: formatLogMessage(timestamp, level, message),
|
|
43
|
-
};
|
|
44
|
-
},
|
|
45
|
-
}));
|
|
46
|
-
}
|
|
47
|
-
exports.logger = (0, winston_1.createLogger)({
|
|
48
|
-
levels: {
|
|
49
|
-
emerg: 0,
|
|
50
|
-
alert: 1,
|
|
51
|
-
crit: 2,
|
|
52
|
-
error: 3,
|
|
53
|
-
warning: 4,
|
|
54
|
-
notice: 5,
|
|
55
|
-
info: 6,
|
|
56
|
-
debug: 7,
|
|
57
|
-
},
|
|
58
|
-
level: 'info',
|
|
59
|
-
transports: loggerTransports,
|
|
60
|
-
format: winston_1.format.combine(winston_1.format.timestamp(), winston_1.format.printf(({ timestamp, level, message }) => {
|
|
61
|
-
return formatLogMessage(String(timestamp), String(level), String(message));
|
|
62
|
-
})),
|
|
63
|
-
});
|
|
64
|
-
const setLogLevel = (logLevel) => {
|
|
65
|
-
exports.logger.level = logLevel;
|
|
66
|
-
};
|
|
67
|
-
exports.setLogLevel = setLogLevel;
|
|
68
|
-
//@ts-ignore
|
|
69
|
-
exports.logger.alert = (message) => exports.logger.log('alert', message);
|
|
3
|
+
exports.allEnvDlog = void 0;
|
|
70
4
|
const allEnvDlog = (key, message, ...optionalParams) => {
|
|
71
|
-
|
|
72
|
-
const debugKey = `debug_${key}`;
|
|
73
|
-
let cachedFormat = logTemplateCache.get(debugKey);
|
|
74
|
-
if (!cachedFormat) {
|
|
75
|
-
cachedFormat = `🔧::${key}::\n{{message}}`;
|
|
76
|
-
if (logTemplateCache.size < MAX_TEMPLATE_CACHE_SIZE) {
|
|
77
|
-
logTemplateCache.set(debugKey, cachedFormat);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
const formattedMessage = cachedFormat.replace('{{message}}', String(message));
|
|
81
|
-
console.debug(formattedMessage, ...optionalParams);
|
|
5
|
+
console.debug(`🔧::${key}::\n${message}`, ...optionalParams);
|
|
82
6
|
};
|
|
83
7
|
exports.allEnvDlog = allEnvDlog;
|
|
84
8
|
//# sourceMappingURL=logger.js.map
|
package/lib/utils/logger.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/utils/logger.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/utils/logger.ts"],"names":[],"mappings":";;;AAAO,MAAM,UAAU,GAAG,CACzB,GAAW,EACX,OAAY,EACZ,GAAG,cAAqB,EACvB,EAAE;IACH,OAAO,CAAC,KAAK,CAAC,OAAO,GAAG,OAAO,OAAO,EAAE,EAAE,GAAG,cAAc,CAAC,CAAC;AAC9D,CAAC,CAAC;AANW,QAAA,UAAU,cAMrB","sourcesContent":["export const allEnvDlog = (\n\tkey: string,\n\tmessage: any,\n\t...optionalParams: any[]\n) => {\n\tconsole.debug(`🔧::${key}::\\n${message}`, ...optionalParams);\n};\n"]}
|
package/package.json
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@drift-labs/common",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.59",
|
|
4
4
|
"description": "Common functions for Drift",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
7
|
-
"browser": {
|
|
8
|
-
"./lib/utils/logger.js": "./lib/utils/logger.browser.js"
|
|
9
|
-
},
|
|
10
7
|
"license": "MIT",
|
|
11
8
|
"repository": {
|
|
12
9
|
"type": "git",
|
|
@@ -20,8 +17,7 @@
|
|
|
20
17
|
],
|
|
21
18
|
"author": "Drift Labs",
|
|
22
19
|
"dependencies": {
|
|
23
|
-
"@drift-labs/sdk": "^2.
|
|
24
|
-
"@slack/web-api": "6.4.0",
|
|
20
|
+
"@drift-labs/sdk": "^2.161.0-beta.4",
|
|
25
21
|
"@solana/spl-token": "^0.4.14",
|
|
26
22
|
"@solana/web3.js": "1.98.0",
|
|
27
23
|
"bcryptjs-react": "2.4.6",
|
|
@@ -33,12 +29,10 @@
|
|
|
33
29
|
"localstorage-memory": "1.0.3",
|
|
34
30
|
"rxjs": "7.8.2",
|
|
35
31
|
"tiny-invariant": "1.3.1",
|
|
36
|
-
"tweetnacl": "1.0.3"
|
|
37
|
-
"winston": "3.13.0",
|
|
38
|
-
"winston-slack-webhook-transport": "2.3.5"
|
|
32
|
+
"tweetnacl": "1.0.3"
|
|
39
33
|
},
|
|
40
34
|
"peerDependencies": {
|
|
41
|
-
"@drift-labs/sdk": "^2.
|
|
35
|
+
"@drift-labs/sdk": "^2.161.0-beta.4",
|
|
42
36
|
"@solana/web3.js": "1.98.0"
|
|
43
37
|
},
|
|
44
38
|
"scripts": {
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export interface Logger {
|
|
2
|
-
level: string;
|
|
3
|
-
log: (level: string, message: string) => void;
|
|
4
|
-
info: (message: string) => void;
|
|
5
|
-
warn: (message: string) => void;
|
|
6
|
-
error: (message: string) => void;
|
|
7
|
-
debug: (message: string) => void;
|
|
8
|
-
alert: (message: string) => void;
|
|
9
|
-
}
|
|
10
|
-
export declare const logger: Logger;
|
|
11
|
-
export declare const setLogLevel: (logLevel: string) => void;
|
|
12
|
-
export declare const allEnvDlog: (key: string, message: any, ...optionalParams: any[]) => void;
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Browser-safe logger stub. Replaces the Node-only winston logger when bundled
|
|
3
|
-
// for browser / React Native environments via the package.json "browser" field.
|
|
4
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.allEnvDlog = exports.setLogLevel = exports.logger = void 0;
|
|
6
|
-
const logTemplateCache = new Map();
|
|
7
|
-
const MAX_TEMPLATE_CACHE_SIZE = 100;
|
|
8
|
-
exports.logger = {
|
|
9
|
-
level: 'info',
|
|
10
|
-
log: (level, message) => {
|
|
11
|
-
console.log(`[${level.toUpperCase()}] ${message}`);
|
|
12
|
-
},
|
|
13
|
-
info: (message) => console.info(message),
|
|
14
|
-
warn: (message) => console.warn(message),
|
|
15
|
-
error: (message) => console.error(message),
|
|
16
|
-
debug: (message) => console.debug(message),
|
|
17
|
-
alert: (message) => console.warn(`[ALERT] ${message}`),
|
|
18
|
-
};
|
|
19
|
-
const setLogLevel = (logLevel) => {
|
|
20
|
-
exports.logger.level = logLevel;
|
|
21
|
-
};
|
|
22
|
-
exports.setLogLevel = setLogLevel;
|
|
23
|
-
const allEnvDlog = (key, message, ...optionalParams) => {
|
|
24
|
-
const debugKey = `debug_${key}`;
|
|
25
|
-
let cachedFormat = logTemplateCache.get(debugKey);
|
|
26
|
-
if (!cachedFormat) {
|
|
27
|
-
cachedFormat = `🔧::${key}::\n{{message}}`;
|
|
28
|
-
if (logTemplateCache.size < MAX_TEMPLATE_CACHE_SIZE) {
|
|
29
|
-
logTemplateCache.set(debugKey, cachedFormat);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
const formattedMessage = cachedFormat.replace('{{message}}', String(message));
|
|
33
|
-
console.debug(formattedMessage, ...optionalParams);
|
|
34
|
-
};
|
|
35
|
-
exports.allEnvDlog = allEnvDlog;
|
|
36
|
-
//# sourceMappingURL=logger.browser.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"log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iBAAiB,CAAC;QAC3C,IAAI,gBAAgB,CAAC,IAAI,GAAG,uBAAuB,EAAE,CAAC;YACrD,gBAAgB,CAAC,GAAG,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC;QAC9C,CAAC;IACF,CAAC;IAED,MAAM,gBAAgB,GAAG,YAAY,CAAC,OAAO,CAAC,aAAa,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC;IAC9E,OAAO,CAAC,KAAK,CAAC,gBAAgB,EAAE,GAAG,cAAc,CAAC,CAAC;AACpD,CAAC,CAAC;AAjBW,QAAA,UAAU,cAiBrB","sourcesContent":["// Browser-safe logger stub. Replaces the Node-only winston logger when bundled\n// for browser / React Native environments via the package.json \"browser\" field.\n\nconst logTemplateCache = new Map<string, string>();\nconst MAX_TEMPLATE_CACHE_SIZE = 100;\n\nexport interface Logger {\n\tlevel: string;\n\tlog: (level: string, message: string) => void;\n\tinfo: (message: string) => void;\n\twarn: (message: string) => void;\n\terror: (message: string) => void;\n\tdebug: (message: string) => void;\n\talert: (message: string) => void;\n}\n\nexport const logger: Logger = {\n\tlevel: 'info',\n\tlog: (level: string, message: string) => {\n\t\tconsole.log(`[${level.toUpperCase()}] ${message}`);\n\t},\n\tinfo: (message: string) => console.info(message),\n\twarn: (message: string) => console.warn(message),\n\terror: (message: string) => console.error(message),\n\tdebug: (message: string) => console.debug(message),\n\talert: (message: string) => console.warn(`[ALERT] ${message}`),\n};\n\nexport const setLogLevel = (logLevel: string) => {\n\tlogger.level = logLevel;\n};\n\nexport const allEnvDlog = (\n\tkey: string,\n\tmessage: any,\n\t...optionalParams: any[]\n) => {\n\tconst debugKey = `debug_${key}`;\n\tlet cachedFormat = logTemplateCache.get(debugKey);\n\n\tif (!cachedFormat) {\n\t\tcachedFormat = `🔧::${key}::\\n{{message}}`;\n\t\tif (logTemplateCache.size < MAX_TEMPLATE_CACHE_SIZE) {\n\t\t\tlogTemplateCache.set(debugKey, cachedFormat);\n\t\t}\n\t}\n\n\tconst formattedMessage = cachedFormat.replace('{{message}}', String(message));\n\tconsole.debug(formattedMessage, ...optionalParams);\n};\n"]}
|