Permalink
Browse files

initial commit

  • Loading branch information...
0 parents commit 2e781566304002d538e19c56b92623915549c9ee @georgeOsdDev committed Nov 2, 2012
Showing with 495 additions and 0 deletions.
  1. +20 −0 .gitignore
  2. +3 −0 .npmignore
  3. +57 −0 Cakefile
  4. +76 −0 README.md
  5. BIN ScreenShot.png
  6. +2 −0 lib/debugUtil.js
  7. +38 −0 package.json
  8. +130 −0 src/debugUtil.coffee
  9. +54 −0 test/coffeelint.json
  10. +65 −0 test/test.html
  11. +50 −0 test/test.js
@@ -0,0 +1,20 @@
+out
+node_modules
+.DS_Store
+
+lib-cov
+*.seed
+*.log
+*.csv
+*.dat
+*.out
+*.pid
+*.gz
+
+pids
+logs
+results
+
+npm-debug.log
+
+.travis*
@@ -0,0 +1,3 @@
+Cakefile
+src/
+test/
@@ -0,0 +1,57 @@
+log = console.log
+crypto = require 'crypto'
+{ exec } = require 'child_process'
+
+Coffee =
+ cmd: "coffee"
+ options: [
+ "-c" #compile option
+ "-o ./lib" #dest
+ "./src/debugUtil.coffee" #src
+ ]
+
+Coffeelint =
+ cmd: "coffeelint"
+ options: [
+ "-f ./test/coffeelint.json" #config file
+ "-r" #recurisve
+ "./" #src
+ ]
+
+Uglifyjs =
+ cmd: "uglifyjs"
+ options: [
+ "--verbose" #verbose
+ "--overwrite" #overwrite
+ "./lib/debugUtil.js" #src
+ ]
+
+task 'compile', (options) ->
+ execGlobalCommand(Coffeelint)
+ execGlobalCommand(Coffee)
+ # execGlobalCommand(Stylus)
+
+task 'uglify', (options) ->
+ execGlobalCommand(Uglifyjs)
+
+task 'lint', (options) ->
+ execGlobalCommand(Coffeelint)
+
+task 'test', (options) ->
+ exec "node ./test/test.js", (err, stdout, stderr)->
+ log stdout + stderr
+
+task 'clean', (options) ->
+ clean()
+
+execGlobalCommand = (command) ->
+ exec "#{command.cmd} #{command.options.join(' ')}", (err, stdout, stderr)->
+ log stdout + stderr
+ if (command.callback)
+ exec "#{command.callback}", (err, stdout, stderr)->
+ log stdout + stderr
+
+clean = ->
+ exec 'rm -rf ./lib/*.js', (err, stdout, stderr)->
+ throw err if err
+ log stdout + stderr
@@ -0,0 +1,76 @@
+# debugUtil
+Some debug utility for both server-side and client-side javascript.
+
+## Install
+### Server Side
+
+```bash
+npm install --save debugUtil
+```
+and
+```javascript
+var debugUtil = require('debugUtil');
+```
+### Client Side
+
+```html
+<script src="/path/to/debugUtil.js"></script>
+```
+
+Client Side, `debugUtil` object is defined as `window.debugUtil`
+
+
+## Usage
+### getColorLogger(name,level,color)
+```javascript
+logger = debugUtil.getColorLogger("myLogger","info","cyan");
+logger.log("message");
+```
+e.g.
+this code will display like this
+```javascript
+defaultLogger = debugUtil.getColorLogger();
+defaultLogger.log("This line is 'debug' level and color is 'default'");
+defaultLogger.fatal("This line is 'fatal' level and color is 'red'");
+defaultLogger.error("This line is 'error' level and color is 'red'");
+defaultLogger.warn("This line is 'warn' level and color is 'yellow'");
+defaultLogger.info("This line is 'info' level and color is 'cyan'");
+defaultLogger.debug("This line is 'debug' level and color is 'default'");
+defaultLogger.trace("This line is 'trace' level and color is 'white'");
+
+//Set Name and Level
+appLogger = debugUtil.getColorLogger("App","info");
+appLogger.log("This line is 'info' level and color is 'default' and appender name is 'App'");
+
+//Set Name, Level and Color
+sysLogger = debugUtil.getColorLogger("Sys","warn","magenta");
+sysLogger.log("This line is 'warn' level and color is 'magenta' and appender name is 'Sys'");
+```
+![Screen Shot](./ScreenShot.png)
+
+### loggingWrap(context,function)
+```javascript
+function sum(a,b){
+ return a+b;
+}
+sum = debugUtil.loggingWrap(this,sum);
+sum(1,2);
+```
+in your console
+```
+Start sum
+arguments[0] = 1
+arguments[1] = 2
+result = [3]
+```
+### debugToScreen(String) *client side only
+```javascript
+debugUtil.debugToScreen("message");
+```
+message will append to `document.body` and will hide on click.
+
+
+
+## License
+Licensed under the incredibly [permissive](http://en.wikipedia.org/wiki/Permissive_free_software_licence) [MIT License](http://creativecommons.org/licenses/MIT/)
+<br/>Copyright &copy; 2012 [Takeharu.Oshida](http://georgeosddev.github.com)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
@@ -0,0 +1,38 @@
+{
+ "name": "debugUtil",
+ "version": "0.1.0",
+ "description": "Some debug utility for both server-side and client-side javascript.",
+ "homepage": "https://github.com/georgeosddev/debugUtil",
+ "keywords": [
+ "debug",
+ "logger"
+ ],
+ "author": "Takeharu.Oshida(http://georgeosddev.github.com)",
+ "maintainers": [
+ "Takeharu.Oshida(http://georgeosddev.github.com)"
+ ],
+ "contributors": [
+ "Takeharu.Oshida(http://georgeosddev.github.com)"
+ ],
+ "bugs": {
+ "url": "https://github.com/georgeosddev/debugUtil/issues"
+ },
+ "repository" : {
+ "type": "git",
+ "url": "http://github.com/georgeosddev/debugUtil.git"
+ },
+ "engines" : {
+ "node": ">=0.4.0"
+ },
+ "dependencies": {
+ },
+ "devDependencies": {
+ "coffee-script": "1.3.x",
+ "coffeelint": ">=0.5.2",
+ "uglify-js": ">=0.8.7"
+ },
+ "main": "./lib/debugUtil.js",
+ "scripts": {
+ "test": "node ./test/test.js"
+ }
+}
@@ -0,0 +1,130 @@
+root = this
+
+window?.onerror = (message, url, lineNumber) ->
+ msg = """An Error Occured on this page.
+ Error: #{message}
+ Url: #{url}
+ Line: #{lineNumber}
+ """
+ console?.log msg
+
+debugUtil =
+ VERSION: "1.0.0"
+ isBrowser:->
+ window?
+
+ loggingWrap: (self, func) ->
+ orgFunc = func
+ ->
+ console?.log "Start #{func.name}"
+ console?.log "arguments[#{i}] = #{arg}" for arg, i in arguments
+ result = orgFunc.apply self, arguments
+ console?.log "result = [#{result}]"
+ result
+
+ debugToScreen: (obj) ->
+ # for client-side only
+ if @isBrowser
+ message = obj.toString()
+ div = root.document.getElementById("debugOutput") || root.document.createElement("div")
+ div.id = "debugOutput"
+ logger = root.document.createElement("p")
+ logger.innerHTML = message
+ logger.setAttribute 'style',"background-color:whiteSmoke"
+ logger.addEventListener 'click', ->
+ div.removeChild(this)
+ div.appendChild logger
+ root.document.body.appendChild(div)
+
+ getColorLogger:(prefix="Logger",level="debug",color="default") ->
+ levels = {
+ fatal : '[FATAL]'
+ error : '[ERORR]'
+ warn : '[WARN]'
+ info : '[INFO]'
+ debug : '[DEBUG]'
+ trace : '[TRACE]'
+ }
+ colors = {
+ black : '\x1B[30m'
+ red : '\x1B[31m'
+ green : '\x1B[32m'
+ yellow : '\x1B[33m'
+ blue : '\x1B[34m'
+ magenta : '\x1B[35m'
+ cyan : '\x1B[36m'
+ white : '\x1B[37m'
+ default : '\x1B[39m'
+ end : '\x1B[39m'
+ }
+ if @isBrowser()
+ for color,val of colors
+ colors[color] = ""
+
+ if not levels[level] then level = "debug"
+ if not colors[color] then color = "default"
+
+ l0Pad = (num) ->
+ if num < 10 then "0" + num else num
+
+ localeTime = ->
+ date = new Date()
+ ret = [
+ date.getFullYear(), "-", l0Pad(date.getMonth() + 1), "-", l0Pad(date.getDate())
+ " ",
+ l0Pad(date.getHours()), ":", l0Pad(date.getMinutes()), ":", l0Pad(date.getSeconds())
+ ]
+ ret.join("")
+
+ joinArguments = (arg) ->
+ Array.prototype.join.apply arg, [" "]
+
+ Logger = {
+ prefix : "[#{prefix}]"
+ level : level
+ color : color
+
+ setLevel : (level) ->
+ @level = level
+
+ setPrefix : (prefix) ->
+ @prefix = "[ #{prefix} ]"
+
+ setColor : (color) ->
+ @color = color
+
+ print : ->
+ args = Array.prototype.slice.apply arguments
+ args.unshift @prefix
+ args.unshift localeTime()
+ args.push colors["end"]
+ console?.log args.join(" ")
+
+ log : ->
+ @print colors[@color],levels[@level],joinArguments(arguments)
+
+ fatal : ->
+ @print colors["red"],levels["fatal"],joinArguments(arguments)
+
+ error : ->
+ @print colors["red"],levels["error"],joinArguments(arguments)
+
+ warn : ->
+ @print colors["yellow"],levels["warn"],joinArguments(arguments)
+
+ info : ->
+ @print colors["cyan"],levels["info"],joinArguments(arguments)
+
+ debug : ->
+ @print colors["default"],levels["debug"],joinArguments(arguments)
+
+ trace : ->
+ @print colors["white"],levels["trace"],joinArguments(arguments)
+ }
+
+if typeof exports isnt 'undefined'
+ if typeof module isnt 'undefined' and module.exports
+ module.exports = debugUtil
+ exports.debugUtil = debugUtil
+else
+ root["debugUtil"] = debugUtil
@@ -0,0 +1,54 @@
+{
+ "no_tabs" : {
+ "level" : "error"
+ },
+
+ "no_trailing_whitespace" : {
+ "level" : "error"
+ },
+
+ "max_line_length" : {
+ "value": 120,
+ "level" : "error"
+ },
+
+ "camel_case_classes" : {
+ "level" : "error"
+ },
+
+ "indentation" : {
+ "value" : 2,
+ "level" : "error"
+ },
+
+ "no_implicit_braces" : {
+ "level" : "ignore"
+ },
+
+ "no_trailing_semicolons" : {
+ "level" : "error"
+ },
+
+ "no_plusplus" : {
+ "level" : "ignore"
+ },
+
+ "no_throwing_strings" : {
+ "level" : "error"
+ },
+
+ "cyclomatic_complexity" : {
+ "value" : 11,
+ "level" : "ignore"
+ },
+
+ "line_endings" : {
+ "value" : "unix",
+ "level" : "ignore"
+ },
+
+ "no_implicit_parens" : {
+ "level" : "ignore"
+ }
+
+}
Oops, something went wrong.

0 comments on commit 2e78156

Please sign in to comment.