1.0.2 • Published 1 year ago
rsc-logger v1.0.2
React Server Component Logger
A beautiful and highly configurable network request logger for react server components.
Install
npm install rsc-logger
yarn add rsc-logger
Usage
import RSC_LOGGER from 'rsc-logger';
// Init in any file
export const logger = RSC_LOGGER.init();
// page.tsx
export default function Home() {
logger.attachLogger();
return (...);
}
Configure Example
import RSC_LOGGER from './rsc-logger';
export const logger = RSC_LOGGER.init({
mode: 'debug',
type: 'fetch',
columns: ['requestType', 'responseStatus', 'duration', 'url', 'responseSize', 'timestamp'],
urlOptions: { host: false, pathname: 'short', search: true },
});
API
RSC_LOGGER.init(options);
logger.attachLogger();
logger.removeLogger();
options
type LogModes = 'info' | 'debug' | 'error';
type LogTypes = 'all' | 'fetch' | 'image' | 'js' | 'css' | 'html' | 'unknown';
type Columns =
| 'requestType'
| 'responseStatus'
| 'duration'
| 'url'
| 'responseSize'
| 'filename'
| 'timestamp';
type URLOptions = { host?: boolean; pathname?: 'full' | 'short'; search?: boolean };
type LoggerType = {
mode?: LogModes;
type?: LogTypes;
columns?: Columns[];
urlOptions?: URLOptions;
};