Logs

Learn how to send, filter, and analyze logs from your applications using Reasonable.

Log Levels

Reasonable supports standard log levels to help you categorize and filter your logs based on their severity and importance.

LevelDescriptionWhen to use
debugDetailed information for debuggingDuring development or when troubleshooting issues
infoGeneral information about system operationFor normal application events like user actions, successful operations
warnWarning conditions that might need attentionFor non-critical issues that don't prevent the application from working
errorError conditions that need immediate attentionFor errors that prevent a function from working correctly
fatalCritical errors that cause the application to crashFor severe errors that prevent the application from continuing to run

If you don't specify a log level, Reasonable will default to the "info" level.

Sending Logs

Here's how to send logs to Reasonable using our SDKs:

// Basic logging
reasonable.debug('Debugging information');
reasonable.info('User logged in', { userId: '123' });
reasonable.warn('API rate limit approaching', { endpoint: '/api/users', remaining: 10 });
reasonable.error('Failed to process payment', { orderId: '456', error: 'Invalid card' });
reasonable.fatal('Database connection lost', { database: 'users' });

// Logging with context
const orderContext = reasonable.withContext({ orderId: '789' });
orderContext.info('Order created');
orderContext.info('Payment processed');
orderContext.info('Order shipped');

// Logging with tags
reasonable.info('User registered', { userId: '123' }, { tags: ['user', 'registration'] });

// Logging with a timestamp
reasonable.info('Event occurred', {}, { timestamp: new Date('2023-01-01T12:00:00Z') });

Structured Logging

Structured logging allows you to include additional context with your logs, making them more useful for debugging and analysis.

Best Practices

  • Be consistent with field names - Use the same field names across your application for the same types of data.
  • Use nested objects sparingly - While nested objects are supported, they can make filtering and searching more complex.
  • Include relevant context - Add fields that will help you understand the log entry later, such as user IDs, request IDs, and other identifiers.
  • Don't log sensitive information - Avoid logging passwords, API keys, or other sensitive data.
// Simple structured log
reasonable.info('User registered', {
  userId: '123',
  email: 'john@example.com',
  plan: 'pro',
  referrer: 'google'
});

// Structured log with nested objects
reasonable.info('Order completed', {
  order: {
    id: '456',
    amount: 99.99,
    currency: 'USD',
    items: [
      { id: '1', name: 'Product A', price: 49.99, quantity: 1 },
      { id: '2', name: 'Product B', price: 24.99, quantity: 2 }
    ]
  },
  customer: {
    id: '123',
    name: 'John Doe',
    email: 'john@example.com'
  },
  shipping: {
    method: 'express',
    address: {
      street: '123 Main St',
      city: 'New York',
      state: 'NY',
      zip: '10001'
    }
  }
});

Searching and Filtering Logs

Reasonable provides powerful search and filtering capabilities to help you find the logs you need.

Search Syntax

You can use the following syntax to search and filter your logs:

SyntaxDescriptionExample
field:valueSearch for logs where the field equals the valuelevel:error
field:"value with spaces"Search for logs where the field equals the value with spacesmessage:"user logged in"
field:>valueSearch for logs where the field is greater than the valueorder.amount:>100
field:<valueSearch for logs where the field is less than the valueorder.amount:<50
field:value1 OR field:value2Search for logs where the field equals value1 or value2level:error OR level:fatal
field:value1 AND field:value2Search for logs where the field equals value1 and value2level:error AND service:api
field:*value*Search for logs where the field contains the valuemessage:*error*
-field:valueSearch for logs where the field does not equal the value-level:debug

Common Search Examples

  • level:error - Find all error logs
  • userId:123 - Find all logs for a specific user
  • message:*payment* - Find all logs with "payment" in the message
  • level:error AND service:api - Find all error logs from the API service
  • timestamp:>2023-01-01 - Find all logs after January 1, 2023
  • level:error OR level:fatal - Find all error or fatal logs
  • -level:debug - Exclude debug logs

Log Retention

Reasonable retains your logs based on your subscription plan:

PlanRetention Period
Free7 days
Pro30 days
EnterpriseCustom (up to 1 year)

Next Steps

Now that you understand how to work with logs in Reasonable, you might want to explore these related topics: