new Console(options)
曆史
| 版本 | 變化 |
|---|---|
| v14.2.0、v12.17.0 | 引入了 |
| v11.7.0 | 引入了 |
| v10.0.0 |
|
| v8.0.0 | 引入了 |
參數
options<Object>stdout<stream.Writable>stderr<stream.Writable>ignoreErrors<boolean> 寫入底層流時忽略錯誤。 默認:true。colorMode<boolean> | <string> 設置此Console實例的顏色支持。設置為true可在檢查值時啟用著色。設置為false會在檢查值時禁用著色。設置為'auto'使顏色支持取決於isTTY屬性的值和getColorDepth()在相應流上返回的值。如果還設置了inspectOptions.colors,則不能使用此選項。 默認:'auto'。inspectOptions<Object> 指定傳遞給的選項。util.inspect()groupIndentation<number> 設置組縮進。 默認:2。
使用一個或兩個可寫流實例創建一個新的 Console。 stdout 是用於打印日誌或信息輸出的可寫流。 stderr 用於警告或錯誤輸出。如果未提供 stderr,則 stdout 用於 stderr 。
const output = fs.createWriteStream('./stdout.log');
const errorOutput = fs.createWriteStream('./stderr.log');
// Custom simple logger
const logger = new Console({ stdout: output, stderr: errorOutput });
// use it like console
const count = 5;
logger.log('count: %d', count);
// In stdout.log: count 5
全局 console 是一個特殊的 Console,其輸出發送到 和 process.stdout 。相當於調用:process.stderr
new Console({ stdout: process.stdout, stderr: process.stderr });
相關用法
- Node.js new assert.AssertionError(options)用法及代碼示例
- Node.js new AsyncResource(type[, options])用法及代碼示例
- Node.js new stream.Duplex(options)用法及代碼示例
- Node.js new stream.Readable([options])用法及代碼示例
- Node.js new URLSearchParams(obj)用法及代碼示例
- Node.js new crypto.Certificate()用法及代碼示例
- Node.js new stream.Writable([options])用法及代碼示例
- Node.js new URLSearchParams(iterable)用法及代碼示例
- Node.js new Agent([options])用法及代碼示例
- Node.js new vm.SourceTextModule(code[, options])用法及代碼示例
- Node.js new stream.Transform([options])用法及代碼示例
- Node.js new PerformanceObserver(callback)用法及代碼示例
- Node.js new URL(input[, base])用法及代碼示例
- Node.js new URLSearchParams(string)用法及代碼示例
- Node.js new assert.CallTracker()用法及代碼示例
- Node.js net.isIP(input)用法及代碼示例
- Node.js net.createConnection(options[, connectListener])用法及代碼示例
- Node.js net.isIPv6(input)用法及代碼示例
- Node.js net.Server.address()用法及代碼示例
- Node.js net.createServer([options][, connectionListener])用法及代碼示例
- Node.js net.Server.listen()用法及代碼示例
- Node.js net.Socket.setTimeout(timeout[, callback])用法及代碼示例
- Node.js net.BlockList.check(address[, type])用法及代碼示例
- Node.js net.isIPv4(input)用法及代碼示例
- Node.js ServerHttp2Stream http2stream.pushStream(headers[, options], callback)用法及代碼示例
注:本文由純淨天空篩選整理自nodejs.org大神的英文原創作品 new Console(options)。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
