chimurai / http-proxy-middleware

:zap: The one-liner node.js http-proxy middleware for connect, express, next.js and more
MIT License
10.7k stars 834 forks source link

logLevel:'debug' does not take effect in vue-cli5 #814

Closed li-2021 closed 2 years ago

li-2021 commented 2 years ago

Checks

Describe the bug (be clear and concise)

In the Vue project created by vue-cli5, I configured the proxy's loglevel: 'debug', but it did not print any logs on the console.Proxy is actually in effect. I try to print in the source code.It can print.However, this.logger.debug method does not print.

this.prepareProxyRequest = async (req) => {
            // https://github.com/chimurai/http-proxy-middleware/issues/17
            // https://github.com/chimurai/http-proxy-middleware/issues/94
            req.url = req.originalUrl || req.url;
            // store uri before it gets rewritten for logging
            const originalPath = req.url;
            const newProxyOptions = Object.assign({}, this.proxyOptions);
            // Apply in order:
            // 1. option.router
            // 2. option.pathRewrite
            await this.applyRouter(req, newProxyOptions);
            await this.applyPathRewrite(req, this.pathRewriter);
            // debug logging for both http(s) and websockets
            if (this.proxyOptions.logLevel === 'debug') {
                const arrow = (0, logger_1.getArrow)(originalPath, req.url, this.proxyOptions.target, newProxyOptions.target);
                console.log('[HPM] %s %s %s %s', req.method, originalPath, arrow, newProxyOptions.target);
                this.logger.debug('[HPM] %s %s %s %s', req.method, originalPath, arrow, newProxyOptions.target);
            }
            return newProxyOptions;
        };

Step-by-step reproduction instructions

1. Configure agent in vue-cli5 project logLevel: 'debug'
2. Start project and request interface

Expected behavior (be clear and concise)

When I configure loglevel: 'debug', I should print the relevant logs on the console when I call the interface through inversion.

  devServer: {
    https: false,
    proxy: {
      '/container-api': {
        target: 'http://***.***.***.204:30080',
        pathRewrite: { '^/container-api': '' },
        changeOrigin: true,
        logLevel: 'debug'
      },
    }
  },

How is http-proxy-middleware used in your project?

Configure the proxy directly in the Vue project created by vue-cli5

What http-proxy-middleware configuration are you using?

const { defineConfig } = require('@vue/cli-service')
module.exports = defineConfig({
  transpileDependencies: true,
  devServer: {
    https: false,
    proxy: {
      '/container-api': {
        target: 'http://***.***.***.204:30080',
        pathRewrite: { '^/container-api': '' },
        changeOrigin: true,
        logLevel: 'debug'
      },
    }
  },
})

What OS/version and node/version are you seeing the problem?

chrome. windows 10 and Node 16.8.0

Additional context (optional)

No response

chimurai commented 2 years ago

console.debug is only visible with node --inspect

Explained in: https://stackoverflow.com/a/47147123/3841188

Logging has been improved in v3 (still in beta) of http-proxy-middleware. And will only use info, warn and error for better compatibility: https://github.com/chimurai/http-proxy-middleware/blob/master/src/logger.ts

chimurai commented 2 years ago

Closing stale issue. Feel free to re-open.