Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tidy up some leftovers of #8847 #8976

Merged
merged 1 commit into from
Mar 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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