@adguard/logger

中文文档
2.0.1发布于 2026/08/29MITTypeScriptESM + CJS零依赖近 30 天下载 5486

AdGuard Logger is a simple tool designed for logging from AdGuard extensions.

原始使用文档
文档目录4 节
  1. Usage
  2. Installation
  3. Basic Usage
  4. Documentation

AdGuard Logger

AdGuard Logger is a simple tool designed for logging from AdGuard extensions.

Usage

Installation

pnpm add @adguard/logger

Basic Usage

The package supports both CommonJS and ES Module import styles.

const { Logger } = require('@adguard/logger');
// or
import { Logger } from '@adguard/logger';

const logger = new Logger();
logger.info('This is an info message');

The default log level is set to info, meaning that messages at the debug level won't be logged. You can adjust this by setting the log level:

import { Logger, LogLevel } from './Logger';

const logger = new Logger();
logger.currentLevel = LogLevel.Debug;
console.log(logger.currentLevel); // Outputs 'debug'
logger.debug('This is a debug message');

Additionally, you can customize your logging solution by providing your own log writer, rather than relying solely on the default console logger:

import { Logger, LogLevel } from './Logger';

const writeToFile = (...args: any[]) => {
// Implement file writing logic here
};
const writer = {
    log: (...args: any[]): void => {
        writeToFile(...args);
        console.log(...args);
    },
    error: (...args: any[]): void => {
        writeToFile(...args);
        console.error(...args);
    },
    info: (...args: any[]): void => {
        writeToFile(...args);
        console.info(...args);
    },
};
const logger = new Logger(writer);

Verbose logging and trace output

This mode is designed solely for development and debugging purposes, providing clickable call stack traces in the console for maximum insight into code execution.

When the logger is set to LogLevel.Verbose, every log method except error() will print with a call stack trace. This helps track the flow of execution and diagnose complex issues. The stack trace is shown as a collapsed group in the console if the writer supports groupCollapsed and groupEnd, making logs more readable; otherwise, traces are printed expanded.

To enable this behavior, the following conditions must be met:

  • Logging level must be set to LogLevel.Verbose.
  • The log method must not be error() (since error() already includes a stack trace).

This feature is intended for developers who need detailed, step-by-step tracking of application execution.

Documentation

版本与发布记录

@adguard/logger 共发布 7 个版本,首次发布于 2024/04/04;过去 12 个月发布了 1 个版本。

版本发布日期距今
2.0.1latest2026/08/292 个月前
2.0.02025/06/071.4 年前
1.1.12024/10/102 年前
1.1.02024/10/082 年前
1.0.22024/09/232 年前
1.0.12024/05/242 年前

关于 @adguard/logger 的常见问题

@adguard/logger 是什么?

AdGuard Logger is a simple tool designed for logging from AdGuard extensions.

如何安装 @adguard/logger?

在项目目录运行 npm install @adguard/logger,或使用 pnpm add / yarn add / bun add。

@adguard/logger 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@adguard/logger 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@adguard/logger 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=22。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@adguard/logger 可以商用吗?

@adguard/logger 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@adguard/logger 的下载量有多少?

根据 npm 官方下载统计,@adguard/logger 在 2026/10/05 – 2026/11/03 这 30 天内被下载 5,486 次,日均约 183 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@adguard/logger 还在维护吗?

最新版本 2.0.1 发布于 2026/08/29(2 个月前);至今共发布 7 个版本,其中过去 12 个月发布了 1 个;首次发布于 2024/04/04。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。