Skip to content
This repository has been archived by the owner on Nov 22, 2022. It is now read-only.

Commit

Permalink
make logger output configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
piscis committed Mar 11, 2013
1 parent e0b4308 commit b215ab0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
10 changes: 5 additions & 5 deletions lib/livecss.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class LiveUpdateMixin

liveUpdate: (cssmanager, userio) ->
if @production
console.log "Not activating live update in production"
@logger.info "Not activating live update in production"
return

if not @app
Expand All @@ -73,7 +73,7 @@ class LiveUpdateMixin

listener = if @server then @server else @app
listener.on "listening", =>
console.log "Activating CSS updater"
@logger.info "Activating CSS updater"

for k, pile of cssmanager.piles
for codeOb in pile.code
Expand All @@ -82,9 +82,9 @@ class LiveUpdateMixin

_watch: (pile, codeOb) ->
return unless codeOb.type is "file"
console.log "watching #{ codeOb.filePath } for changes"
@logger.info "watching #{ codeOb.filePath } for changes"
fs.watch codeOb.filePath, =>
console.log "updated", codeOb.filePath
@logger.info "updated", codeOb.filePath
@io.emit "update", codeOb.getId()

# For testing
Expand All @@ -95,5 +95,5 @@ if socketio?
else
module.exports = class LiveUpdateDisabled
liveUpdate: ->
console.log "No socket.io installed. Live update won't work."
@logger.error "No socket.io installed. Live update won't work."

8 changes: 8 additions & 0 deletions lib/logger.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Basic Logger functionality
exports.debug = console.debug
exports.notice = console.log
exports.info = console.info
exports.warn = console.warn
exports.warning = console.warn
exports.error = console.error
exports.critical = console.error
10 changes: 8 additions & 2 deletions lib/piler.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ async = require "async"
OB = require "./serialize"
compilers = require "./compilers"
assetUrlParse = require "./asseturlparse"
logger = require "./logger"

toGlobals = (globals) ->
code = ""
Expand Down Expand Up @@ -149,7 +150,7 @@ class BasePile

warnPiledUp: (fnname) ->
if @piledUp
console.log "Warning pile #{ @name } has been already piled up. Calling #{ fnname } does not do anything."
@logger.warn "Warning pile #{ @name } has been already piled up. Calling #{ fnname } does not do anything."

pileUp: (cb) ->
@piledUp = true
Expand Down Expand Up @@ -242,6 +243,9 @@ class PileManager
constructor: (@settings) ->
@production = @settings.production
@settings.urlRoot ?= "/pile/"
@logger = @settings.logger || logger



@piles =
global: new @Type "global", @production, @settings.urlRoot
Expand All @@ -266,6 +270,8 @@ class PileManager
pile.addUrl url

pileUp: ->
logger = @logger
logger.notice "Start assets generation for '#{ @Type::ext }'"
for name, pile of @piles then do (pile) =>
pile.pileUp (err, code) =>
throw err if err
Expand All @@ -275,7 +281,7 @@ class PileManager

fs.writeFile outputPath, code, (err) ->
throw err if err
console.log "Wrote #{ pile.ext } pile #{ pile.name } to #{ outputPath }"
logger.info "Wrote #{ pile.ext } pile #{ pile.name } to #{ outputPath }"

getSources: (namespaces...) ->
if typeof _.last(namespaces) is "object"
Expand Down

0 comments on commit b215ab0

Please sign in to comment.