久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何讓 Winston 使用 Webpack?

How do I get Winston to work with Webpack?(如何讓 Winston 使用 Webpack?)
本文介紹了如何讓 Winston 使用 Webpack?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我有一個使用 node.js 的電子應用程序.我想使用 Winston 登錄應用程序.我已將 winston 添加到我的 package.json 文件中,但是當我為 webpack 運行構建命令時,我收到了來自 winston 中的 colors.js 依賴項的一些警告.

I have an electron application which is using node.js. I would like to use Winston for logging in the application. I've added winston to my package.json file, but when I run the build command for webpack I'm getting some warnings from the colors.js dependency in winston.

'...the request of a dependency is an expression...'

然后它引用winston 和colors.js.忽略警告不起作用,因為電子應用程序在嘗試從 winston 加載一些文件時遇到異常.

It then references winston and colors.js. Ignoring the warnings doesn't work, as the electron application gets an exception trying to load some files from winston.

我在 SO 和 github 站點上進行了一些挖掘,他們說 colors.js 有一些動態(tài)的 require 語句,webpack 有問題.我還看到其他示例項目似乎已經啟動并運行了winston,并且在他們的項目中沒有任何問題.有誰知道如何在電子應用程序中正確包含帶有 webpack 的 winston 日志記錄包?

I did some digging on SO and the github site and they say that colors.js has some dynamic require statements that webpack is having issues with. I've also seen that other sample projects seem to have winston up and running without any issues in their projects. Does anyone know how to correctly include the winston logging package with webpack in an electron app?

推薦答案

這個問題有兩個方面:

1) winston 直接或間接依賴于 color.js,因此一旦 winston 存在,依賴項就會自動包含在內.在它的一些舊版本中,它包含一個動態(tài)的 require 語句,這導致:

1) winston directly or indirectly depends on color.js, so that dependency automatically gets included, once winston is there. In some older versions of it, it included a dynamic require statement, which leads to this:

2) 一個依賴有動態(tài)的 require 語句,Webpack 無法處理;您可以配置 webpack 以便它可以忽略此特定情況,或者也可以將 winston 升級到更新版本,因此 color.js 將在沒有動態(tài)要求的變體中被選擇(參見 https://github.com/winstonjs/winston/issues/984).

2) a dependency has a dynamic require statement that Webpack cannot handle; you can either configure webpack so it can ignore this specific case, or also upgrade winston to a newer version, so color.js will be picked in a variant without that dynamic require (see https://github.com/winstonjs/winston/issues/984).

要告訴 Webpack 與動態(tài) require 相處,你需要告訴 Webpack Winston 是一個外部庫.

To tell Webpack to get along with the dynamic require, you need to tell Webpack that Winston is an external library.

這是我的 webpack.config.js 中的一個示例:

Here's an example from my webpack.config.js:

 externals: {
    'electron': 'require("electron")',
    'net': 'require("net")',
    'remote': 'require("remote")',
    'shell': 'require("shell")',
    'app': 'require("app")',
    'ipc': 'require("ipc")',
    'fs': 'require("fs")',
    'buffer': 'require("buffer")',
    'winston': 'require("winston")',
    'system': '{}',
    'file': '{}'
},

要使用電子使記錄器在 Angular 2 應用程序中可用,請創(chuàng)建一個 logger.js 文件,然后用全局日志記錄服務 TypeScript 文件(即 logging.service.ts)包裝它.logger.js 文件使用所需的 Winston 配置設置創(chuàng)建 logger 變量.

To make the logger available in an angular 2 app using electron, create a logger.js file and then wrap it with a global logging service TypeScript file (i.e. logging.service.ts). The logger.js file creates the logger variable with the desired Winston configuration settings.

logger.js:

    var winston = require( 'winston' ),
    fs = require( 'fs' ),
    logDir = 'log', // Or read from a configuration
    env = process.env.NODE_ENV || 'development',
    logger;
?


     winston.setLevels( winston.config.npm.levels );
    winston.addColors( winston.config.npm.colors );

    if ( !fs.existsSync( logDir ) ) {
        // Create the directory if it does not exist
        fs.mkdirSync( logDir );
    }
    logger = new( winston.Logger )( {
        transports: [
            new winston.transports.Console( {
                level: 'warn', // Only write logs of warn level or higher
                colorize: true
            } ),
            new winston.transports.File( {
                level: env === 'development' ? 'debug' : 'info',
                filename: logDir + '/logs.log',
                maxsize: 1024 * 1024 * 10 // 10MB
            } )
        ],
        exceptionHandlers: [
            new winston.transports.File( {
                filename: 'log/exceptions.log'
            } )
        ]
    } );
    ?
    module.exports = logger;

logging.service.ts:

logging.service.ts:

export var LoggerService = require('./logger.js');

現在日志服務可以在整個應用程序中使用.

Now the logging service is available for use throughout the application.

例子:

import {LoggerService} from '<path>';
...    
LoggerService.log('info', 'Login successful for user ' + this.user.email);

這篇關于如何讓 Winston 使用 Webpack?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯(lián)網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯(lián)系我們刪除處理,感謝您的支持!

相關文檔推薦

How to fix BrowserWindow is not a constructor error when creating child window in Electron renderer process(在 Electron 渲染器進程中創(chuàng)建子窗口時如何修復 BrowserWindow 不是構造函數錯誤) - IT屋-程序員軟件開發(fā)技術
mainWindow.loadURL(quot;https://localhost:3000/quot;) show white screen on Electron app(mainWindow.loadURL(https://localhost:3000/) 在 Electron 應用程序上顯示白屏)
Electron webContents executeJavaScript : Cannot execute script on second on loadURL(Electron webContents executeJavaScript:無法在第二個 loadURL 上執(zhí)行腳本)
how to use electron browser window inside components in angular-cli?(如何在angular-cli的組件內使用電子瀏覽器窗口?)
ElectronJS - sharing redux store between windows?(ElectronJS - 在 Windows 之間共享 redux 存儲?)
How to access camera/webcamera inside electron app?(如何在電子應用程序中訪問相機/網絡攝像頭?)
主站蜘蛛池模板: 日韩电影免费观看中文字幕 | 亚洲精品av在线 | 国产视频日韩 | 精品国产乱码久久久久久1区2区 | 狠狠色网| 久久亚洲国产精品日日av夜夜 | 欧美精品成人 | 日韩色综合 | 国产成人久久精品一区二区三区 | 亚洲国产成人在线观看 | 91综合网 | 国产99精品 | 久久人体视频 | 天天躁日日躁狠狠躁白人 | 欧美一级毛片在线播放 | 在线观看国产精品一区二区 | 中文在线一区二区 | 午夜亚洲 | 一区二区在线 | 国产成人一区二区三区 | 国产精品成人久久久久a级 久久蜜桃av一区二区天堂 | 国产精品一区二区久久精品爱微奶 | 久久精品国产一区二区三区不卡 | 欧美精品一区三区 | 欧美 视频 | 欧美国产日韩精品 | 久草热播 | 美日韩一区二区 | 国产精品一二三区 | 欧美亚洲综合久久 | 日韩视频二区 | 国产视频一区在线 | 久久精品一区 | 中文字幕在线观看www | 97视频久久 | 观看毛片 | 超碰超碰 | 国产综合第一页 | 国产成人精品久久 | 国产精品日韩一区 | 国产精品亚洲第一区在线暖暖韩国 |