0.3.5 • Published 10 months ago

@juicyjah/juicy-logs-kit-svelte v0.3.5

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

juicy-logs-kit-svelte

The official logging tool for sending app logs and events to Juicy Logs from SvelteKit applications.

This package is meant to abstract the boiler plate of sending logs and events to the Juicy Logs servers, as well as subscribing to the event pubsub.

Signup for a free account at https://logs.juicyjah.com/signup and take the first step to a fresh and painless app logging and event pub/sub experience.

How to use

  1. Install the package with npm
npm i juicy-logs-kit-svelte
  1. Add to your SvelteKit app.
// src/hooks.server.js
import { sequence } from '@sveltejs/kit/hooks'
import { Logger } from "juicy-logs-kit-svelte"
...

const { hooks } = new Logger()

export const handle = sequence(hooks.handle, otherHandleFunction)

export const handleError = sequence(hooks.handleError, otherHandleErrorFunction)
  1. In your environment variables, provide the URL and API token needed to access your logs at Juicy Logs.
#.env

...
JUICY_LOGS_URL=https://logs.juicyjah.com
JUICY_LOGS_TOKEN=your-token-here
JUICY_LOGS_SOURCE_NAME=your-app-name-here
  1. Access your logs at https://logs.juicyjah.com

Configure your logs

You can customize the logging behavior by passing a configuration object when initializing the Logger:

const { hooks } = new Logger({
  log_debug: true,      // Enable/disable debug logs
  log_info: true,       // Enable/disable info logs
  log_error: true,      // Enable/disable error logs
  log_warn: true,       // Enable/disable warning logs
  log_http_methods: ['GET', 'POST', 'PUT', 'DELETE'],  // HTTP methods to log
  exclude_http_methods: [],  // HTTP methods to exclude from logging
  log_http_status_codes: [200, 201, 400, 401, 403, 404, 500], // Status codes to log
  exclude_http_status_codes: [], // Status codes to exclude from logging
  exclude_routes: ['/health-check'], // Routes to exclude from logging
  console: false        // Enable console logging in addition to sending to Juicy Logs
})

All configuration options are optional and will use sensible defaults if not specified.

Configuration Options

OptionTypeDefaultDescription
log_debugbooleantrueControls whether debug-level logs are processed and sent to Juicy Logs
log_infobooleantrueControls whether info-level logs are processed and sent to Juicy Logs
log_errorbooleantrueControls whether error-level logs are processed and sent to Juicy Logs
log_warnbooleantrueControls whether warning-level logs are processed and sent to Juicy Logs
log_http_methodsstring[]'CONNECT', 'DELETE', 'GET', 'HEAD', 'OPTIONS', 'PATCH', 'POST', 'PUT', 'TRACE'List of HTTP methods that should be logged
exclude_http_methodsstring[][]List of HTTP methods that should be excluded from logging. Takes precedence over log_http_methods
log_http_status_codesnumber[]100-511List of HTTP status codes that should be logged. Defaults to all standard HTTP status codes
exclude_http_status_codesnumber[][]List of HTTP status codes that should be excluded from logging. Takes precedence over log_http_status_codes
exclude_routesstring[][]List of route patterns that should be excluded from logging (e.g. '/health-check', '/api/metrics')
consolebooleanfalseWhen true, logs will also be output to the console in addition to being sent to Juicy Logs

Using Events

Juicy Logs supports event pushing for tracking important application events. To use events:

import { EventPusher } from "juicy-logs-kit-svelte"

// Create an event pusher instance
const eventPusher = new EventPusher()

// Push a simple event with just a message
await eventPusher.push("User logged in")

// Push a detailed event
await eventPusher.push({
  type: "user_action",        // Event type for categorization
  type_id: "login",          // Specific event identifier
  action: "login_successful", // The action that occurred
  message: "User successfully logged in",  // Human-readable message
  data: {                    // Additional event data
    userId: "123",
    timestamp: new Date(),
    browser: "Chrome"
  }
})

// You can also use the static method
await EventPusher.push({
  type: "system_event",
  message: "Application started"
})

Events require either a type or type_id field to be specified when sending detailed events. The message field is optional but recommended for better readability in your event logs.

Event Fields

FieldTypeRequiredDescription
typestringYes*Category or classification of the event (e.g., 'user_action', 'system_event')
type_idstringYes*Category or classification ID of the event (e.g., 'asflsdfuilur-134cadsrfq34-asfae23')
messagestringNoHuman-readable description of the event
dataobjectNoAdditional structured data related to the event
sourcestringNoSource of the event (defaults to JUICY_LOGS_SOURCE_NAME from env)

* Either type or type_id must be specified for detailed events

You can view your events in the Events section of your Juicy Logs dashboard at https://logs.juicyjah.com.

TODO

  • Add events pubsub subscription functionality
  • Add more request metadata logging (headers, user agent, etc.)
  • Add support for custom log formatters
  • Add batch event processing
0.3.5

10 months ago

0.3.4

10 months ago

0.3.3

10 months ago

0.3.2

10 months ago

0.3.1

10 months ago

0.3.0

10 months ago

0.2.3

10 months ago

0.2.2

10 months ago

0.2.1

11 months ago

0.2.0

11 months ago

0.1.7

11 months ago

0.1.6

11 months ago

0.1.5

11 months ago

0.1.4

11 months ago

0.1.3

11 months ago

0.1.2

11 months ago

0.1.1

11 months ago

0.1.0

11 months ago