Skip to content

Commit 7aeb681

Browse files
committed
Logger is now in the Concern module.
1 parent 5b7e969 commit 7aeb681

15 files changed

+53
-42
lines changed

lib/concurrent/actor.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
require 'concurrent/configuration'
22
require 'concurrent/executor/serialized_execution'
3-
require 'concurrent/logging'
43
require 'concurrent/synchronization'
54
require 'concurrent/edge/future'
65

lib/concurrent/actor/behaviour/abstract.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1+
require 'concurrent/concern/logging'
2+
13
module Concurrent
24
module Actor
35
module Behaviour
46
class Abstract
57
include TypeCheck
68
include InternalDelegations
9+
include Concern::Logging
710

811
attr_reader :core, :subsequent
912

@@ -39,7 +42,7 @@ def broadcast(public, event)
3942
def reject_envelope(envelope)
4043
envelope.reject! ActorTerminated.new(reference)
4144
dead_letter_routing << envelope unless envelope.future
42-
log Logging::DEBUG, "rejected #{envelope.message} from #{envelope.sender_path}"
45+
log DEBUG, "rejected #{envelope.message} from #{envelope.sender_path}"
4346
end
4447
end
4548
end

lib/concurrent/actor/behaviour/sets_results.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ def on_envelope(envelope)
1414
result = pass envelope
1515
if result != MESSAGE_PROCESSED && !envelope.future.nil?
1616
envelope.future.success result
17-
log Logging::DEBUG, "finished processing of #{envelope.message.inspect}"
17+
log DEBUG, "finished processing of #{envelope.message.inspect}"
1818
end
1919
nil
2020
rescue => error
21-
log Logging::ERROR, error
21+
log ERROR, error
2222
case error_strategy
2323
when :terminate!
2424
terminate!

lib/concurrent/actor/context.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require 'concurrent/concern/logging'
2+
13
module Concurrent
24
module Actor
35

@@ -22,6 +24,7 @@ module Actor
2224
class AbstractContext
2325
include TypeCheck
2426
include InternalDelegations
27+
include Concern::Logging
2528

2629
attr_reader :core
2730

lib/concurrent/actor/core.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
require 'concurrent/concern/logging'
12
require 'concurrent/executors'
23

34
module Concurrent
@@ -11,7 +12,7 @@ module Actor
1112
# that would eat up all threads in task pool and deadlock
1213
class Core < Synchronization::Object
1314
include TypeCheck
14-
include Concurrent::Logging
15+
include Concern::Logging
1516

1617
# @!attribute [r] reference
1718
# Reference to this actor which can be safely passed around.
@@ -44,7 +45,7 @@ class Core < Synchronization::Object
4445
# @option opts [CompletableFuture, nil] initialized, if present it'll be set or failed after {Context} initialization
4546
# @option opts [Reference, nil] parent **private api** parent of the actor (the one spawning )
4647
# @option opts [Proc, nil] logger a proc accepting (level, progname, message = nil, &block) params,
47-
# can be used to hook actor instance to any logging system, see {Concurrent::Logging}
48+
# can be used to hook actor instance to any logging system, see {Concurrent::Concern::Logging}
4849
# @param [Proc] block for class instantiation
4950
def initialize(opts = {}, &block)
5051
super(&nil)
@@ -127,7 +128,7 @@ def schedule_execution
127128
end
128129

129130
def broadcast(public, event)
130-
log Logging::DEBUG, "event: #{event.inspect} (#{public ? 'public' : 'private'})"
131+
log DEBUG, "event: #{event.inspect} (#{public ? 'public' : 'private'})"
131132
@first_behaviour.on_event(public, event)
132133
end
133134

lib/concurrent/actor/default_dead_letter_handler.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module Concurrent
22
module Actor
33
class DefaultDeadLetterHandler < RestartingContext
44
def on_message(dead_letter)
5-
log Logging::INFO, "got dead letter #{dead_letter.inspect}"
5+
log INFO, "got dead letter #{dead_letter.inspect}"
66
end
77
end
88
end

lib/concurrent/agent.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
require 'thread'
22
require 'concurrent/concern/dereferenceable'
33
require 'concurrent/concern/observable'
4-
require 'concurrent/logging'
4+
require 'concurrent/concern/logging'
55
require 'concurrent/executor/executor'
66
require 'concurrent/concern/deprecation'
77

@@ -81,7 +81,7 @@ module Concurrent
8181
class Agent
8282
include Concern::Dereferenceable
8383
include Concern::Observable
84-
include Logging
84+
include Concern::Logging
8585
include Concern::Deprecation
8686

8787
attr_reader :timeout, :io_executor, :fast_executor

lib/concurrent/concern/deprecation.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
require 'concurrent/logging'
1+
require 'concurrent/concern/logging'
22

33
module Concurrent
44
module Concern
55

66
module Deprecation
77
# TODO require additional parameter: a version. Display when it'll be removed based on that. Error if not removed.
8-
include Logging
8+
include Concern::Logging
99

1010
def deprecated(message, strip = 2)
1111
caller_line = caller(strip).first

lib/concurrent/concern/logging.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
require 'logger'
2+
3+
module Concurrent
4+
module Concern
5+
6+
# Include where logging is needed
7+
module Logging
8+
include Logger::Severity
9+
10+
# Logs through {Configuration#logger}, it can be overridden by setting @logger
11+
# @param [Integer] level one of Logger::Severity constants
12+
# @param [String] progname e.g. a path of an Actor
13+
# @param [String, nil] message when nil block is used to generate the message
14+
# @yieldreturn [String] a message
15+
def log(level, progname, message = nil, &block)
16+
(@logger || Concurrent.global_logger).call level, progname, message, &block
17+
rescue => error
18+
$stderr.puts "`Concurrent.configuration.logger` failed to log #{[level, progname, message, block]}\n" +
19+
"#{error.message} (#{error.class})\n#{error.backtrace.join "\n"}"
20+
end
21+
end
22+
end
23+
end

lib/concurrent/configuration.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
require 'concurrent/atomics'
33
require 'concurrent/errors'
44
require 'concurrent/executors'
5+
require 'concurrent/concern/deprecation'
6+
require 'concurrent/concern/logging'
57
require 'concurrent/utility/at_exit'
68
require 'concurrent/utility/processor_counter'
7-
require 'concurrent/concern/deprecation'
89

910
module Concurrent
10-
extend Logging
11+
extend Concern::Logging
1112
extend Concern::Deprecation
1213

1314
# Suppresses all output when used for logging.

0 commit comments

Comments
 (0)