How do I show logs in the console using angular-CL

2019-05-04 19:08发布

问题:

I'm using angular-cli for webpack.

ng serve

and the build succeed and I see

** NG Live Development Server is running on http://localhost:4200. **
Hash: dd30d5aeee6e21802b4d e Time: 9397ms
chunk {0} styles.bundle.js, styles.bundle.map (styles) 163 kB {4} [initial] [rendered]
chunk {1} main.bundle.js, main.bundle.map (main) 6.52 kB {3} [initial] [rendered]
chunk {2} scripts.bundle.js, scripts.bundle.map (scripts) 361 kB {4} [initial] [rendered]
chunk {3} vendor.bundle.js, vendor.bundle.map (vendor) 2.22 MB [initial] [rendered]
chunk {4} inline.bundle.js, inline.bundle.map (inline) 0 bytes [entry] [rendered]
webpack: bundle is now VALID.

nothing seems to be wrong. But I don't see any logs on the console when I access http://localhost:4200. Is there anyway I could turn on the server log on console?

回答1:

You can't make your angular code log to the shell that started ng serve, sorry :-(

You will only see build errors in that console



回答2:

You need to change the filter in console window of your google chrome browser, then you can see the message which you have written in console.log() method.



回答3:

When I do console.log("something") the log is appearing in the browser inspector console tab. I do not need any configuration.



回答4:

Although you can't log dom/web events in the console that don't cause server requests, you can increase the amount of information that the compilation process and static web server provide by passing a --verbose flag when starting up: ng serve --verbose.

Also, if you're running a proxy a server to hit a local API server and you want some more logging regarding how those requests are being proxied, you can increase the logLevel in your proxy configuration.

Example proxy.conf.json: { "/api": { "target": "http://localhost:3001", "secure": false, "logLevel": "debug" } }

You would then be starting the server as ng serve --proxy-config proxy.conf.json --verbose.



回答5:

you can also install and run another server. a simple one to use can be installed via npm:

npm install http-server

if you're using routing, you might want to use spa-http-server

npm install spa-http-server