npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@fastgpt-sdk/logger

v0.1.2

Published

FastGPT SDK for logger

Readme

@fastgpt-sdk/logger

FastGPT 的通用日志 SDK,基于 @logtape/logtape,内置:

  • Console pretty log
  • OpenTelemetry OTLP log sink
  • AsyncLocalStorage 上下文透传
  • 兼容 FastGPT 现有 getLogger(...).info('msg', {...}) 调用风格

安装

pnpm add @fastgpt-sdk/logger

快速开始

import { configureLogger, getLogger, withContext } from '@fastgpt-sdk/logger';

await configureLogger({
  defaultCategory: ['my-app'],
  console: {
    enabled: true,
    level: 'info'
  },
  otel: {
    enabled: true,
    serviceName: 'my-app',
    url: 'http://localhost:4318/v1/logs',
    level: 'info'
  },
  sensitiveProperties: ['password', 'token']
});

const logger = getLogger(['my-app', 'worker']);

await withContext({ requestId: 'req_123' }, async () => {
  logger.info('worker started', { jobId: 'job_001' });
});

API

configureLogger(options)

type LoggerConfigureOptions = {
  defaultCategory?: readonly string[];
  console?: boolean | { enabled?: boolean; level?: LogLevel };
  otel?: false | {
    enabled?: boolean;
    level?: LogLevel;
    serviceName: string;
    url?: string;
    loggerName?: string;
  };
  sensitiveProperties?: readonly string[];
  contextLocalStorage?: AsyncLocalStorage<Record<string, unknown>>;
  loggers?: Config['loggers'];
};
  • defaultCategory: 默认 category,不传时默认 ['system']
  • console: 控制台输出配置
  • otel: OpenTelemetry 输出配置;启用时需要 serviceName
  • sensitiveProperties: 命中这些字段的日志不会发往 OTEL sink
  • contextLocalStorage: 可注入自己的上下文存储实例
  • loggers: 可覆盖默认的 LogTape logger 路由配置

getLogger(category?)

const logger = getLogger(['app', 'api']);

logger.info('request completed', { status: 200 });
logger.error('request failed', { error });

category 不需要预注册;传任意字符串数组即可。

withContext(context, fn)

await withContext({ requestId: 'req_123' }, async () => {
  logger.info('handling request');
});

Env Helper

如果项目已经使用环境变量管理日志配置,也可以直接用 SDK 提供的转换助手:

import { configureLoggerFromEnv } from '@fastgpt-sdk/logger';

await configureLoggerFromEnv({
  env: process.env,
  defaultCategory: ['my-app'],
  defaultServiceName: 'my-app',
  sensitiveProperties: ['password', 'token']
});

支持读取这些环境变量:

  • LOG_ENABLE_CONSOLE
  • LOG_CONSOLE_LEVEL
  • LOG_ENABLE_OTEL
  • LOG_OTEL_LEVEL
  • LOG_OTEL_SERVICE_NAME
  • LOG_OTEL_URL

OpenTelemetry

启用 otel 后,SDK 会创建 OTLP HTTP log exporter。

await configureLogger({
  otel: {
    enabled: true,
    serviceName: 'my-app',
    loggerName: 'my-app',
    url: 'http://localhost:4318/v1/logs'
  }
});

也可以直接从 @fastgpt-sdk/logger 导入 getOpenTelemetrySink 进行更细粒度集成。

FastGPT 迁移建议

如果你在 FastGPT 仓库内部使用:

  • 通用能力放到 sdk/logger
  • 业务分类常量继续放在 service 侧
  • service 侧保留一层 configureLoggerFromEnv 风格的兼容封装