WebFund 2016W: Tutorial 5
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
To get checked off show a TA your working storeLogs.js or your progress working towards it by the end of tutorial time.