updated some docs and removed some
This commit is contained in:
parent
2aaeba2f6c
commit
fe96cf6679
7 changed files with 109 additions and 734 deletions
|
|
@ -1,18 +1,16 @@
|
|||
# Loki Logging for Stock Bot
|
||||
|
||||
This document outlines how to use the Loki logging system integrated with the Stock Bot platform.
|
||||
This document outlines how to use the Loki logging system integrated with the Stock Bot platform (Updated June 2025).
|
||||
|
||||
## Overview
|
||||
|
||||
Loki is a horizontally-scalable, highly-available, multi-tenant log aggregation system inspired by Prometheus. It is designed to be very cost effective and easy to operate. Unlike other logging systems, Loki is built around the idea of only indexing metadata about your logs (labels), not the full text. This makes Loki more resource-efficient than traditional log storage systems.
|
||||
Loki provides centralized logging for all Stock Bot services with:
|
||||
|
||||
For Stock Bot, Loki provides:
|
||||
|
||||
1. Centralized logging for all services
|
||||
2. Log aggregation and filtering by service, level, and custom labels
|
||||
3. Integration with Grafana for visualization
|
||||
4. Query capabilities for log analysis
|
||||
5. Alert capabilities for critical issues
|
||||
1. **Centralized logging** for all microservices
|
||||
2. **Log aggregation** and filtering by service, level, and custom labels
|
||||
3. **Grafana integration** for visualization and dashboards
|
||||
4. **Query capabilities** using LogQL for log analysis
|
||||
5. **Alert capabilities** for critical issues
|
||||
|
||||
## Getting Started
|
||||
|
||||
|
|
@ -23,7 +21,7 @@ For Stock Bot, Loki provides:
|
|||
scripts\docker.ps1 monitoring
|
||||
```
|
||||
|
||||
You can also start Loki directly using Docker Compose:
|
||||
Or start services individually:
|
||||
|
||||
```cmd
|
||||
# Start Loki service only
|
||||
|
|
@ -43,21 +41,21 @@ Once started:
|
|||
|
||||
## Using the Logger in Your Services
|
||||
|
||||
The Stock Bot logger has been enhanced to automatically send logs to Loki. Here's how to use it:
|
||||
The Stock Bot logger automatically sends logs to Loki using the updated pattern:
|
||||
|
||||
```typescript
|
||||
import { Logger, LogLevel } from '@stock-bot/utils';
|
||||
import { getLogger } from '@stock-bot/logger';
|
||||
|
||||
// Create a logger for your service
|
||||
const logger = new Logger('your-service-name', LogLevel.INFO);
|
||||
const logger = getLogger('your-service-name');
|
||||
|
||||
// Log at different levels
|
||||
logger.debug('Detailed information for debugging');
|
||||
logger.info('General information about operations');
|
||||
logger.warn('Potential issues that don't affect operation');
|
||||
logger.warn('Potential issues that don\'t affect operation');
|
||||
logger.error('Critical errors that require attention');
|
||||
|
||||
// Log with structured data (will be searchable in Loki)
|
||||
// Log with structured data (searchable in Loki)
|
||||
logger.info('Processing trade', {
|
||||
symbol: 'MSFT',
|
||||
price: 410.75,
|
||||
|
|
@ -107,10 +105,10 @@ Inside Grafana, you can use these LogQL queries to analyze your logs:
|
|||
|
||||
## Testing the Logging Integration
|
||||
|
||||
A test script is provided to verify the logging integration:
|
||||
Test the logging integration using Bun:
|
||||
|
||||
```bash
|
||||
# Run from project root
|
||||
```cmd
|
||||
# Run from project root using Bun (current runtime)
|
||||
bun run tools/test-loki-logging.ts
|
||||
```
|
||||
|
||||
|
|
@ -120,8 +118,8 @@ Our logging implementation follows this architecture:
|
|||
|
||||
```
|
||||
┌─────────────────┐ ┌─────────────────┐
|
||||
│ Trading Services│────►│ @stock-bot/utils│
|
||||
└─────────────────┘ │ Logger │
|
||||
│ Trading Services│────►│ @stock-bot/logger│
|
||||
└─────────────────┘ │ getLogger() │
|
||||
└────────┬────────┘
|
||||
│
|
||||
▼
|
||||
|
|
@ -163,9 +161,9 @@ If logs aren't appearing in Grafana:
|
|||
type .env | findstr "LOKI_"
|
||||
```
|
||||
|
||||
4. Ensure your service has the latest @stock-bot/utils package
|
||||
4. Ensure your service has the latest @stock-bot/logger package
|
||||
|
||||
5. Check for errors in the Loki container logs:
|
||||
```cmd
|
||||
docker logs trading-bot-loki
|
||||
docker logs stock-bot-loki
|
||||
```
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue