Home  >  Article  >  Web Front-end  >  Use Log.io in Node.js to monitor logs in real time in the browser (equivalent to the tail -f command)_node.js

Use Log.io in Node.js to monitor logs in real time in the browser (equivalent to the tail -f command)_node.js

WBOY
WBOYOriginal
2016-05-16 16:36:131766browse

Today, I took some time to browse node.js. Haha, I read an introductory article (http://www.nodebeginner.org/index-zh-cn.html). I feel that I am getting started, but There is a sentence in it that is quite enlightening:

Copy code The code is as follows:

However, these are all front-end technologies after all. Although it always feels good to use jQuery when you want to enhance the page, in the end, you are at most a JavaScript user, not a JavaScript developer. Then, along comes Node.js, server-side JavaScript, how cool is that? So, you think it’s time to pick up the familiar yet unfamiliar JavaScript again. But wait, writing Node.js applications is one thing; understanding why they are written the way they are written means — you need to know JavaScript. This time it's for real.
Yes, this time we are going to play it for real. .

By the way, I saw a good thing log.io, the official explanation is:

Copy code The code is as follows:

Real-time log monitoring in your browser
Powered by node.js socket.io

Real-time log monitoring, we may think of tail -f under Linux, log.io has roughly the same meaning, but it is much more powerful than tail -f. This thing is also based on C/S architecture.

The following is a practical demonstration:

1. Installation

This thing depends on nodejs. Let’s install nodejs first and refer to the official installation method: (http://nodejs.org/download/)

I am using the mac brew installation method here:

Copy code The code is as follows:

brew install nodejs

Or use yum:

Copy code The code is as follows:

yum install nodejs

After that we can use npm to install log.io

Copy code The code is as follows:

npm install -g log.io --user "chenqing"

After installation, start the server (no configuration required):

Copy code The code is as follows:

log.io-server

Configure the client afterwards

Copy code The code is as follows:

vim ~/.log.io/harvester.conf

exports.config = {
nodeName: "application_server",
logStreams: {
test: [
"/Users/chenqing/test.log"
]
},
server: {
host: '0.0.0.0',
port: 28777
}
}

Start the client: log.io-harvester

Let’s test it out:

First go to the command line

Copy code The code is as follows:

[ chenqing@Qing ~ ] for i in {1..1000};do echo `date ` >> test.log ;done

Open the browser: http://localhost:28778/

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn