@unvired/react-native-unvired-sdk 0.0.10 → 0.0.11
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/BuildNo.txt +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/logger/BaseLogger.d.ts +0 -9
- package/dist/logger/BaseLogger.js +1 -44
- package/dist/logger/Logger.d.ts +1 -1
- package/dist/logger/Logger.types.d.ts +7 -44
- package/dist/logger/services/LoggerNative.d.ts +2 -2
- package/dist/logger/services/LoggerNative.js +10 -5
- package/package.json +1 -1
package/BuildNo.txt
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
R-0.000.
|
|
1
|
+
R-0.000.0011
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { Logger, logger } from './logger/Logger';
|
|
2
|
-
export type { LogLevel, ILogger, ILoggerImplementation,
|
|
2
|
+
export type { LogLevel, ILogger, ILoggerImplementation, } from './logger/Logger';
|
|
3
3
|
export { default } from './logger/Logger';
|
|
@@ -16,13 +16,4 @@ export declare class BaseLogger {
|
|
|
16
16
|
getLogFileContent(): Promise<string>;
|
|
17
17
|
getBackupLogFileContent(): Promise<string | null>;
|
|
18
18
|
clearLogFile(): Promise<void>;
|
|
19
|
-
get logFile(): string;
|
|
20
|
-
write(message: string): Promise<void>;
|
|
21
|
-
readLog(): Promise<string>;
|
|
22
|
-
rotateLog(): Promise<void>;
|
|
23
|
-
getLogSizes(): Promise<{
|
|
24
|
-
logFile: number;
|
|
25
|
-
backupFile: number;
|
|
26
|
-
}>;
|
|
27
|
-
private getFileSize;
|
|
28
19
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { Platform } from 'react-native';
|
|
3
3
|
import { LoggerNative } from './services/LoggerNative';
|
|
4
4
|
import { LoggerWeb } from './services/LoggerWeb';
|
|
5
|
-
export const MAX_LOG_SIZE =
|
|
5
|
+
export const MAX_LOG_SIZE = 100 * 1024 * 1024;
|
|
6
6
|
export class BaseLogger {
|
|
7
7
|
constructor() {
|
|
8
8
|
this.logLevel = 'info';
|
|
@@ -72,47 +72,4 @@ export class BaseLogger {
|
|
|
72
72
|
getLogFileContent() { return this.impl.getLogFileContent(); }
|
|
73
73
|
getBackupLogFileContent() { return this.impl.getBackupLogFileContent(); }
|
|
74
74
|
clearLogFile() { return this.impl.clear(); }
|
|
75
|
-
// -------------------------
|
|
76
|
-
// ILogger interface compatibility
|
|
77
|
-
// -------------------------
|
|
78
|
-
get logFile() {
|
|
79
|
-
return this.impl.logFile || '';
|
|
80
|
-
}
|
|
81
|
-
async write(message) {
|
|
82
|
-
const line = `[${new Date().toISOString()}] ${message}`;
|
|
83
|
-
await this.impl.writeLine(line, MAX_LOG_SIZE);
|
|
84
|
-
}
|
|
85
|
-
async readLog() {
|
|
86
|
-
return this.impl.getLogFileContent();
|
|
87
|
-
}
|
|
88
|
-
async rotateLog() {
|
|
89
|
-
if (this.impl.rotateLog) {
|
|
90
|
-
await this.impl.rotateLog();
|
|
91
|
-
}
|
|
92
|
-
else {
|
|
93
|
-
// For Windows, force rotation by writing max size
|
|
94
|
-
await this.impl.writeLine('', Number.MAX_SAFE_INTEGER);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
async getLogSizes() {
|
|
98
|
-
const logSize = await this.getFileSize(this.impl.logFile);
|
|
99
|
-
const backupSize = await this.getFileSize(this.impl.backupZip || this.impl.tempFile || '');
|
|
100
|
-
return { logFile: logSize, backupFile: backupSize };
|
|
101
|
-
}
|
|
102
|
-
async getFileSize(path) {
|
|
103
|
-
if (!path)
|
|
104
|
-
return 0;
|
|
105
|
-
try {
|
|
106
|
-
// Try to use RNFS if available
|
|
107
|
-
const RNFS = require('@dr.pogodin/react-native-fs');
|
|
108
|
-
if (await RNFS.exists(path)) {
|
|
109
|
-
const stat = await RNFS.stat(path);
|
|
110
|
-
return stat.size;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
catch {
|
|
114
|
-
// Ignore
|
|
115
|
-
}
|
|
116
|
-
return 0;
|
|
117
|
-
}
|
|
118
75
|
}
|
package/dist/logger/Logger.d.ts
CHANGED
|
@@ -2,6 +2,6 @@ import { BaseLogger, LogLevel } from './BaseLogger';
|
|
|
2
2
|
export declare class Logger extends BaseLogger {
|
|
3
3
|
}
|
|
4
4
|
export declare const logger: Logger;
|
|
5
|
-
export type { ILogger, ILoggerImplementation,
|
|
5
|
+
export type { ILogger, ILoggerImplementation, } from './Logger.types';
|
|
6
6
|
export type { LogLevel };
|
|
7
7
|
export default logger;
|
|
@@ -13,7 +13,6 @@ export interface ILoggerImplementation {
|
|
|
13
13
|
backupZip?: string;
|
|
14
14
|
init(): Promise<void>;
|
|
15
15
|
writeLine(line: string, maxSize: number): Promise<void>;
|
|
16
|
-
rotateLog?(): Promise<void>;
|
|
17
16
|
getLogFileURL(): Promise<string>;
|
|
18
17
|
getLogFileContent(): Promise<string>;
|
|
19
18
|
getBackupLogFileContent(): Promise<string | null>;
|
|
@@ -24,48 +23,12 @@ export interface ILoggerImplementation {
|
|
|
24
23
|
* This is what consumers of the logger package should use
|
|
25
24
|
*/
|
|
26
25
|
export interface ILogger {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
readLog(): Promise<string>;
|
|
34
|
-
rotateLog(): Promise<void>;
|
|
35
|
-
getLogSizes(): Promise<{
|
|
36
|
-
logFile: number;
|
|
37
|
-
backupFile: number;
|
|
38
|
-
}>;
|
|
39
|
-
getLogFileURL?(): Promise<string>;
|
|
40
|
-
getLogFileContent?(): Promise<string>;
|
|
26
|
+
setLogLevel(level: LogLevel): void;
|
|
27
|
+
logDebug(className: string, methodName: string, message: string): void;
|
|
28
|
+
logInfo(className: string, methodName: string, message: string): void;
|
|
29
|
+
logError(className: string, methodName: string, message: string): void;
|
|
30
|
+
getLogFileURL(): Promise<string>;
|
|
31
|
+
getLogFileContent(): Promise<string>;
|
|
41
32
|
getBackupLogFileContent(): Promise<string | null>;
|
|
42
|
-
clearLogFile
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Configuration options for logger initialization
|
|
46
|
-
*/
|
|
47
|
-
export interface ILoggerConfig {
|
|
48
|
-
logLevel?: LogLevel;
|
|
49
|
-
maxLogSize?: number;
|
|
50
|
-
logDir?: string;
|
|
51
|
-
logFileName?: string;
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Log entry structure
|
|
55
|
-
*/
|
|
56
|
-
export interface ILogEntry {
|
|
57
|
-
timestamp: string;
|
|
58
|
-
level: LogLevel;
|
|
59
|
-
className?: string;
|
|
60
|
-
methodName?: string;
|
|
61
|
-
message: string;
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Log file information
|
|
65
|
-
*/
|
|
66
|
-
export interface ILogFileInfo {
|
|
67
|
-
path: string;
|
|
68
|
-
size: number;
|
|
69
|
-
exists: boolean;
|
|
70
|
-
lastModified?: Date;
|
|
33
|
+
clearLogFile(): Promise<void>;
|
|
71
34
|
}
|
|
@@ -9,9 +9,9 @@ export declare class LoggerNative implements ILoggerImplementation {
|
|
|
9
9
|
init(): Promise<void>;
|
|
10
10
|
writeLine(line: string, maxSize: number): Promise<void>;
|
|
11
11
|
private ensureDir;
|
|
12
|
-
rotateLog
|
|
12
|
+
private rotateLog;
|
|
13
13
|
getLogFileURL(): Promise<string>;
|
|
14
14
|
getLogFileContent(): Promise<any>;
|
|
15
|
-
getBackupLogFileContent(): Promise<
|
|
15
|
+
getBackupLogFileContent(): Promise<any>;
|
|
16
16
|
clear(): Promise<void>;
|
|
17
17
|
}
|
|
@@ -28,7 +28,7 @@ export class LoggerNative {
|
|
|
28
28
|
this.isRotating = false; // Rotation lock to prevent concurrent rotations
|
|
29
29
|
this.isAvailable = false;
|
|
30
30
|
const dir = 'unvired_logs_local';
|
|
31
|
-
const file = '
|
|
31
|
+
const file = 'applog_local.txt'; // main log file
|
|
32
32
|
if (!RNFS) {
|
|
33
33
|
console.warn('⚠️ LoggerNative: RNFS not available, logging to file system disabled');
|
|
34
34
|
this.logDir = '';
|
|
@@ -47,7 +47,7 @@ export class LoggerNative {
|
|
|
47
47
|
this.logDir = '';
|
|
48
48
|
}
|
|
49
49
|
this.logFile = `${this.logDir}/${file}`;
|
|
50
|
-
this.backupZip = `${this.logDir}/
|
|
50
|
+
this.backupZip = `${this.logDir}/backuplog_local.zip`;
|
|
51
51
|
}
|
|
52
52
|
async init() {
|
|
53
53
|
if (!this.isAvailable || !this.logDir || !RNFS)
|
|
@@ -174,7 +174,10 @@ export class LoggerNative {
|
|
|
174
174
|
if (!this.isAvailable || !RNFS)
|
|
175
175
|
return '';
|
|
176
176
|
try {
|
|
177
|
-
|
|
177
|
+
if (await RNFS.exists(this.logFile)) {
|
|
178
|
+
return await RNFS.readFile(this.logFile, 'utf8');
|
|
179
|
+
}
|
|
180
|
+
return '';
|
|
178
181
|
}
|
|
179
182
|
catch (e) {
|
|
180
183
|
console.error('❌ LoggerNative getLogFileContent error:', e);
|
|
@@ -185,9 +188,11 @@ export class LoggerNative {
|
|
|
185
188
|
if (!this.isAvailable || !RNFS)
|
|
186
189
|
return null;
|
|
187
190
|
try {
|
|
191
|
+
// Force rotation to ensure current logs are zipped
|
|
192
|
+
await this.rotateLog();
|
|
188
193
|
if (await RNFS.exists(this.backupZip)) {
|
|
189
|
-
|
|
190
|
-
return
|
|
194
|
+
// Return base64 content for download/upload
|
|
195
|
+
return await RNFS.readFile(this.backupZip, 'base64');
|
|
191
196
|
}
|
|
192
197
|
return null;
|
|
193
198
|
}
|
package/package.json
CHANGED