feat: add logs function (#6)

This commit is contained in:
Kevin Lee
2024-08-15 17:43:21 +08:00
committed by GitHub
parent 8d59c86a92
commit 7e5fd0e082
12 changed files with 182 additions and 11 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

15
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{
"name": "@openim/electron-client-sdk",
"version": "1.0.6",
"version": "1.0.9",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "@openim/electron-client-sdk",
"version": "1.0.6",
"version": "1.0.9",
"license": "MIT",
"dependencies": {
"koffi": "^2.8.0",
@@ -15,6 +15,7 @@
"devDependencies": {
"@commitlint/cli": "^16.2.4",
"@commitlint/config-conventional": "^16.2.4",
"@openim/wasm-client-sdk": "^3.8.0",
"@rollup/plugin-alias": "^5.1.0",
"@rollup/plugin-terser": "^0.4.4",
"@types/ffi-napi": "^4.0.10",
@@ -42,7 +43,7 @@
"node": ">=12.0"
},
"peerDependencies": {
"@openim/wasm-client-sdk": "^3.8.0-rc.0",
"@openim/wasm-client-sdk": "^3.8.0",
"electron": ">=12.0.0"
}
},
@@ -1881,10 +1882,10 @@
}
},
"node_modules/@openim/wasm-client-sdk": {
"version": "3.8.0-rc.0",
"resolved": "https://registry.npmjs.org/@openim/wasm-client-sdk/-/wasm-client-sdk-3.8.0-rc.0.tgz",
"integrity": "sha512-SGd0Yu4tUQfs9FDkR3x49NjX0jPO1W0ETxGYqKO1BMmIyhwVGeKQMpfHD2QXPh2yefhT4OLoNBffHihopUrK6Q==",
"peer": true,
"version": "3.8.1",
"resolved": "https://registry.npmjs.org/@openim/wasm-client-sdk/-/wasm-client-sdk-3.8.1.tgz",
"integrity": "sha512-1z90Z5A24MCeIuQtvP68GhQ2bEaS+XjpqtSnpLA9qcahaQqErzanzwJ4kDbo+1+Z0MFNqnDzjlnUjyf2FRv41Q==",
"dev": true,
"engines": {
"node": ">=12.0"
}

View File

@@ -1,6 +1,6 @@
{
"name": "@openim/electron-client-sdk",
"version": "1.0.8",
"version": "1.0.9",
"description": "open im sdk for node",
"source": "src/index.ts",
"main": "lib/index.js",

View File

@@ -2,7 +2,13 @@ import koffi from 'koffi';
import { v4 as uuidV4 } from 'uuid';
import type { LibOpenIMSDK } from 'libOpenIMSDK';
import { UserModuleApi, setupUserModule } from './modules/user';
import { InitConfig, LoginParams, UploadLogsParams } from '@/types/params';
import {
DebugLogsParams,
ErrorLogsParams,
InitConfig,
LoginParams,
UploadLogsParams,
} from '@/types/params';
import { BaseResponse, EmitProxy } from '@/types/entity';
import { ErrorCode } from '@/constant/api';
import { NativeEvent, eventMapping } from '@/constant/callback';
@@ -14,7 +20,7 @@ import {
setupConversationModule,
} from './modules/conversation';
import { type MessageModuleApi, setupMessageModule } from './modules/message';
import { CbEvents, LoginStatus } from '@openim/wasm-client-sdk';
import { CbEvents, LoginStatus, LogLevel } from '@openim/wasm-client-sdk';
import { SelfUserInfo } from '@openim/wasm-client-sdk/lib/types/entity';
import {
SetConversationExParams,
@@ -861,6 +867,16 @@ class OpenIMSDK
'void',
['baseCallback *', 'str', 'int', 'str', 'listenerCallback *']
);
this.libOpenIMSDK.logs = this.lib.func('__stdcall', 'logs', 'void', [
'baseCallback *',
'str',
'int',
'str',
'int',
'str',
'str',
'str',
]);
// advance
if (this.enterprise) {
@@ -1239,6 +1255,98 @@ class OpenIMSDK
);
});
verboseLogs = (params: DebugLogsParams, opid = uuidV4()) =>
new Promise<BaseResponse<void>>((resolve, reject) => {
this.libOpenIMSDK.logs(
this.baseCallbackWrap(resolve, reject),
opid,
LogLevel.Verbose,
'',
0,
params.msgs,
'',
JSON.stringify(params.keyAndValue)
);
});
debugLogs = (params: DebugLogsParams, opid = uuidV4()) =>
new Promise<BaseResponse<void>>((resolve, reject) => {
this.libOpenIMSDK.logs(
this.baseCallbackWrap(resolve, reject),
opid,
LogLevel.Debug,
'',
0,
params.msgs,
'',
JSON.stringify(params.keyAndValue)
);
});
infoLogs = (params: DebugLogsParams, opid = uuidV4()) =>
new Promise<BaseResponse<void>>((resolve, reject) => {
this.libOpenIMSDK.logs(
this.baseCallbackWrap(resolve, reject),
opid,
LogLevel.Info,
'',
0,
params.msgs,
'',
JSON.stringify(params.keyAndValue)
);
});
warnLogs = (params: ErrorLogsParams, opid = uuidV4()) =>
new Promise<BaseResponse<void>>((resolve, reject) => {
this.libOpenIMSDK.logs(
this.baseCallbackWrap(resolve, reject),
opid,
LogLevel.Warn,
'',
0,
params.msgs,
params.err,
JSON.stringify([])
);
});
errorLogs = (params: ErrorLogsParams, opid = uuidV4()) =>
new Promise<BaseResponse<void>>((resolve, reject) => {
this.libOpenIMSDK.logs(
this.baseCallbackWrap(resolve, reject),
opid,
LogLevel.Error,
'',
0,
params.msgs,
params.err,
JSON.stringify([])
);
});
fatalLogs = (params: ErrorLogsParams, opid = uuidV4()) =>
new Promise<BaseResponse<void>>((resolve, reject) => {
this.libOpenIMSDK.logs(
this.baseCallbackWrap(resolve, reject),
opid,
LogLevel.Fatal,
'',
0,
params.msgs,
params.err,
JSON.stringify([])
);
});
panicLogs = (params: ErrorLogsParams, opid = uuidV4()) =>
new Promise<BaseResponse<void>>((resolve, reject) => {
this.libOpenIMSDK.logs(
this.baseCallbackWrap(resolve, reject),
opid,
LogLevel.Panic,
'',
0,
params.msgs,
params.err,
JSON.stringify([])
);
});
// implements user api
getSelfUserInfo!: UserModuleApi['getSelfUserInfo'];
setSelfInfo!: UserModuleApi['setSelfInfo'];

View File

@@ -14,6 +14,8 @@ import {
SoundMsgByPathParams,
VideoMsgByPathParams,
UploadLogsParams,
DebugLogsParams,
ErrorLogsParams,
} from './types/params';
type EmitterEvents = {
@@ -93,7 +95,38 @@ type IMSDKInterface = Omit<WasmInterface, 'login'> & {
uploadLogs: (
params: UploadLogsParams,
opid?: string
) => Promise<WsResponse<string>>;
) => Promise<WsResponse<unknown>>;
/**
* @access only for electron
*/
verboseLogs: (
params: DebugLogsParams,
opid?: string
) => Promise<WsResponse<unknown>>;
debugLogs: (
params: DebugLogsParams,
opid?: string
) => Promise<WsResponse<unknown>>;
infoLogs: (
params: DebugLogsParams,
opid?: string
) => Promise<WsResponse<unknown>>;
warnLogs: (
params: ErrorLogsParams,
opid?: string
) => Promise<WsResponse<unknown>>;
errorLogs: (
params: ErrorLogsParams,
opid?: string
) => Promise<WsResponse<unknown>>;
fatalLogs: (
params: ErrorLogsParams,
opid?: string
) => Promise<WsResponse<unknown>>;
panicLogs: (
params: ErrorLogsParams,
opid?: string
) => Promise<WsResponse<unknown>>;
};
type ElectronInvoke = (method: string, ...args: any[]) => Promise<WsResponse>;

View File

@@ -752,6 +752,16 @@ declare module 'libOpenIMSDK' {
ex: string,
pCallback: CB_I_S
): void;
logs(
cCallback: CB_S_I_S_S,
operationID: string,
logLevel: number,
file: string,
line: number,
msgs: string,
err: string,
keyAndValue: string
): void;
}
const lib: LibOpenIMSDK;
export default lib;

View File

@@ -37,3 +37,22 @@ export type UploadLogsParams = {
line: number;
ex?: string;
};
export type LogsParams = {
logLevel: LogLevel;
file: string;
line: number;
msgs: string;
err: string;
keyAndValue: string[];
};
export type DebugLogsParams = {
msgs: string;
keyAndValue: string[];
};
export type ErrorLogsParams = {
msgs: string;
err: string;
};