logologo
Bắt đầu
Hướng dẫn
Phát triển
Plugin
API
English
简体中文
日本語
한국어
Deutsch
Français
Español
Português
Русский
Italiano
Türkçe
Українська
Tiếng Việt
Bahasa Indonesia
ไทย
Polski
Nederlands
Čeština
العربية
עברית
हिन्दी
Svenska
Bắt đầu
Hướng dẫn
Phát triển
Plugin
API
logologo
Tổng quan API

@nocobase/auth

AuthManager
Auth
BaseAuth

@nocobase/cache

CacheManager
Cache

@nocobase/cli

Giao diện dòng lệnh NocoBase
Biến Môi Trường Toàn Cầu

@nocobase/client

Ứng dụng
Plugin

@nocobase/database

bộ sưu tập
Trường

interfaces

BaseInterface
Các Toán Tử Lọc

RelationRepository

BelongsToManyRepository
belongs-to-repository
HasManyRepository
HasOneRepository
Repository

shared

create-options
destroy-options
find-one
Bắt đầu với Bộ sưu tập
transaction
update-options

@nocobase/data-source-manager

DataSourceManager
DataSource (trừu tượng)
ICollectionManager
ICollection
IField
IModel
IRepository

@nocobase/flow-engine

Trình quản lý nguồn dữ liệu
Ngữ cảnh luồng
FlowEngine
FlowModel
Tài nguyên luồng

@nocobase/logger

Logger

@nocobase/server

AppCommand
Ứng dụng
AuditManager
Ngữ cảnh
Di chuyển
Plugin

@nocobase/sdk

Auth
Storage
Previous PageTài nguyên luồng
Next PageAppCommand
TIP

Tài liệu này được dịch bởi AI. Đối với bất kỳ thông tin không chính xác nào, vui lòng tham khảo phiên bản tiếng Anh

#Logger

#Tạo Logger

#createLogger()

Tạo một logger tùy chỉnh.

#Chữ ký

  • createLogger(options: LoggerOptions)

#Kiểu

interface LoggerOptions
  extends Omit<winston.LoggerOptions, 'transports' | 'format'> {
  dirname?: string;
  filename?: string;
  format?: 'logfmt' | 'json' | 'delimiter' | 'console' | winston.Logform.Format;
  transports?: ('console' | 'file' | 'dailyRotateFile' | winston.transport)[];
}

#Chi tiết

Thuộc tínhMô tả
dirnameThư mục đầu ra của nhật ký
filenameTên tệp nhật ký
formatĐịnh dạng nhật ký
transportsPhương thức xuất nhật ký

#createSystemLogger()

Tạo các nhật ký hệ thống được in theo một phương thức quy định. Tham khảo Logger - Nhật ký hệ thống

#Chữ ký

  • createSystemLogger(options: SystemLoggerOptions)

#Kiểu

export interface SystemLoggerOptions extends LoggerOptions {
  seperateError?: boolean; // print error seperately, default true
}

#Chi tiết

Thuộc tínhMô tả
seperateErrorCó xuất riêng các nhật ký cấp độ error hay không

#requestLogger()

Middleware để ghi nhật ký yêu cầu và phản hồi API.

app.use(requestLogger(app.name));

#Chữ ký

  • requestLogger(appName: string, options?: RequestLoggerOptions): MiddewareType

#Kiểu

export interface RequestLoggerOptions extends LoggerOptions {
  skip?: (ctx?: any) => Promise<boolean>;
  requestWhitelist?: string[];
  responseWhitelist?: string[];
}

#Chi tiết

Thuộc tínhKiểuMô tảGiá trị mặc định
skip(ctx?: any) => Promise<boolean>Bỏ qua việc ghi nhật ký cho một số yêu cầu dựa trên ngữ cảnh yêu cầu.-
requestWhiteliststring[]Danh sách trắng các thông tin yêu cầu được in trong nhật ký.[ 'action', 'header.x-role', 'header.x-hostname', 'header.x-timezone', 'header.x-locale','header.x-authenticator', 'header.x-data-source', 'referer']
responseWhiteliststring[]Danh sách trắng các thông tin phản hồi được in trong nhật ký.['status']

#app.createLogger()

#Định nghĩa

class Application {
  createLogger(options: LoggerOptions) {
    const { dirname } = options;
    return createLogger({
      ...options,
      dirname: getLoggerFilePath(this.name || 'main', dirname || ''),
    });
  }
}

Khi dirname là một đường dẫn tương đối, các tệp nhật ký sẽ được xuất vào thư mục có tên của ứng dụng hiện tại.

#plugin.createLogger()

Cách sử dụng tương tự như app.createLogger().

#Định nghĩa

class Plugin {
  createLogger(options: LoggerOptions) {
    return this.app.createLogger(options);
  }
}

#Cấu hình Logger

#getLoggerLevel()

getLoggerLevel(): 'debug' | 'info' | 'warn' | 'error'

Lấy cấp độ nhật ký hiện đang được cấu hình trong hệ thống.

#getLoggerFilePath()

getLoggerFilePath(...paths: string[]): string

Nối các đường dẫn thư mục dựa trên thư mục nhật ký hiện đang được cấu hình trong hệ thống.

#getLoggerTransports()

getLoggerTransports(): ('console' | 'file' | 'dailyRotateFile')[]

Lấy các phương thức xuất nhật ký hiện đang được cấu hình trong hệ thống.

#getLoggerFormat()

getLoggerFormat(): 'logfmt' | 'json' | 'delimiter' | 'console'

Lấy định dạng nhật ký hiện đang được cấu hình trong hệ thống.

#Xuất nhật ký

#Transports

Các phương thức xuất được định nghĩa trước.

  • Transports.console
  • Transports.file
  • Transports.dailyRotateFile
import { Transports } from '@nocobase/logger';

const transport = Transports.console({
  //...
});

#Tài liệu liên quan

  • Hướng dẫn phát triển - Logger
  • Logger