@qubit-ltd/logging 1.4.6 → 1.4.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3342,7 +3342,7 @@ and <code>NONE</code>. Lowercase letters are also allowed.</p>
3342
3342
 
3343
3343
  <footer>
3344
3344
  Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.4</a>
3345
- on Wed Apr 16 2025 13:42:01 GMT+0800 (China Standard Time)
3345
+ on Wed Apr 16 2025 17:13:07 GMT+0800 (China Standard Time)
3346
3346
  using the <a href="https://github.com/Haixing-Hu/jsdoc-minami">customized Minami theme</a>.
3347
3347
  </footer>
3348
3348
 
@@ -777,7 +777,7 @@ person.eat(meal); // 日志中将会打印此方法调用的签名
777
777
 
778
778
  <footer>
779
779
  Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.4</a>
780
- on Wed Apr 16 2025 13:42:01 GMT+0800 (China Standard Time)
780
+ on Wed Apr 16 2025 17:13:07 GMT+0800 (China Standard Time)
781
781
  using the <a href="https://github.com/Haixing-Hu/jsdoc-minami">customized Minami theme</a>.
782
782
  </footer>
783
783
 
@@ -51,92 +51,80 @@
51
51
  <article><h1>js-logging</h1>
52
52
  <p><a href="https://npmjs.com/package/@qubit-ltd/logging"><img src="https://img.shields.io/npm/v/@qubit-ltd/logging.svg" alt="npm package"></a>
53
53
  <a href="https://www.apache.org/licenses/LICENSE-2.0"><img src="https://img.shields.io/badge/License-Apache-blue.svg" alt="License"></a>
54
- <a href="README.zh_CN.md"><img src="https://img.shields.io/badge/%E6%96%87%E6%A1%A3-%E4%B8%AD%E6%96%87%E7%89%88-blue.svg" alt="中文文档"></a>
54
+ <a href="README.md"><img src="https://img.shields.io/badge/Document-English-blue.svg" alt="English Document"></a>
55
55
  <a href="https://dl.circleci.com/status-badge/redirect/gh/Haixing-Hu/js-logging/tree/master"><img src="https://dl.circleci.com/status-badge/img/gh/Haixing-Hu/js-logging/tree/master.svg?style=shield" alt="CircleCI"></a>
56
56
  <a href="https://coveralls.io/github/Haixing-Hu/js-logging?branch=master"><img src="https://coveralls.io/repos/github/Haixing-Hu/js-logging/badge.svg?branch=master" alt="Coverage Status"></a></p>
57
- <p><a href="https://npmjs.com/package/@qubit-ltd/logging">@qubit-ltd/logging</a> is a JavaScript library that provides powerful
58
- logging capabilities through decorators for class methods and properties.
59
- This library is designed to seamlessly integrate with <a href="https://github.com/Haixing-Hu/vue3-class-component/">Vue.js class components</a>,
60
- offering an elegant solution for handling logging in your JavaScript projects.</p>
61
- <h2>Features</h2>
57
+ <p><a href="https://npmjs.com/package/@qubit-ltd/logging">@qubit-ltd/logging</a> 是一个 JavaScript 库,通过装饰器为类方法和属性提供强大的日志记录功能。
58
+ 该库旨在与<a href="https://github.com/Haixing-Hu/vue3-class-component/">Vue.js 类组件</a>无缝集成,为处理 JavaScript 项目中的日志记录提供了优雅的解决方案。</p>
59
+ <h2>特性</h2>
62
60
  <ul>
63
- <li>📝 Simple and flexible logging interface with different log levels</li>
64
- <li>🔍 Support for formatted log messages with placeholders</li>
65
- <li>🎯 Decorators for automatic method logging and class logger integration</li>
66
- <li>🔄 Seamless integration with Vue.js class components</li>
67
- <li>🎛️ Configurable logging levels and appenders</li>
68
- <li>🌐 Global and individual logger management</li>
69
- <li>📋 Browser console and custom appender support</li>
61
+ <li>📝 简单灵活的日志接口,支持不同的日志级别</li>
62
+ <li>🔍 支持带占位符的格式化日志消息</li>
63
+ <li>🎯 自动方法日志记录和类日志集成的装饰器</li>
64
+ <li>🔄 Vue.js类组件无缝集成</li>
65
+ <li>🎛️ 可配置的日志级别和输出器</li>
66
+ <li>🌐 全局和单独的日志记录器管理</li>
67
+ <li>📋 支持浏览器控制台和自定义输出器</li>
70
68
  </ul>
71
- <h2>Installation</h2>
72
- <p>To install the library, use either npm or yarn:</p>
69
+ <h2>安装</h2>
70
+ <p>使用 npm yarn 安装该库:</p>
73
71
  <pre class="prettyprint source lang-sh"><code>npm install @qubit-ltd/logging
74
72
  </code></pre>
75
- <p>or</p>
73
+ <p>或</p>
76
74
  <pre class="prettyprint source lang-sh"><code>yarn add @qubit-ltd/logging
77
75
  </code></pre>
78
- <h2>The <code>Logger</code> Class</h2>
79
- <p>The <code>Logger</code> class provides a simple yet flexible logging interface.</p>
80
- <h3>Get or create a Logger</h3>
81
- <p>You can retrieve a <code>Logger</code> instance by calling the static method
82
- <code>Logger.getLogger(name, options)</code>, where</p>
76
+ <h2><code>Logger</code> 类</h2>
77
+ <p><code>Logger</code> 类提供了一个简单而灵活的日志记录接口。</p>
78
+ <h3>获取或创建 Logger</h3>
79
+ <p>你可以通过调用静态方法 <code>Logger.getLogger(name, options)</code> 获取一个 <code>Logger</code> 实例,其中:</p>
83
80
  <ul>
84
- <li><code>name</code> is the identifier of the logger. If a logger with the same name exists,
85
- it will be returned; otherwise, a new one will be created.</li>
86
- <li><code>options</code> (optional) is an object that may include:
81
+ <li><code>name</code> logger 的标识符。如果已经存在具有相同名称的 logger,则返回该实例;否则将创建一个新的 logger。</li>
82
+ <li><code>options</code>(可选)是一个对象,可能包括:
87
83
  <ul>
88
- <li><code>appender: object</code>: specifies the output destination for log messages.
89
- This object must implement <code>trace</code>, <code>debug</code>, <code>info</code>, <code>warn</code> and <code>error</code>
90
- methods. If omitted, the existing appender of the logger will be used, or
91
- the default appender will be assigned to a new logger.</li>
92
- <li><code>level: string</code>: defines the logging level (<code>TRACE</code>, <code>DEBUG</code>, <code>INFO</code>, <code>WARN</code>,
93
- <code>ERROR</code>, <code>NONE</code>). Case-insensitive. If omitted, the existing logging level
94
- of the logger will be used, or the default logging level will be assigned to
95
- a new logger.</li>
84
+ <li><code>appender: object</code>:指定日志消息的输出目的地。此对象必须实现 <code>trace</code>、<code>debug</code>、<code>info</code>、<code>warn</code> <code>error</code> 方法。
85
+ 如果省略,将使用 logger 的现有 appender,或者为新创建的 logger 分配默认 appender。</li>
86
+ <li><code>level: string</code>:定义日志记录级别(<code>TRACE</code>、<code>DEBUG</code>、<code>INFO</code>、<code>WARN</code>、<code>ERROR</code>、<code>NONE</code>)。不区分大小写。
87
+ 如果省略,将使用 logger 的现有日志级别,或者为新创建的 logger 分配默认日志级别。</li>
96
88
  </ul>
97
89
  </li>
98
90
  </ul>
99
- <p>Example:</p>
91
+ <p>示例:</p>
100
92
  <pre class="prettyprint source lang-javascript"><code>import Logger from '@qubit-ltd/logging';
101
93
 
102
- // Create a logger with default settings
94
+ // 创建一个使用默认设置的logger
103
95
  const logger1 = Logger.getLogger('MyLogger');
104
96
 
105
- // Create a logger with custom level
97
+ // 创建一个自定义日志级别的logger
106
98
  const logger2 = Logger.getLogger('DebugLogger', { level: 'DEBUG' });
107
99
 
108
- // Create a logger with custom appender
100
+ // 创建一个带自定义输出器的logger
109
101
  const customAppender = {
110
- trace: (message, ...args) => { /* custom trace implementation */ },
111
- debug: (message, ...args) => { /* custom debug implementation */ },
112
- info: (message, ...args) => { /* custom info implementation */ },
113
- warn: (message, ...args) => { /* custom warn implementation */ },
114
- error: (message, ...args) => { /* custom error implementation */ },
102
+ trace: (message, ...args) => { /* 自定义trace实现 */ },
103
+ debug: (message, ...args) => { /* 自定义debug实现 */ },
104
+ info: (message, ...args) => { /* 自定义info实现 */ },
105
+ warn: (message, ...args) => { /* 自定义warn实现 */ },
106
+ error: (message, ...args) => { /* 自定义error实现 */ },
115
107
  };
116
108
  const logger3 = Logger.getLogger('CustomLogger', { appender: customAppender, level: 'INFO' });
117
109
  </code></pre>
118
- <h3>Logging Messages</h3>
110
+ <h3>记录日志消息</h3>
119
111
  <ul>
120
- <li><code>logger.trace(message, ...args)</code>: Logs a trace-level message.</li>
121
- <li><code>logger.debug(message, ...args)</code>: Logs a debug-level message.</li>
122
- <li><code>logger.info(message, ...args)</code>: Logs an info-level message.</li>
123
- <li><code>logger.warn(message, ...args)</code>: Logs a warning-level message.</li>
124
- <li><code>logger.error(message, ...args)</code>: Logs an error-level message.</li>
125
- <li><code>logger.log(level, message, ...args)</code>: Logs a message in the specified logging level.</li>
112
+ <li><code>logger.trace(message, ...args)</code>:记录一个 trace 级别的消息。</li>
113
+ <li><code>logger.debug(message, ...args)</code>:记录一个 debug 级别的消息。</li>
114
+ <li><code>logger.info(message, ...args)</code>:记录一个 info 级别的消息。</li>
115
+ <li><code>logger.warn(message, ...args)</code>:记录一个警告级别的消息。</li>
116
+ <li><code>logger.error(message, ...args)</code>:记录一个错误级别的消息。</li>
117
+ <li><code>logger.log(level, message, ...args)</code>:以指定的日志级别记录消息。</li>
126
118
  </ul>
127
- <p>You can use placeholders in log messages to dynamically insert variables:</p>
119
+ <p>你可以在日志消息中使用占位符动态插入变量:</p>
128
120
  <ul>
129
- <li><code>%o</code> or <code>%O</code>: JavaScript object output. Clicking the object name opens
130
- more information about it in the inspector.</li>
131
- <li><code>%d</code> or<code> %i</code>: Integer output (supports formatting). For example,
132
- <code>logger.info('Foo %.2d', 1.1)</code> will output the number as two significant
133
- figures with a leading 0: <code>Foo 01</code>.</li>
134
- <li><code>%s</code>: String output.</li>
135
- <li><code>%f</code>: Floating-point number output (supports formatting). For example,
136
- <code>logger.debug(&quot;Foo %.2f&quot;, 1.1)</code> will output the number to 2 decimal
137
- places: <code>Foo 1.10</code>.</li>
121
+ <li><code>%o</code> <code>%O</code>:JavaScript 对象输出。点击对象名称可以在检查器中查看更多信息。</li>
122
+ <li><code>%d</code> <code>%i</code>:整数输出(支持格式化)。例如,<code>logger.info('Foo %.2d', 1.1)</code> 将数字输出为两位有效数字并带有前导0:
123
+ <code>Foo 01</code>。</li>
124
+ <li><code>%s</code>:字符串输出。</li>
125
+ <li><code>%f</code>:浮点数输出(支持格式化)。例如,<code>logger.debug(&quot;Foo %.2f&quot;, 1.1)</code> 将数字输出为两位小数:<code>Foo 1.10</code>。</li>
138
126
  </ul>
139
- <p>Example:</p>
127
+ <p>示例:</p>
140
128
  <pre class="prettyprint source lang-javascript"><code>import Logger from '@qubit-ltd/logging';
141
129
 
142
130
  const logger = Logger.getLogger('MyClass');
@@ -148,35 +136,35 @@ logger.error('This is an error message with argument %s and argument %o', 'foo',
148
136
  const level = 'info';
149
137
  logger.log(level, 'This is an %s message with argument %s and argument %o', level, 'foo', { bar: 'baz' });
150
138
  </code></pre>
151
- <h3>Set the Logging Level</h3>
152
- <p>Adjust the logging level for a logger using <code>logger.setLevel(level)</code>.</p>
153
- <p>Available levels (from most to least verbose):</p>
139
+ <h3>设置日志级别</h3>
140
+ <p>使用 <code>logger.setLevel(level)</code> 调整 logger 的日志级别。</p>
141
+ <p>可用的日志级别(从最详细到最简略):</p>
154
142
  <ul>
155
- <li><code>TRACE</code>: Most detailed information for debugging purposes</li>
156
- <li><code>DEBUG</code>: General debugging information</li>
157
- <li><code>INFO</code>: General information about application progress</li>
158
- <li><code>WARN</code>: Warning situations that might require attention</li>
159
- <li><code>ERROR</code>: Error conditions that need handling</li>
160
- <li><code>NONE</code>: Completely disable logging</li>
143
+ <li><code>TRACE</code>:用于调试目的的最详细信息</li>
144
+ <li><code>DEBUG</code>:一般调试信息</li>
145
+ <li><code>INFO</code>:关于应用程序进度的一般信息</li>
146
+ <li><code>WARN</code>:可能需要注意的警告情况</li>
147
+ <li><code>ERROR</code>:需要处理的错误条件</li>
148
+ <li><code>NONE</code>:完全禁用日志记录</li>
161
149
  </ul>
162
- <p>All level names are case-insensitive.</p>
163
- <p>Example:</p>
150
+ <p>所有级别名称不区分大小写。</p>
151
+ <p>示例:</p>
164
152
  <pre class="prettyprint source lang-javascript"><code>const logger = Logger.getLogger('MyClass');
165
153
 
166
- // Change the level to only show warnings and errors
154
+ // 将级别更改为只显示警告和错误
167
155
  logger.setLevel('WARN');
168
156
 
169
- // These won't be displayed because they're below the WARN level
170
- logger.trace('This trace message will not be displayed');
171
- logger.debug('This debug message will not be displayed');
172
- logger.info('This info message will not be displayed');
157
+ // 这些不会显示,因为它们低于WARN级别
158
+ logger.trace('这条跟踪消息不会显示');
159
+ logger.debug('这条调试消息不会显示');
160
+ logger.info('这条信息消息不会显示');
173
161
 
174
- // These will be displayed
175
- logger.warn('This warning message will be displayed');
176
- logger.error('This error message will be displayed');
162
+ // 这些会显示
163
+ logger.warn('这条警告消息会显示');
164
+ logger.error('这条错误消息会显示');
177
165
  </code></pre>
178
- <h3>Set the Logging Appender</h3>
179
- <p>Use <code>logger.setAppender(appender)</code> to assign a custom appender object that defines:</p>
166
+ <h3>设置日志 Appender</h3>
167
+ <p>使用 <code>logger.setAppender(appender)</code> logger 分配一个自定义的 appender 对象,该对象定义了以下方法:</p>
180
168
  <ul>
181
169
  <li><code>trace(message, ...args)</code></li>
182
170
  <li><code>debug(message, ...args)</code></li>
@@ -184,11 +172,11 @@ logger.error('This error message will be displayed');
184
172
  <li><code>warn(message, ...args)</code></li>
185
173
  <li><code>error(message, ...args)</code></li>
186
174
  </ul>
187
- <p>Example:</p>
175
+ <p>示例:</p>
188
176
  <pre class="prettyprint source lang-javascript"><code>const logger = Logger.getLogger('MyClass');
189
- logger.setAppender(console); // Outputs log messages to the console.
177
+ logger.setAppender(console); // 将日志消息输出到控制台
190
178
 
191
- // Or create a custom appender that adds timestamps to all logs
179
+ // 或者创建一个为所有日志添加时间戳的自定义输出器
192
180
  const timestampAppender = {
193
181
  trace: (message, ...args) => console.trace(`[${new Date().toISOString()}] ${message}`, ...args),
194
182
  debug: (message, ...args) => console.debug(`[${new Date().toISOString()}] ${message}`, ...args),
@@ -198,133 +186,124 @@ const timestampAppender = {
198
186
  };
199
187
  logger.setAppender(timestampAppender);
200
188
  </code></pre>
201
- <h3>Enable or Disable Logging</h3>
189
+ <h3>启用或禁用日志记录</h3>
202
190
  <ul>
203
- <li><code>logger.enable()</code>: Enable logging.</li>
204
- <li><code>logger.disable()</code>: Disable logging.</li>
205
- <li><code>logger.setEnabled(enabled)</code>: Dynamically control logging.</li>
191
+ <li><code>logger.enable()</code>:启用日志记录。</li>
192
+ <li><code>logger.disable()</code>:禁用日志记录。</li>
193
+ <li><code>logger.setEnabled(enabled)</code>:动态控制日志记录的启用与禁用。</li>
206
194
  </ul>
207
- <p>Example:</p>
195
+ <p>示例:</p>
208
196
  <pre class="prettyprint source lang-javascript"><code>const logger = Logger.getLogger('MyClass');
209
197
 
210
- // Disable all logging temporarily
198
+ // 暂时禁用所有日志
211
199
  logger.disable();
212
- logger.info('This message will not be logged');
200
+ logger.info('此消息不会被记录');
213
201
 
214
- // Re-enable logging
202
+ // 重新启用日志
215
203
  logger.enable();
216
- logger.info('This message will be logged');
204
+ logger.info('此消息会被记录');
217
205
 
218
- // Use a condition to control logging
206
+ // 使用条件控制日志记录
219
207
  const debugMode = process.env.NODE_ENV === 'development';
220
208
  logger.setEnabled(debugMode);
221
209
  </code></pre>
222
- <h3>Managing Loggers</h3>
210
+ <h3>管理日志记录器</h3>
223
211
  <ul>
224
- <li><code>Logger.clearAllLoggers()</code>: Clears all registered loggers.</li>
225
- <li><code>Logger.getLevel(name)</code>: Retrieves the logging level for a specific logger.</li>
226
- <li><code>Logger.setLevel(name, level)</code>: Sets the logging level for a specific logger.</li>
212
+ <li><code>Logger.clearAllLoggers()</code>:清除所有已注册的日志记录器。</li>
213
+ <li><code>Logger.getLevel(name)</code>:获取特定日志记录器的日志级别。</li>
214
+ <li><code>Logger.setLevel(name, level)</code>:设置特定日志记录器的日志级别。</li>
227
215
  </ul>
228
- <p>Example:</p>
229
- <pre class="prettyprint source lang-javascript"><code>// Create multiple loggers
216
+ <p>示例:</p>
217
+ <pre class="prettyprint source lang-javascript"><code>// 创建多个日志记录器
230
218
  const apiLogger = Logger.getLogger('API');
231
219
  const uiLogger = Logger.getLogger('UI');
232
220
  const dbLogger = Logger.getLogger('Database');
233
221
 
234
- // Change a specific logger's level without accessing its instance
222
+ // 在不访问实例的情况下更改特定日志记录器的级别
235
223
  Logger.setLevel('API', 'DEBUG');
236
224
  Logger.setLevel('Database', 'ERROR');
237
225
 
238
- // Get a logger's current level
226
+ // 获取日志记录器的当前级别
239
227
  const uiLevel = Logger.getLevel('UI');
240
- console.log(`UI Logger level: ${uiLevel}`);
228
+ console.log(`UI Logger级别: ${uiLevel}`);
241
229
 
242
- // Clear all loggers when shutting down the application
230
+ // 关闭应用程序时清除所有日志记录器
243
231
  Logger.clearAllLoggers();
244
232
  </code></pre>
245
- <h3>Default Levels and Appenders</h3>
246
- <p>The default logging levels and appenders are used when creating a new logger
247
- without specifying the level or appender.</p>
233
+ <h3>默认级别和 Appender</h3>
234
+ <p>当创建一个新日志记录器时,如果没有指定级别或 appender,将使用默认的日志级别和 appender。</p>
248
235
  <ul>
249
- <li><code>Logger.getDefaultLevel()</code>: Gets the default logging level.</li>
250
- <li><code>Logger.setDefaultLevel(level)</code>: Sets the default logging level.</li>
251
- <li><code>Logger.resetDefaultLevel()</code>: Resets the default logging level to the
252
- factory value.</li>
253
- <li><code>Logger.getDefaultAppender()</code>: Gets the default logging appender.</li>
254
- <li><code>Logger.setDefaultAppender(appender)</code>: Sets the default logging appender.</li>
255
- <li><code>Logger.resetDefaultAppender()</code>: Resets the default logging appender to the
256
- factory value.</li>
236
+ <li><code>Logger.getDefaultLevel()</code>:获取默认日志级别。</li>
237
+ <li><code>Logger.setDefaultLevel(level)</code>:设置默认日志级别。</li>
238
+ <li><code>Logger.resetDefaultLevel()</code>:将默认日志级别重置为出厂值。</li>
239
+ <li><code>Logger.getDefaultAppender()</code>:获取默认日志 appender。</li>
240
+ <li><code>Logger.setDefaultAppender(appender)</code>:设置默认日志 appender。</li>
241
+ <li><code>Logger.resetDefaultAppender()</code>:将默认日志 appender 重置为出厂值。</li>
257
242
  </ul>
258
- <p>Example:</p>
259
- <pre class="prettyprint source lang-javascript"><code>// Get the current default level
243
+ <p>示例:</p>
244
+ <pre class="prettyprint source lang-javascript"><code>// 获取当前默认级别
260
245
  const defaultLevel = Logger.getDefaultLevel();
261
- console.log(`Default logging level: ${defaultLevel}`);
246
+ console.log(`默认日志级别: ${defaultLevel}`);
262
247
 
263
- // Change the default level for all new loggers
248
+ // 为所有新的日志记录器更改默认级别
264
249
  Logger.setDefaultLevel('DEBUG');
265
250
 
266
- // All new loggers will now have DEBUG level by default
267
- const logger = Logger.getLogger('NewLogger'); // Will have DEBUG level
251
+ // 所有新的日志记录器现在默认将具有DEBUG级别
252
+ const logger = Logger.getLogger('NewLogger'); // 将具有DEBUG级别
268
253
 
269
- // Reset to the original factory default level
254
+ // 重置为原始的工厂默认级别
270
255
  Logger.resetDefaultLevel();
271
256
  </code></pre>
272
- <h3>Global Loggers Management</h3>
257
+ <h3>全局日志管理</h3>
273
258
  <ul>
274
- <li><code>Logger.setAllLevels(level)</code>: Applies a logging level to all existing loggers.</li>
275
- <li><code>Logger.resetAllLevels()</code>: Resets the logging level of all existing loggers to
276
- the default logging level.</li>
277
- <li><code>Logger.setAllAppenders(appender)</code>: Applies a logging appender to all existing
278
- loggers.</li>
279
- <li><code>Logger.resetAllAppenders()</code>: Resets the logging appender of all existing loggers
280
- to the default logging appender.</li>
259
+ <li><code>Logger.setAllLevels(level)</code>:将指定日志级别应用于所有现有日志记录器。</li>
260
+ <li><code>Logger.resetAllLevels()</code>:将所有现有日志记录器的日志级别重置为默认日志级别。</li>
261
+ <li><code>Logger.setAllAppenders(appender)</code>:将指定日志 appender 应用于所有现有日志记录器。</li>
262
+ <li><code>Logger.resetAllAppenders()</code>:将所有现有日志记录器的日志 appender 重置为默认 appender。</li>
281
263
  </ul>
282
- <p>Example:</p>
283
- <pre class="prettyprint source lang-javascript"><code>// Create several loggers with different levels
264
+ <p>示例:</p>
265
+ <pre class="prettyprint source lang-javascript"><code>// 创建几个具有不同级别的日志记录器
284
266
  const logger1 = Logger.getLogger('Logger1', { level: 'TRACE' });
285
267
  const logger2 = Logger.getLogger('Logger2', { level: 'INFO' });
286
268
  const logger3 = Logger.getLogger('Logger3', { level: 'ERROR' });
287
269
 
288
- // Change all loggers to WARNING level at once
270
+ // 一次将所有日志记录器更改为WARN级别
289
271
  Logger.setAllLevels('WARN');
290
272
 
291
- // Now all loggers will only display WARN and ERROR messages
292
- logger1.info('This won't be displayed');
293
- logger2.warn('This will be displayed');
294
- logger3.error('This will be displayed');
273
+ // 现在所有日志记录器将只显示WARNERROR消息
274
+ logger1.info('这不会显示');
275
+ logger2.warn('这会显示');
276
+ logger3.error('这会显示');
295
277
 
296
- // Reset all loggers to use the default level
278
+ // 将所有日志记录器重置为使用默认级别
297
279
  Logger.resetAllLevels();
298
280
 
299
- // Apply a custom appender to all existing loggers
300
- const fileAppender = { /* ... implementation of logging to a file ... */ };
281
+ // 将自定义输出器应用于所有现有的日志记录器
282
+ const fileAppender = { /* ... 记录到文件的实现 ... */ };
301
283
  Logger.setAllAppenders(fileAppender);
302
284
  </code></pre>
303
- <h3>Reset to Factory Defaults</h3>
285
+ <h3>重置日志记录器</h3>
304
286
  <ul>
305
- <li><code>Logger.reset()</code>: Resets all loggers to the factory default settings. This
306
- includes clearing all existing loggers, and resetting the default logging
307
- level and the default logging appender.</li>
287
+ <li><code>Logger.reset()</code>:将日志记录器重置为出厂状态。这将清除所有已注册的日志记录器、重置默认日志级别和默认日志 appender。</li>
308
288
  </ul>
309
- <p>Example:</p>
310
- <pre class="prettyprint source lang-javascript"><code>// After making many modifications to loggers and defaults
311
- // This single call resets everything to factory settings
289
+ <p>示例:</p>
290
+ <pre class="prettyprint source lang-javascript"><code>// 在对日志记录器和默认设置进行多次修改后
291
+ // 这一个调用将一切重置为工厂设置
312
292
  Logger.reset();
313
293
  </code></pre>
314
- <h2>The <code>@Log</code> Decorator</h2>
315
- <p>The <code>@Log</code> decorator automatically logs the method signature, including the
316
- class name, method name, and parameters.</p>
317
- <p>Example:</p>
294
+ <h2><code>@Log</code> 装饰器</h2>
295
+ <p><code>@Log</code> 装饰器会自动记录方法签名,包括类名、方法名和参数。</p>
296
+ <p>示例:</p>
318
297
  <pre class="prettyprint source lang-javascript"><code>import { Log } from '@qubit-ltd/logging';
319
298
 
320
299
  class Person {
321
300
  @Log
322
301
  eat(meal) {
323
- // method implementation
324
- return `Eating ${meal.name}`;
302
+ // 方法实现
303
+ return `正在吃${meal.name}`;
325
304
  }
326
305
 
327
- // Custom options for the Log decorator
306
+ // Log装饰器的自定义选项
328
307
  @Log({ level: 'INFO', withResult: true })
329
308
  calculateCalories(food, amount) {
330
309
  const calories = food.caloriesPerUnit * amount;
@@ -333,30 +312,29 @@ class Person {
333
312
  }
334
313
 
335
314
  const person = new Person();
336
- const meal = { name: 'Breakfast', type: 'healthy' };
315
+ const meal = { name: '早餐', type: '健康' };
337
316
  person.eat(meal);
338
- // Logs: &quot;Person.eat({&quot;name&quot;:&quot;Breakfast&quot;,&quot;type&quot;:&quot;healthy&quot;})&quot;
317
+ // 记录: &quot;Person.eat({&quot;name&quot;:&quot;早餐&quot;,&quot;type&quot;:&quot;健康&quot;})&quot;
339
318
 
340
319
  const calories = person.calculateCalories({ caloriesPerUnit: 50 }, 4);
341
- // Logs: &quot;Person.calculateCalories({&quot;caloriesPerUnit&quot;:50}, 4) => 200&quot;
320
+ // 记录: &quot;Person.calculateCalories({&quot;caloriesPerUnit&quot;:50}, 4) => 200&quot;
342
321
  </code></pre>
343
- <h2>The <code>@HasLogger</code> Decorator</h2>
344
- <p>The <code>@HasLogger</code> decorator adds a named logger to a class, which is accessible
345
- via the <code>logger</code> property.</p>
346
- <p>Example:</p>
322
+ <h2><code>@HasLogger</code> 装饰器</h2>
323
+ <p><code>@HasLogger</code> 装饰器会为类添加一个命名的日志记录器,可以通过 <code>logger</code> 属性访问。</p>
324
+ <p>示例:</p>
347
325
  <pre class="prettyprint source lang-javascript"><code>import { HasLogger } from '@qubit-ltd/logging';
348
326
 
349
327
  @HasLogger
350
328
  class MyClass {
351
329
  foo() {
352
- this.logger.debug('This is MyClass.foo()');
330
+ this.logger.debug('这是MyClass.foo()');
353
331
  }
354
332
 
355
333
  bar(param) {
356
- this.logger.info('Processing with parameter: %o', param);
357
- // do something with param
334
+ this.logger.info('使用参数处理: %o', param);
335
+ // 使用param做一些事情
358
336
  if (param.value &lt; 0) {
359
- this.logger.warn('Negative value detected: %d', param.value);
337
+ this.logger.warn('检测到负值: %d', param.value);
360
338
  }
361
339
  return param.value * 2;
362
340
  }
@@ -366,8 +344,8 @@ const instance = new MyClass();
366
344
  instance.foo();
367
345
  instance.bar({ value: -5 });
368
346
  </code></pre>
369
- <h2>Using with Vue.js Class Components</h2>
370
- <p>You can use the <code>@Log</code> and <code>@HasLogger</code> decorators with <a href="https://github.com/Haixing-Hu/vue3-class-component/">Vue.js class components</a>:</p>
347
+ <h2>与 Vue.js 类组件一起使用</h2>
348
+ <p>你可以在<a href="https://github.com/Haixing-Hu/vue3-class-component/">Vue.js 类组件</a>中使用 <code>@Log</code> 和 <code>@HasLogger</code> 装饰器:</p>
371
349
  <pre class="prettyprint source lang-javascript"><code>import { HasLogger, Log } from '@qubit-ltd/logging';
372
350
  import { Component, toVue } from '@qubit-ltd/vue3-class-component';
373
351
 
@@ -381,20 +359,20 @@ class MyComponent {
381
359
 
382
360
  @Log
383
361
  foo() {
384
- this.logger.debug('This is MyComponent.foo()');
385
- this.message = 'clicked at ' + new Date().toLocaleTimeString();
362
+ this.logger.debug('这是MyComponent.foo()');
363
+ this.message = '点击于 ' + new Date().toLocaleTimeString();
386
364
  }
387
365
 
388
366
  @Log({ level: 'INFO' })
389
367
  async fetchData() {
390
368
  try {
391
- this.logger.info('Fetching data from API...');
369
+ this.logger.info('API获取数据...');
392
370
  const response = await fetch('/api/data');
393
371
  const data = await response.json();
394
- this.logger.info('Data received: %o', data);
372
+ this.logger.info('接收到数据: %o', data);
395
373
  return data;
396
374
  } catch (error) {
397
- this.logger.error('Failed to fetch data: %o', error);
375
+ this.logger.error('获取数据失败: %o', error);
398
376
  throw error;
399
377
  }
400
378
  }
@@ -402,11 +380,11 @@ class MyComponent {
402
380
 
403
381
  export default toVue(MyComponent);
404
382
  </code></pre>
405
- <p><strong>Note</strong>: The <code>@HasLogger</code> decorator must be placed <strong>after</strong> the <code>@Component</code> decorator.</p>
406
- <h2>Advanced Usage</h2>
407
- <h3>Creating a Custom Appender</h3>
408
- <p>You can create custom appenders to direct logs to different destinations:</p>
409
- <pre class="prettyprint source lang-javascript"><code>// File logging appender (Node.js example)
383
+ <p><strong>注意</strong>:<code>@HasLogger</code> 装饰器必须放在 <code>@Component</code> 装饰器的<strong>后面</strong>。</p>
384
+ <h2>高级用法</h2>
385
+ <h3>创建自定义输出器</h3>
386
+ <p>你可以创建自定义输出器将日志定向到不同的目的地:</p>
387
+ <pre class="prettyprint source lang-javascript"><code>// 文件日志输出器(Node.js示例)
410
388
  import fs from 'fs';
411
389
 
412
390
  const fileAppender = {
@@ -424,46 +402,44 @@ const fileAppender = {
424
402
  error: function(message, ...args) { this._writeToFile('ERROR', message, ...args); }
425
403
  };
426
404
 
427
- // Use the custom appender
405
+ // 使用自定义输出器
428
406
  const logger = Logger.getLogger('AppLogger', { appender: fileAppender });
429
407
  </code></pre>
430
- <h3>Conditional Logging</h3>
408
+ <h3>条件日志记录</h3>
431
409
  <pre class="prettyprint source lang-javascript"><code>import Logger from '@qubit-ltd/logging';
432
410
 
433
411
  function processData(data, options = {}) {
434
412
  const logger = Logger.getLogger('DataProcessor');
435
413
 
436
- // Enable debug logging only when explicitly requested
414
+ // 仅在明确请求时启用调试日志
437
415
  if (options.debug) {
438
416
  logger.setLevel('DEBUG');
439
417
  } else {
440
418
  logger.setLevel('INFO');
441
419
  }
442
420
 
443
- logger.debug('Processing data with options: %o', options);
444
- // rest of the function
421
+ logger.debug('使用选项处理数据: %o', options);
422
+ // 函数的其余部分
445
423
  }
446
424
  </code></pre>
447
- <h2><span id="contributing">Contributing</span></h2>
448
- <p>If you find any issues or have suggestions for improvements, please feel free
449
- to open an issue or submit a pull request to the <a href="https://github.com/Haixing-Hu/js-logging">GitHub repository</a>.</p>
450
- <h3>Development Setup</h3>
451
- <pre class="prettyprint source lang-bash"><code># Clone the repository
425
+ <h2><span id="contributing">贡献</span></h2>
426
+ <p>如果您发现任何问题或有改进建议,请随时在<a href="https://github.com/Haixing-Hu/js-logging">GitHub 仓库</a>上提交 issue pull request。</p>
427
+ <h3>开发设置</h3>
428
+ <pre class="prettyprint source lang-bash"><code># 克隆仓库
452
429
  git clone https://github.com/Haixing-Hu/js-logging.git
453
430
  cd js-logging
454
431
 
455
- # Install dependencies
432
+ # 安装依赖
456
433
  yarn install
457
434
 
458
- # Run tests
435
+ # 运行测试
459
436
  yarn test
460
437
 
461
- # Build the library
438
+ # 构建库
462
439
  yarn build
463
440
  </code></pre>
464
- <h2><span id="license">License</span></h2>
465
- <p><a href="https://npmjs.com/package/@qubit-ltd/logging">@qubit-ltd/logging</a> is distributed under the Apache 2.0 license.
466
- See the <a href="LICENSE">LICENSE</a> file for more details.</p></article>
441
+ <h2><span id="license">许可证</span></h2>
442
+ <p><a href="https://npmjs.com/package/@qubit-ltd/logging">@qubit-ltd/logging</a> 根据 Apache 2.0 许可证分发。详情请参阅 <a href="LICENSE">LICENSE</a> 文件。</p></article>
467
443
  </section>
468
444
 
469
445
 
@@ -477,7 +453,7 @@ See the <a href="LICENSE">LICENSE</a> file for more details.</p></article>
477
453
 
478
454
  <footer>
479
455
  Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.4</a>
480
- on Wed Apr 16 2025 13:42:01 GMT+0800 (China Standard Time)
456
+ on Wed Apr 16 2025 17:13:07 GMT+0800 (China Standard Time)
481
457
  using the <a href="https://github.com/Haixing-Hu/jsdoc-minami">customized Minami theme</a>.
482
458
  </footer>
483
459
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qubit-ltd/logging",
3
- "version": "1.4.6",
3
+ "version": "1.4.8",
4
4
  "description": "A simple JavaScript logging framework",
5
5
  "author": "Haixing Hu",
6
6
  "license": "Apache-2.0",
@@ -46,7 +46,7 @@
46
46
  "es5": "check-es-version -e 5 -s true",
47
47
  "deploy": "npm run lint && npm run test && npm run build:all && npm publish --registry='https://npm.qubit.ltd/' --access public",
48
48
  "deploy:public": "npm run lint && npm run test && npm run build:all && npm publish --registry='https://registry.npmjs.org/' --access public",
49
- "deploy:all": "npm run deploy && npm run deploy:public"
49
+ "deploy:all": "npm run deploy && npm publish --registry='https://registry.npmjs.org/' --access public"
50
50
  },
51
51
  "browserify": {
52
52
  "transform": [