near-logger
v1.1.4197
Published
npm Package - near-logger
Readme
near-logger
A lightweight npm package for reading and writing logs to NEAR smart contracts.
Installation
npm install near-logger
Usage
import { getLogs, writeLog, getLogCount, getLogsByLevel, clearLogs } from 'near-logger'; import * as nearApiJs from 'near-api-js';
Get Logs
const logs = await getLogs('mycontract.near', 20, 'mainnet'); console.log(logs);
Write a Log
await writeLog( { contractId: 'mycontract.near', level: 'info', message: 'Hello NEAR' }, account, keyPair // optional );
Get Log Count
const count = await getLogCount('mycontract.near', 'testnet');
console.log(Total logs: ${count});
Get Logs by Level
const errors = await getLogsByLevel('mycontract.near', 'error', 'mainnet'); console.log(errors);
Clear Logs
await clearLogs('mycontract.near', account, keyPair);
API
| Function | Description |
|---|---|
| getLogs(contractId, limit?, networkId?) | Fetch recent logs from a contract |
| writeLog(entry, account, keyPair?) | Write a log entry to a contract |
| getLogCount(contractId, networkId?) | Get total number of logs |
| getLogsByLevel(contractId, level, networkId?) | Filter logs by level |
| clearLogs(contractId, account, keyPair?) | Clear all logs from a contract |
Types
LogLevel:'info' | 'warn' | 'error' | 'debug'LogEntry:{ contractId, level, message, timestamp, txHash }
License
MIT
