Skip to content

Commit

Permalink
Merge pull request #1316 from nanoc/logger-mutex
Browse files Browse the repository at this point in the history
Add mutex to logger
  • Loading branch information
denisdefreyne committed Feb 17, 2018
2 parents bda65cc + d07916a commit d09c9b3
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions nanoc/lib/nanoc/cli/logger.rb
Expand Up @@ -28,6 +28,7 @@ class Logger

def initialize
@level = :high
@mutex = Mutex.new
end

# Logs a file-related action.
Expand Down Expand Up @@ -63,11 +64,12 @@ def file(level, action, name, duration = nil)
#
# @return [void]
def log(level, message, io = $stdout)
# Don't log when logging is disabled
return if @level == :off
return if @level != :low && @level != level

# Log when level permits it
io.puts(message) if @level == :low || @level == level
@mutex.synchronize do
io.puts(message)
end
end
end
end

0 comments on commit d09c9b3

Please sign in to comment.