Skip to content

Commit

Permalink
Tidy up some leftovers of #8847 (#8976)
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian J. Cardiff authored Mar 30, 2020
1 parent 3bdaa28 commit bd498e6
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
14 changes: 7 additions & 7 deletions spec/std/log/io_backend_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ private def s(value : Log::Severity)
value
end

private def stdio_logger(*, stdout : IO, config = nil, source : String = "", progname : String? = nil)
private def io_logger(*, stdout : IO, config = nil, source : String = "", progname : String? = nil)
builder = Log::Builder.new
backend = Log::IOBackend.new
backend.progname = progname if progname
Expand All @@ -17,7 +17,7 @@ end
describe Log::IOBackend do
it "logs messages" do
IO.pipe do |r, w|
logger = stdio_logger(stdout: w)
logger = io_logger(stdout: w)
logger.debug { "debug:skip" }
logger.info { "info:show" }

Expand All @@ -37,7 +37,7 @@ describe Log::IOBackend do

it "logs context" do
IO.pipe do |r, w|
logger = stdio_logger(stdout: w)
logger = io_logger(stdout: w)
Log.context.clear
Log.with_context do
Log.context.set foo: "bar"
Expand All @@ -50,7 +50,7 @@ describe Log::IOBackend do

it "logs any object" do
IO.pipe do |r, w|
logger = stdio_logger(stdout: w)
logger = io_logger(stdout: w)
logger.info { 12345 }

r.gets.should match(/12345/)
Expand All @@ -59,7 +59,7 @@ describe Log::IOBackend do

it "formats message" do
IO.pipe do |r, w|
logger = stdio_logger(progname: "the-program", stdout: w, source: "db.pool")
logger = io_logger(progname: "the-program", stdout: w, source: "db.pool")
logger.warn { "message" }

r.gets(chomp: false).should match(/W, \[.+? #\d+\] WARNING -- the-program:db.pool: message\n/)
Expand All @@ -68,7 +68,7 @@ describe Log::IOBackend do

it "uses custom formatter" do
IO.pipe do |r, w|
logger = stdio_logger(stdout: w)
logger = io_logger(stdout: w)
logger.backend.as(Log::IOBackend).formatter = Log::Formatter.new do |entry, io|
io << entry.severity.to_s[0].upcase << ": " << entry.message
end
Expand All @@ -80,7 +80,7 @@ describe Log::IOBackend do

it "yields message" do
IO.pipe do |r, w|
logger = stdio_logger(stdout: w, progname: "prog", source: "db")
logger = io_logger(stdout: w, progname: "prog", source: "db")
logger.error { "message" }
logger.fatal { "another message" }

Expand Down
2 changes: 1 addition & 1 deletion src/log.cr
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
# end
# ```
#
# A `Log` will emit the messages to the `Log::Backends` attached to it as long as
# A `Log` will emit the messages to the `Log::Backend`s attached to it as long as
# the configured severity filter `level` permits it.
#
# Logs can also be created from a type directly. For the type `DB::Pool` the source `db.pool` will be used.
Expand Down
2 changes: 1 addition & 1 deletion src/log/context.cr
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Immutable structured context information for logging.
#
# See `Log.context`, `Log.context=`, `Log::Context#clear`, `Log::Context#set`, `Log::Context#using`.
# See `Log.context`, `Log.context=`, `Log::Context#clear`, `Log::Context#set`, `Log.with_context`.
class Log::Context
Crystal.datum types: {bool: Bool, i: Int32, i64: Int64, f: Float32, f64: Float64, s: String, time: Time}, hash_key_type: String, immutable: true

Expand Down
4 changes: 2 additions & 2 deletions src/log/main.cr
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,11 @@ class Log
end

# :ditto:
def set(values : NamedTuple) forall V
def set(values : NamedTuple)
extend_fiber_context(Fiber.current, Log::Context.new(values))
end

private def extend_fiber_context(fiber : Fiber, values : Context) forall V
private def extend_fiber_context(fiber : Fiber, values : Context)
context = fiber.logging_context
fiber.logging_context = context.merge(values)
end
Expand Down

0 comments on commit bd498e6

Please sign in to comment.