Difference between revisions of "WebFund 2016W: Tutorial 5"

From Soma-notes
Jump to navigation Jump to search
 
Line 11: Line 11:
A sample logfile is [http://homeostasis.scs.carleton.ca/~soma/webfund-2016w/code/sample.log here].  You can gather other samples simply by grabbing files from /var/log/ on any Linux/UNIX machine.
A sample logfile is [http://homeostasis.scs.carleton.ca/~soma/webfund-2016w/code/sample.log here].  You can gather other samples simply by grabbing files from /var/log/ on any Linux/UNIX machine.


Your should base your code on [http://homeostasis.scs.carleton.ca/~soma/webfund-2016w/code/storeLogLine.js storeLogLine.js], a program that creates a single database entry based on a log message entered as command line arguments.  (See the comments in the code.) To run this program you need to type "npm install mongodb".  If that doesn't work, [http://homeostasis.scs.carleton.ca/~soma/webfund-2016w/code/storeLogLine.zip download the code with node_modules].
Your should base your code on [http://homeostasis.scs.carleton.ca/~soma/webfund-2016w/code/storeLogLine.js storeLogLine.js], a program that creates a single database entry based on a log message entered as command line arguments.  (See the comments in the code.)


The documents stored by storeLogs.js should have the same format as storeLogLine.js, except there should be an additional property "source" which should contain the name of the source logfile along with the prefix "file:".  Thus, the command
The documents stored by storeLogs.js should have the same format as storeLogLine.js, except there should be an additional property "source" which should contain the name of the source logfile along with the prefix "file:".  Thus, the command
Line 20: Line 20:


  npm install mongodb
  npm install mongodb
If that doesn't work, [http://homeostasis.scs.carleton.ca/~soma/webfund-2016w/code/storeLogLine.zip download the code with node_modules].


To get checked off show a TA your working <tt>storeLogs.js</tt> or your progress working towards it by the end of tutorial time.
To get checked off show a TA your working <tt>storeLogs.js</tt> or your progress working towards it by the end of tutorial time.

Latest revision as of 17:58, 24 February 2016

In today's tutorial you'll be making a simple program, storeLogs.js that stores the logs in a file into a MongoDB database. The program can be run as follows:

 node storeLogs.js <logfile>

Where <logfile> is the name of a file with log entries, one to a line, in the following format:

 Feb 17 12:46:02 mycomputername theservice:  This is the log message

Lines should be delimited by newlines (\n). This is the default unless you are on Windows. (On Windows textfiles can be delimited with carriage returns and newlines (\r\n).)

A sample logfile is here. You can gather other samples simply by grabbing files from /var/log/ on any Linux/UNIX machine.

Your should base your code on storeLogLine.js, a program that creates a single database entry based on a log message entered as command line arguments. (See the comments in the code.)

The documents stored by storeLogs.js should have the same format as storeLogLine.js, except there should be an additional property "source" which should contain the name of the source logfile along with the prefix "file:". Thus, the command

 node storeLogs.js mylogs

should store documents with the property source having the value "file:mylogs".

Note that in order to get storeLogLine.js to run you will need to do the following first in the directory where the program file is:

npm install mongodb

If that doesn't work, download the code with node_modules.

To get checked off show a TA your working storeLogs.js or your progress working towards it by the end of tutorial time.