-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(rewrite) allow to set log lvl and format from cassandra
- Loading branch information
1 parent
a7f321a
commit 67dbaa9
Showing
8 changed files
with
95 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
unused_args = false | ||
redefined = false | ||
globals = {"ngx", "describe", "setup", "teardown", "it", "pending", "before_each", "after_each", "finally", "spy"} | ||
globals = {"ngx", "describe", "setup", "teardown", "it", "pending", "before_each", "after_each", "finally", "spy", "mock"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
local log = require "cassandra.log" | ||
local cassandra = require "cassandra" | ||
|
||
describe("Casandra", function() | ||
local p = log.print | ||
setup(function() | ||
spy.on(log, "set_lvl") | ||
local l = mock(log.print, true) | ||
log.print = l | ||
end) | ||
teardown(function() | ||
log.set_lvl:revert() | ||
log.print = p | ||
end) | ||
it("should have a default logging level", function() | ||
local lvl = log.get_lvl() | ||
assert.equal(3, lvl) | ||
end) | ||
it("should have a default format", function() | ||
finally(function() | ||
log.print:clear() | ||
end) | ||
log.err("hello") | ||
assert.spy(log.print).was.called_with("ERR -- hello") | ||
end) | ||
describe("set_log_level", function() | ||
it("should set the logging level when outside of ngx_lua", function() | ||
finally(function() | ||
log.print:clear() | ||
end) | ||
|
||
cassandra.set_log_level("INFO") | ||
assert.spy(log.set_lvl).was.called_with("INFO") | ||
|
||
-- INFO | ||
log.err("hello world") | ||
log.info("hello world") | ||
assert.spy(log.print).was.called(2) | ||
|
||
log.print:clear() | ||
cassandra.set_log_level("ERR") | ||
|
||
-- ERR | ||
log.err("bye world") | ||
log.info("bye world") | ||
assert.spy(log.print).was.called(1) | ||
end) | ||
end) | ||
describe("set_log_format", function() | ||
it("should set the logging format when outside of ngx_lua", function() | ||
finally(function() | ||
log.print:clear() | ||
end) | ||
|
||
cassandra.set_log_format("Cassandra [%s]: %s") | ||
log.err("some error") | ||
assert.spy(log.print).was.called_with("Cassandra [ERR]: some error") | ||
end) | ||
end) | ||
end) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters