Permalink
Browse files

Merge pull request #14 from Postmedia/logging

Update default logging with optional env setting
  • Loading branch information...
2 parents 8954f09 + e94b810 commit 7a621cc0887bf86555815a32b18a9390cd07ba49 Edward de Groot committed Oct 11, 2012
View
@@ -1,3 +1,7 @@
+0.4.1 / 2012-10-11
+===================
+ * Update default logging with optional env setting
+
0.4.0 / 2012-10-05
===================
* Upgraded dependencies
View
@@ -1,7 +1,7 @@
{
"name": "pantry",
"description": "A JSON/XML resource caching library based on Request",
- "version": "0.4.0",
+ "version": "0.4.1",
"homepage": "https://github.com/Postmedia/pantry",
"author": "Edward de Groot <edegroot@postmedia.com> (http://mred9.com)",
"contributors": [
@@ -2,7 +2,7 @@ Log = require 'coloured-log'
Memcached = require 'memcached'
module.exports = class MemcachedStorage
- constructor: (servers = "localhost:11211", options = {}, verbosity = 'DEBUG') ->
+ constructor: (servers = "localhost:11211", options = {}, verbosity = Log.NOTICE) ->
# configure the log
@log = new Log(verbosity)
View
@@ -2,7 +2,7 @@ Log = require 'coloured-log'
module.exports = class MemoryStorage
- constructor: (options = {}, verbosity = 'ERROR') ->
+ constructor: (options = {}, verbosity = Log.NOTICE) ->
# default configuration
@config = {capacity: 1000}
View
@@ -2,7 +2,7 @@ Log = require 'coloured-log'
redis = require 'redis'
module.exports = class RedisStorage
- constructor: (port = 6379, host = 'localhost', options = {}, verbosity = 'ERROR') ->
+ constructor: (port = 6379, host = 'localhost', options = {}, verbosity = Log.NOTICE) ->
# configure the log
@log = new Log(verbosity)
@up = false # used to track status of connection
View
@@ -13,14 +13,14 @@ config = {
shelfLife: 60
maxLife: 300
caseSensitive: true
- verbosity: 'ERROR'
+ verbosity: process.env.PANTRY_VERBOSITY or Log.NOTICE
xmlOptions: {explicitRoot: false}
}
log = new Log(config.verbosity)
inProgress = {} # holds requests in progress
@storage = null # cache storage container
-@backup = new MemoryStorage(config) # backup memory storage container (if primary storage isn't available)
+@backup = new MemoryStorage(config, config.verbosity) # backup memory storage container (if primary storage isn't available)
# update configuration and defaults
@configure = (options) ->
@@ -1,12 +1,13 @@
should = require 'should'
+Log = require 'coloured-log'
Storage = require '../src/pantry-memcached'
MockResource = require '../mocks/resource-mock'
describe 'pantry-memcached', ->
describe 'get/put', ->
describe 'when adding an item to storage', ->
- storage = new Storage
+ storage = new Storage(null, null, Log.CRITICAL)
resource = new MockResource 'fresh', "Hello World #{new Date()}"
it 'should not return an error', (done) ->
storage.put resource, (err, results) ->
@@ -1,4 +1,5 @@
should = require 'should'
+Log = require 'coloured-log'
Storage = require '../src/pantry-memory'
MockResource = require '../mocks/resource-mock'
@@ -12,25 +13,25 @@ describe 'pantry-memory', ->
describe 'config', ->
describe 'when configuring capacity with no specified ideal', ->
it 'should have an ideal capicity of 90%', ->
- (new Storage {capacity: 100}).config.should.have.property 'ideal', 90
+ (new Storage {capacity: 100}, Log.CRITICAL).config.should.have.property 'ideal', 90
describe 'when configuring an ideal > 90%', ->
it 'should have an ideal capicity of 90%', ->
- (new Storage {capacity: 100, ideal: 95}).config.should.have.property 'ideal', 90
+ (new Storage {capacity: 100, ideal: 95}, Log.CRITICAL).config.should.have.property 'ideal', 90
describe 'when configuring an ideal < 10%', ->
it 'should have an ideal capicity of 10%', ->
- (new Storage {capacity: 100, ideal: 5}).config.should.have.property 'ideal', 10
+ (new Storage {capacity: 100, ideal: 5}, Log.CRITICAL).config.should.have.property 'ideal', 10
describe 'when configuring an ideal between 10% and 90%', ->
it 'should have an ideal capicity as specified', ->
- (new Storage {capacity: 100, ideal: 11}).config.should.have.property 'ideal', 11
- (new Storage {capacity: 100, ideal: 50}).config.should.have.property 'ideal', 50
- (new Storage {capacity: 100, ideal: 89}).config.should.have.property 'ideal', 89
+ (new Storage {capacity: 100, ideal: 11}, Log.CRITICAL).config.should.have.property 'ideal', 11
+ (new Storage {capacity: 100, ideal: 50}, Log.CRITICAL).config.should.have.property 'ideal', 50
+ (new Storage {capacity: 100, ideal: 89}, Log.CRITICAL).config.should.have.property 'ideal', 89
describe 'get/put', ->
describe 'when adding an item to storage', ->
- storage = new Storage
+ storage = new Storage( {}, Log.CRITICAL)
resource = new MockResource 'fresh', "Hello World #{new Date()}"
it 'should not return an error', (done) ->
storage.put resource, (err, results) ->
@@ -42,7 +43,7 @@ describe 'pantry-memory', ->
describe 'cleanup', ->
describe 'when capacity has been exceeded with fresh items', ->
- storage = new Storage({capacity: 3, ideal: 2})
+ storage = new Storage({capacity: 3, ideal: 2}, Log.CRITICAL)
.put(new MockResource())
.put(new MockResource())
.put(new MockResource())
@@ -51,7 +52,7 @@ describe 'pantry-memory', ->
storage.stockCount.should.equal storage.config.ideal
describe 'when capacity has been exceeded and contains spoiled items', ->
- storage = new Storage({capacity: 5, ideal: 4})
+ storage = new Storage({capacity: 5, ideal: 4}, Log.CRITICAL)
.put(new MockResource())
.put(new MockResource('expired'))
.put(new MockResource('spoiled'))
@@ -68,7 +69,7 @@ describe 'pantry-memory', ->
countState(storage, 'expired').should.equal 1
describe 'when capacity has been exceeded and contains expired items', ->
- storage = new Storage({capacity: 5, ideal: 4})
+ storage = new Storage({capacity: 5, ideal: 4}, Log.CRITICAL)
.put(new MockResource())
.put(new MockResource('expired'))
.put(new MockResource('expired'))
@@ -82,7 +83,7 @@ describe 'pantry-memory', ->
describe 'clear', ->
it 'should empty the storage', ->
- storage = new Storage()
+ storage = new Storage( {}, Log.CRITICAL)
.put(new MockResource())
.put(new MockResource())
storage.clear()
@@ -1,12 +1,13 @@
should = require 'should'
+Log = require 'coloured-log'
Storage = require '../src/pantry-redis'
MockResource = require '../mocks/resource-mock'
describe 'pantry-redis', ->
describe 'get/put', ->
describe 'when adding an item to storage', ->
- storage = new Storage
+ storage = new Storage(null, null, null, Log.CRITICAL)
resource = new MockResource 'fresh', "Hello World #{new Date()}"
it 'should not return an error', (done) ->
storage.put resource, (err, results) ->
View
@@ -1,5 +1,6 @@
should = require 'should'
pantry = require '../src/pantry'
+Log = require 'coloured-log'
describe 'pantry', ->
describe 'configure', ->
@@ -8,14 +9,14 @@ describe 'pantry', ->
config.should.have.property 'shelfLife', 60
config.should.have.property 'maxLife', 300
config.should.have.property 'caseSensitive', true
- config.should.have.property 'verbosity', 'ERROR'
+ config.should.have.property 'verbosity', Log.Notice
it 'should allow configuration overides', ->
- config = pantry.configure { caseSensitive: false}
+ config = pantry.configure { caseSensitive: false, verbosity: Log.CRITICAL}
config.should.have.property 'shelfLife', 60
config.should.have.property 'maxLife', 300
config.should.have.property 'caseSensitive', false
- config.should.have.property 'verbosity', 'ERROR'
+ config.should.have.property 'verbosity', Log.CRITICAL
describe 'generateKey', ->
it 'should leave case alone if caseSensitive', ->

0 comments on commit 7a621cc

Please sign in to comment.