@serkankuyu/catchlogs
v2.1.6
Published
Error logs daily for developers
Readme
Catchlogs
Catchlogs is a powerful error tracking platform designed for developers. It helps you instantly detect and respond to errors in your applications.
Why Catchlogs?
While identifying errors in local development is usually straightforward, once your project goes live, errors can go unnoticed without user feedback. This leads to poor user experience and potential reputation damage. Catchlogs solves this by capturing and analyzing errors in real-time.
Features
- Automatic Error Capture: Automatically catches uncaught exceptions
- Promise Error Handling: Automatically catches unhandled promise rejections
- Try-Catch Integration: Easily send errors from try-catch blocks
- Channel Support: Organize logs by different channels (e.g., production, staging, development)
- Quick Setup: Easy integration with npm
- Framework Agnostic: Works with all JavaScript projects
Getting Started
Sign in with Google Sign in to Catchlogs with your Google account to obtain your API key.
Install Catchlogs
npm i @serkankuyu/catchlogs- Integrate Catchlogs
Basic Usage
import catchlogs from '@serkankuyu/catchlogs';
// Initialize the SDK with a specific channel
const logger = new catchlogs('API_KEY', 'production'); // channel is optional, defaults to 'default'
logger.init();
// All uncaught errors will now be automatically logged to the specified channelMultiple Channels Example
// Different loggers for different environments or purposes
const productionLogger = new catchlogs('API_KEY', 'production');
const stagingLogger = new catchlogs('API_KEY', 'staging');
const developmentLogger = new catchlogs('API_KEY', 'development');
// Initialize the appropriate logger based on your environment
const logger = process.env.NODE_ENV === 'production' ? productionLogger : developmentLogger;
logger.init();Vue.js Integration
// main.js
import { createApp } from 'vue'
import catchlogs from '@serkankuyu/catchlogs'
import App from './App.vue'
const logger = new catchlogs('API_KEY', 'vue-errors');
logger.init();
const app = createApp(App)
app.config.errorHandler = (error) => {
catchlogs.catch(error);
}
app.mount('#app')React Integration
// index.js or App.js
import React from 'react';
import catchlogs from '@serkankuyu/catchlogs';
const logger = new catchlogs('API_KEY', 'react-errors');
logger.init();
class ErrorBoundary extends React.Component {
componentDidCatch(error, errorInfo) {
catchlogs.catch(error);
}
render() {
return this.props.children;
}
}
// Wrap your application with ErrorBoundary
<ErrorBoundary>
<App />
</ErrorBoundary>Try-Catch Usage
import catchlogs from '@serkankuyu/catchlogs';
// Initialize with a specific channel for try-catch errors
const logger = new catchlogs('API_KEY', 'try-catch-errors');
logger.init();
try {
// Code that might throw an error
throw new Error('An error occurred');
} catch (error) {
catchlogs.catch(error);
}Async/Await Usage
import catchlogs from '@serkankuyu/catchlogs';
// Initialize with a specific channel for API errors
const logger = new catchlogs('API_KEY', 'api-errors');
logger.init();
async function fetchData() {
try {
const response = await fetch('https://api.example.com/data');
const data = await response.json();
return data;
} catch (error) {
catchlogs.catch(error);
throw error;
}
}Environment Based Channel Example
import catchlogs from '@serkankuyu/catchlogs';
// Channel seçimi ortama göre otomatik yapılır
const channel = process.env.NODE_ENV === 'production'
? 'production'
: process.env.NODE_ENV === 'staging'
? 'staging'
: 'development';
const logger = new catchlogs('API_KEY', channel);
logger.init();
// Tüm hatalar otomatik olarak doğru kanala gönderilecekCustom Error Reporting
const logger = new catchlogs('API_KEY', 'custom-monitoring');
async function sendCustomError(data) {
try {
const requestData = {
message: data,
type: 'custom',
severity: 'high',
component: 'payment-service',
timestamp: new Date().toISOString()
};
const result = await logger.sendCatchlogs(requestData);
console.log('Log sent successfully:', result);
} catch (error) {
console.error('Error sending log:', error.message);
}
}Support
If you encounter any issues or have questions, feel free to reach out through [email protected]
