Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,32 @@ Just Node.js saying hello to the world and such.



<h3>Maddie Rajavasireddy</h3>

<h3>Description:</h3>

<h4>Building the Logger</h4>

Create a logger module. Logger will need the following features:

A log method that takes 2 parameters
The first parameter should be the message to log
The second parameter should be a string specifying the logging level (INFO, WARNING, ERROR)
An info method that only takes a single parameter for the message and outputs it at the info level
A warning method that only takes a single parameter for the message and outputs it at the warning level
An error method that only takes a single parameter for the message and outputs it at the error level

Based on the logging level, colorize your output using chalk according to the following chart
INFO: blue
WARNING: yellow
ERROR: red

<h4>Logging from a JSON File</h4>

Now that the logger is built and ready to use, require the JSON file in the data/ folder so that one can output the messages. Each message has a "level" key so be sure to output the message using the correct level in the logger!

Require the JSON file
Require lodash to make iterating over the JSON object easier
Use the lodash _.each function to iterate over the JSON
Output the message for each entry at the given logging level
Verify that the JSON is output correctly and each message is colorized according to its logging level
8 changes: 8 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
var _ = require("lodash"); //get lodash
var logs = require("./data/logs");
var logger = require("./lib/logger");

//loop through the logs and print to console
_.each(logs, function(log){
logger.log(log.message, log.level);
});
30 changes: 30 additions & 0 deletions lib/logger.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const chalk = require("chalk"); //get chalk

var logger = {
log: function(message, level){
//call different method based on log level
switch(level) {
case "info":
this.info(message);
break;
case "warning":
this.warning(message);
break;
case "error":
this.error(message);
}

},
info: function(message){
console.log(chalk.blue(message)); //info -> message in blue
},
warning: function(message){
console.log(chalk.yellow(message)); //info -> message in yellow
},
error: function(message){
console.log(chalk.red(message)); //info -> message in red
}
};

//export logger
module.exports = logger;
23 changes: 23 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "assignment_node_hello_world",
"version": "1.0.0",
"description": "assignment_node_hello_world ===========================",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/maddiereddy/assignment_node_hello_world.git"
},
"author": "Maddie Rajavasireddy",
"license": "ISC",
"bugs": {
"url": "https://github.com/maddiereddy/assignment_node_hello_world/issues"
},
"homepage": "https://github.com/maddiereddy/assignment_node_hello_world#readme",
"dependencies": {
"chalk": "^2.1.0",
"lodash": "^4.17.4"
}
}