Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Input in more methods inside the class

  • Loading branch information...
commit aeadc9c09c133f2b4881af922ddd05d593fb1a38 1 parent 838e59d
Fadrizul H. authored
4 index.js
View
@@ -1,5 +1,7 @@
/*
-Logs-it by Fadrizul H.
+Logs-It
+Copyright (C) 2012 Fadrizul H. <fadrizul@gmail.com>
+MIT Licensed
*/
var LogsIt;
4 lib/ansi-codes.js
View
@@ -1,5 +1,7 @@
/*
-Logs-It by Fadrizul H. - ANSI codes
+Logs-It
+Copyright (C) 2012 Fadrizul H. <fadrizul@gmail.com>
+MIT Licensed
*/
var ansiCodes;
30 lib/logs-it.js
View
@@ -1,26 +1,48 @@
/*
-Logs-It by Fadrizul H.
+Logs-It
+Copyright (C) 2012 Fadrizul H. <fadrizul@gmail.com>
+MIT Licensed
*/
-var LogsIt, ansiCodes, util;
+var LogsIt, colour, util;
util = require("util");
-ansiCodes = require("./ansi-codes");
+colour = require("./ansi-codes");
LogsIt = (function() {
function LogsIt() {}
+ LogsIt.prototype.it = function(input) {
+ var json;
+ if (this.isItSerialised === true) {
+ return util.log(this.inspect(input));
+ } else {
+ json = JSON.stringify(input);
+ return util.log(this.inspect(json));
+ }
+ };
+
LogsIt.prototype.inspect = function(input) {
var nodeId;
nodeId = process.pid;
- return console.log(this.colourIt("NodeId: " + nodeId + " - " + input, ansiCodes.cyan));
+ return this.colourIt("NodeId: " + nodeId + " - " + (this.colourIt(input, colour.red)), colour.blue);
};
LogsIt.prototype.colourIt = function(str, code) {
return "\033[" + code + "m " + str;
};
+ LogsIt.prototype.isItSerialised = function(input) {
+ var isBoolean, isNull, isNumber, isString;
+ isString = typeof input === "string";
+ isBoolean = typeof input === "boolean";
+ isNumber = typeof input === "number";
+ isNull = typeof input === null;
+ if (isString || isBoolean || isNumber || isNull) return true;
+ return false;
+ };
+
return LogsIt;
})();
5 src/index.coffee
View
@@ -1,7 +1,10 @@
###
-Logs-it by Fadrizul H.
+Logs-It
+Copyright (C) 2012 Fadrizul H. <fadrizul@gmail.com>
+MIT Licensed
###
+
# Load & exports the module
# ------------------------------------------------------------------------------
LogsIt = require "./lib/logs-it"
5 src/lib/ansi-codes.coffee
View
@@ -1,7 +1,10 @@
###
-Logs-It by Fadrizul H. - ANSI codes
+Logs-It
+Copyright (C) 2012 Fadrizul H. <fadrizul@gmail.com>
+MIT Licensed
###
+
ansiCodes =
off : 0
bold : 1
28 src/lib/logs-it.coffee
View
@@ -1,21 +1,41 @@
###
-Logs-It by Fadrizul H.
+Logs-It
+Copyright (C) 2012 Fadrizul H. <fadrizul@gmail.com>
+MIT Licensed
###
# Load dependencies
# ------------------------------------------------------------------------------
-util = require "util"
-ansiCodes = require "./ansi-codes"
+util = require "util"
+colour = require "./ansi-codes"
class LogsIt
+ it : (input) ->
+
+ if @isItSerialised is true
+ util.log @inspect input
+ else
+ json = JSON.stringify input
+ util.log @inspect json
+
inspect : (input) ->
nodeId = process.pid
- console.log @colourIt "NodeId: #{ nodeId } - #{ input }", ansiCodes.cyan
+ @colourIt "NodeId: #{ nodeId } - #{ @colourIt input, colour.red }", colour.blue
colourIt : (str, code) ->
return "\033[#{ code }m #{ str }"
+ isItSerialised : (input) ->
+
+ isString = typeof input is "string"
+ isBoolean = typeof input is "boolean"
+ isNumber = typeof input is "number"
+ isNull = typeof input is null
+
+ return true if isString or isBoolean or isNumber or isNull
+ return false
+
module.exports = LogsIt
Please sign in to comment.
Something went wrong with that request. Please try again.