Permalink
Browse files

v1.1.3. Improvement.

- v1.1.3 October 18, 2012
	- Updated cli-color from 0.1 to 0.2
	- Make cli-color an optional dependency
  • Loading branch information...
1 parent 7804b36 commit d6d109608aeb58ad438e97c37d86838f02812be9 @balupton balupton committed Oct 18, 2012
Showing with 27 additions and 20 deletions.
  1. +4 −0 History.md
  2. +1 −1 example/console.coffee
  3. +5 −5 package.json
  4. +17 −14 src/lib/formatter.coffee
View
@@ -1,5 +1,9 @@
## History
+- v1.1.3 October 18, 2012
+ - Updated cli-color from 0.1 to 0.2
+ - Make cli-color an optional dependency
+
- v1.1.2 August 10, 2012
- Rejigged directory structure
- Re-added markdown files to npm distribution as they are required for the npm website
@@ -19,7 +19,7 @@ logger.log 'this','is','awesome'
# Colors
cliColor = caterpillar.cliColor
logger.log ''
-logger.log 'this is', cliColor.magenta.bold.italic.underline('awesome')
+logger.log 'this is', (cliColor?.magenta.bold.italic.underline('awesome') or 'awesome')
# Grouping
logger.config.autoFlush = false
View
@@ -1,6 +1,6 @@
{
"name": "caterpillar",
- "version": "1.1.2",
+ "version": "1.1.3",
"description": "Caterpillar is an awesome, simple console logger for node.js. It supports grouping of messages, filtering log levels, colors, times, modules, custom formatters and custom transports. It's awesome.",
"homepage": "https://github.com/bevry/caterpillar",
"keywords": [
@@ -27,12 +27,12 @@
"engines" : {
"node": ">=0.4.0"
},
- "dependencies": {
- "cli-color": "0.1.x"
+ "dependencies": {},
+ "optionalDependencies": {
+ "cli-color": "0.2.x"
},
"devDependencies": {
- "coffee-script": "1.3.x",
- "docco": "0.3.x"
+ "coffee-script": "1.3.x"
},
"directories": {
"lib": "./out/lib"
@@ -1,6 +1,9 @@
# Requires
util = require('util')
-cliColor = require('cli-color')
+try
+ cliColor = require('cli-color')
+catch err
+ cliColor = null
# Formatter
class Formatter
@@ -24,21 +27,21 @@ class Formatter
getLevel: ->
@config.level ? null
-
+
setLevel: (level) ->
@config.level = level
@
-
+
padLeft: (padding,size,msg) ->
# Prepare
padding = String(padding)
msg = String(msg)
-
+
# Handle
if msg.length < size
for i in [0...size-msg.length]
msg = padding+msg
-
+
# Return
msg
@@ -51,7 +54,7 @@ class Formatter
if msg.length < size
for i in [0...size-msg.length]
msg += padding
-
+
# Return
msg
@@ -92,7 +95,7 @@ class Formatter
@config.colors[levelCode]
else
false
-
+
getDate: ->
# Prepare
now = new Date()
@@ -106,7 +109,7 @@ class Formatter
# Return
"#{year}-#{month}-#{date} #{hours}:#{minutes}:#{seconds}.#{ms}"
-
+
getLineInfo: ->
# Prepare
result =
@@ -129,32 +132,32 @@ class Formatter
result.file = parts[0].replace(/^.+?\(/, '')
result.line = parts[1]
break
-
+
return result
# Console Formatter
class ConsoleFormatter extends Formatter
format: (levelCode,levelName,args) ->
# Prepare
{date,file,line,method,color,levelName,message} = @details(levelCode, levelName, args)
-
+
# Check
- if !message
+ if !message
message
else
# Mappings
- color = color and cliColor[color] or (str) -> str
+ color = color and cliColor?[color] or (str) -> str
levelName = color(levelName+':')
# Formatters
debugFormatter = false #cliColor.white
- messageFormatter = cliColor.bold
+ messageFormatter = color and cliColor?.bold
# Message
messageString = "#{levelName} #{message}"
messageString = messageFormatter(messageString) if messageFormatter
- #
+ #
if @config.level is 7
# Debug Information
seperator = '\n'

0 comments on commit d6d1096

Please sign in to comment.