JavaScript error tracking and monitoring library for Node.js and browser environments with telemetry, automatic error grouping, and real-time notifications
—
Core error and message logging functionality providing multiple severity levels with flexible argument patterns and automatic error enrichment.
General purpose logging method that accepts multiple argument types.
/**
* Log a message or error at the 'log' level
* @param args - Variable arguments: message, error, object, callback, etc.
* @returns Object containing the UUID of the logged item
*/
function log(...args: LogArgument[]): LogResult;Usage Examples:
// String message
rollbar.log('User action completed');
// Error object
rollbar.log(new Error('Something went wrong'));
// Message with additional data
rollbar.log('User action', { userId: 123, action: 'login' });
// Message with callback
rollbar.log('Processing data', (err, data) => {
if (err) console.error('Failed to log:', err);
});
// Multiple arguments
rollbar.log('Payment processed', paymentData, user, callback);Debug level logging for detailed diagnostic information.
/**
* Log a message or error at the 'debug' level
* @param args - Variable arguments: message, error, object, callback, etc.
* @returns Object containing the UUID of the logged item
*/
function debug(...args: LogArgument[]): LogResult;Informational logging for general application events.
/**
* Log a message or error at the 'info' level
* @param args - Variable arguments: message, error, object, callback, etc.
* @returns Object containing the UUID of the logged item
*/
function info(...args: LogArgument[]): LogResult;Warning level logging for potential issues that don't stop execution.
/**
* Log a message or error at the 'warning' level
* @param args - Variable arguments: message, error, object, callback, etc.
* @returns Object containing the UUID of the logged item
*/
function warn(...args: LogArgument[]): LogResult;Alias for the warn method.
/**
* Log a message or error at the 'warning' level (alias for warn)
* @param args - Variable arguments: message, error, object, callback, etc.
* @returns Object containing the UUID of the logged item
*/
function warning(...args: LogArgument[]): LogResult;Error level logging for exceptions and failures.
/**
* Log a message or error at the 'error' level
* @param args - Variable arguments: message, error, object, callback, etc.
* @returns Object containing the UUID of the logged item
*/
function error(...args: LogArgument[]): LogResult;Usage Examples:
// Log caught exception
try {
riskyOperation();
} catch (err) {
rollbar.error(err);
}
// Log error with context
rollbar.error('Database connection failed', {
host: 'db.example.com',
port: 5432,
retries: 3
});Critical level logging for severe errors requiring immediate attention.
/**
* Log a message or error at the 'critical' level
* @param args - Variable arguments: message, error, object, callback, etc.
* @returns Object containing the UUID of the logged item
*/
function critical(...args: LogArgument[]): LogResult;Wait for all pending items to be sent before executing callback.
/**
* Wait for all pending items to be sent to Rollbar
* @param callback - Function to call when all items are sent
*/
function wait(callback: () => void): void;Usage Example:
// Ensure all logs are sent before shutting down
rollbar.error('Critical system error');
rollbar.wait(() => {
console.log('All logs sent, shutting down...');
process.exit(1);
});Get the last error that occurred in Rollbar itself.
/**
* Get the last error that occurred within Rollbar
* @returns The last error or null if no errors
*/
function lastError(): MaybeError;Build a JSON payload from item data for manual sending.
/**
* Build JSON payload from item data
* @param item - Item data to convert to JSON
* @returns JSON string representation of the item
*/
function buildJsonPayload(item: any): string;Send a pre-built JSON payload to Rollbar.
/**
* Send a pre-built JSON payload to Rollbar
* @param jsonPayload - JSON string to send
*/
function sendJsonPayload(jsonPayload: string): void;type LogArgument = string | Error | object | Dictionary | Callback | Date | any[] | undefined;
interface LogResult {
uuid: string;
}
type MaybeError = Error | undefined | null;
type Level = 'debug' | 'info' | 'warning' | 'error' | 'critical';
interface Callback<TResponse = any> {
(err: MaybeError, response: TResponse): void;
}
type Dictionary = { [key: string]: unknown };The logging methods accept flexible argument patterns:
rollbar.error('Something happened')rollbar.error(new Error('Failed'))rollbar.error('Operation failed', error)rollbar.error('Failed to process', { userId: 123 })rollbar.error('Failed', data, callback)rollbar.error(error, { context: 'payment' })rollbar.error('Payment failed', error, userData, callback)The library automatically determines the appropriate handling based on argument types.
Install with Tessl CLI
npx tessl i tessl/npm-rollbar