@rabby-wallet/rabby-logger
v0.3.0
Published
Rabby log parser and platform-agnostic logger core with rolling zip writer
Downloads
361
Readme
@rabby-wallet/rabby-logger
Platform-agnostic Rabby log parsing and writing primitives.
This package provides:
- parsing for Rabby
.logfiles and exported.ziparchives @rabby-log/v1line formatting- a generic rolling zip writer
- a generic logger core
It does not ship platform-specific storage or lifecycle adapters.
Install
npm install @rabby-wallet/rabby-loggerParse logs
import {
mergeParsedLogInputs,
parseRabbyLogInputBytes,
} from "@rabby-wallet/rabby-logger";
const inputs = await Promise.all(
files.map(async (file) =>
parseRabbyLogInputBytes(file.name, await file.arrayBuffer()),
),
);
const dataset = mergeParsedLogInputs(inputs);
console.log(dataset.records[0]?.message);Write logs
Most hosts should not implement a new writer from scratch.
Recommended path:
- implement
LoggingFileSystemAdapter - use the built-in
RollingZipLogWriter - pass it to
AppLogger
import {
AppLogger,
RollingZipLogWriter,
type LoggingFileSystemAdapter,
} from "@rabby-wallet/rabby-logger";
const myFsAdapter: LoggingFileSystemAdapter = {
mkdir: async (path) => {},
readFile: async (path, encoding) => "...",
writeFile: async (path, contents, encoding) => {},
appendFile: async (path, contents, encoding) => {},
moveFile: async (from, to) => {},
listFiles: async (path) => [],
unlink: async (path) => {},
};
const writer = new RollingZipLogWriter({
fs: myFsAdapter,
rootDir: "/applogs",
archivePrefix: "rabby-mobile-logs",
});
const logger = new AppLogger({
runtimeEnv: "production",
platform: "ios",
writer,
shouldWriteToFile: () => true,
shouldCaptureConsole: () => true,
});
logger.installConsoleCapture();
logger.info("app boot");
await logger.flush();
await logger.finalizeArchive();Bring Your Own Writer
If your host already owns archive layout, rotation, or native zip writing,
implement AppLogWriter instead of LoggingFileSystemAdapter.
import { AppLogger, type AppLogWriter } from "@rabby-wallet/rabby-logger";
class NativeArchiveWriter implements AppLogWriter {
async writeLine(line: string) {
await nativeLogger.appendUtf8Line(line);
}
async flush() {
await nativeLogger.flush();
}
async finalizeArchive() {
return nativeLogger.finalizeZip();
}
getState() {
return {
rootDir: "/native/applogs",
activeArchivePath: nativeLogger.currentArchivePath(),
};
}
}
const logger = new AppLogger({
runtimeEnv: "production",
platform: "android",
writer: new NativeArchiveWriter(),
shouldWriteToFile: () => true,
});React Native Example
This is the same integration shape used by Rabby Mobile: react-native-fs
provides the file operations, while RollingZipLogWriter keeps ownership of
formatting, entry rotation, and archive finalization.
import { Platform } from "react-native";
import RNFS from "react-native-fs";
import {
AppLogger,
RollingZipLogWriter,
type LoggingFileSystemAdapter,
} from "@rabby-wallet/rabby-logger";
const rnfsLoggingAdapter: LoggingFileSystemAdapter = {
mkdir(path) {
return RNFS.mkdir(path, { NSURLIsExcludedFromBackupKey: true });
},
readFile(path, encoding) {
return RNFS.readFile(path, encoding);
},
writeFile(path, contents, encoding) {
return RNFS.writeFile(path, contents, encoding);
},
appendFile(path, contents, encoding) {
return RNFS.appendFile(path, contents, encoding);
},
moveFile(from, to) {
return RNFS.moveFile(from, to);
},
async listFiles(path) {
const entries = await RNFS.readDir(path);
return entries.filter(item => item.isFile()).map(item => ({
name: item.name,
path: item.path,
size: item.size,
mtimeMs: item.mtime ? item.mtime.getTime() : undefined,
}));
},
unlink(path) {
return RNFS.unlink(path);
},
};
const writer = new RollingZipLogWriter({
fs: rnfsLoggingAdapter,
rootDir: `${RNFS.DocumentDirectoryPath}/applogs`,
archivePrefix: "rabby-mobile-logs",
});
export const logger = new AppLogger({
runtimeEnv: "production",
platform: Platform.OS,
writer,
shouldWriteToFile: () => true,
shouldCaptureConsole: () => true,
});Host responsibilities
The host application must provide:
- either a
LoggingFileSystemAdapterforRollingZipLogWriter, or anAppLogWriter - its own app lifecycle integration
- any platform-specific file sharing or export flow
Repository-only development notes live under packages/rabby-logger/docs/.
