GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - CarmenSoftware-dev/nestjs-loki-log-sample

BranchesTags
Open more actions menu

Latest commit

 

History

2 Commits
2 Commits

Folders and files

NameName
Last commit message
Last commit date
scripts
scripts
 
 
src
src
 
 
test
test
 
 
.gitignore
.gitignore
 
 
README.md
README.md
 
 
env.example
env.example
 
 
eslint.config.mjs
eslint.config.mjs
 
 
nest-cli.json
nest-cli.json
 
 
package-lock.json
package-lock.json
 
 
package.json
package.json
 
 
tsconfig.build.json
tsconfig.build.json
 
 
tsconfig.json
tsconfig.json
 
 

Repository files navigation

NestJS Loki Logger Sample

โปรเจคตัวอย่างสำหรับการใช้งาน NestJS พร้อมกับ Loki logging system และ Swagger API documentation

🚀 Features

  • NestJS Framework - Modern Node.js framework
  • Loki Logging - Centralized logging system
  • Swagger/OpenAPI - Interactive API documentation
  • TypeScript - Full type safety
  • Validation - Request validation with class-validator
  • Structured Logging - Advanced logging capabilities

📋 Prerequisites

  • Node.js 18+
  • npm หรือ yarn
  • Docker (สำหรับ Loki)

🛠️ Installation

# Clone repository
git clone <repository-url>
cd nest-loki-log-sample

# Install dependencies
npm install

# Copy environment file
cp .env.example .env

# Edit environment variables
nano .env

⚙️ Environment Variables

สร้างไฟล์ .env ในโฟลเดอร์หลัก:

# Application Configuration
NODE_ENV=development
PORT=4000
APP_NAME=nest-loki-logger

# Logging Configuration
LOG_LEVEL=info

# Loki Configuration
LOKI_HOST=localhost
LOKI_PORT=3100
LOKI_PROTOCOL=http
LOKI_USERNAME=
LOKI_PASSWORD=

# Swagger Configuration
SWAGGER_TITLE=NestJS Loki Logger API
SWAGGER_DESCRIPTION=API สำหรับการทดสอบ NestJS พร้อมกับ Loki logging system
SWAGGER_VERSION=1.0

🐳 Running Loki

# Start Loki with Docker Compose
npm run loki:up

# Check logs
npm run loki:logs

# Stop Loki
npm run loki:down

🚀 Running the Application

# Development mode
npm run start:dev

# Production build
npm run build
npm run start:prod

# Debug mode
npm run start:debug

📚 API Documentation

หลังจากรันแอปพลิเคชันแล้ว สามารถเข้าถึง Swagger UI ได้ที่:

URL: http://localhost:4000/api

Available Endpoints

App Controller

  • GET / - Root endpoint

Example Controller

  • GET /example - Hello endpoint
  • GET /example/performance - Performance test
  • POST /example/users - Create user
  • GET /example/users/:id - Get user by ID
  • GET /example/error - Trigger error test
  • GET /example/structured - Structured logging test

🧪 Testing

# Unit tests
npm run test

# E2E tests
npm run e2e

# Test coverage
npm run test:cov

# Test logging functionality
npm run test:logging

📝 Logging Examples

โปรเจคนี้มีตัวอย่างการใช้งาน logging หลายรูปแบบ:

Basic Logging

this.logger.log('Message', 'Context');
this.logger.error('Error message', 'stack trace', 'Context');
this.logger.warn('Warning message', 'Context');

Performance Logging

this.logger.logPerformance('operation_name', duration, 'Context');

Business Event Logging

this.logger.logBusinessEvent('user_created', userData, 'Context');

Structured Logging with Custom Labels

this.logger.logWithLabels('Message', customLabels, 'Context');

🏗️ Project Structure

src/
├── config/           # Configuration files
├── controllers/      # API controllers
├── dto/             # Data Transfer Objects
├── modules/         # Feature modules
├── services/        # Business logic services
└── main.ts          # Application entry point

🔧 Development

Adding New Endpoints

  1. สร้าง DTO ใน src/dto/
  2. เพิ่ม Swagger decorators
  3. สร้าง controller method
  4. อัปเดต Swagger documentation

Adding New DTOs

import { ApiProperty } from '@nestjs/swagger';
import { IsString, IsNotEmpty } from 'class-validator';

export class NewDto {
  @ApiProperty({
    description: 'Description',
    example: 'Example value'
  })
  @IsString()
  @IsNotEmpty()
  field: string;
}

📊 Monitoring

  • Loki: http://localhost:3100
  • Application: http://localhost:4000
  • API Docs: http://localhost:4000/api

🤝 Contributing

  1. Fork the repository
  2. Create feature branch
  3. Commit changes
  4. Push to branch
  5. Create Pull Request

📄 License

This project is licensed under the MIT License.

About

No description, website, or topics provided.

Resources

Readme
Activity

Stars

0 stars

Watchers

0 watching

Forks

0 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.