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

Lua redis.log implementation #266

Merged
merged 3 commits into from Mar 16, 2020
Merged

Lua redis.log implementation #266

merged 3 commits into from Mar 16, 2020

Conversation

upcFrost
Copy link
Contributor

@upcFrost upcFrost commented Mar 8, 2020

Added a very simple redis.log Lua call support, wired to the standard python logging lib.

Issue #265

* Added redis.log function support, wired to the standard logging lib
@coveralls
Copy link

coveralls commented Mar 8, 2020

Coverage Status

Coverage increased (+0.07%) to 97.034% when pulling 759eab6 on upcFrost:master into fc07cf4 on jamesls:master.

2 similar comments
@coveralls
Copy link

Coverage Status

Coverage increased (+0.07%) to 97.034% when pulling 759eab6 on upcFrost:master into fc07cf4 on jamesls:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.07%) to 97.034% when pulling 759eab6 on upcFrost:master into fc07cf4 on jamesls:master.

@coveralls
Copy link

coveralls commented Mar 8, 2020

Coverage Status

Coverage increased (+0.02%) to 96.99% when pulling c95beb0 on upcFrost:master into fc07cf4 on jamesls:master.

Copy link
Collaborator

@bmerry bmerry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, looks like a solid start. I'd just like some extra handling of cases where the user uses it incorrectly.

fakeredis/_server.py Outdated Show resolved Hide resolved
fakeredis/_server.py Outdated Show resolved Hide resolved
test_fakeredis.py Outdated Show resolved Hide resolved
'INFO:%s:verbose' % logger.name,
'INFO:%s:notice' % logger.name,
'WARNING:%s:warning' % logger.name])

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add another test (or several) which makes malformed calls e.g.

  • Too many arguments
  • Too few arguments (or no arguments)
  • Message is not a string
  • Level is not redis.LOG_*

fakeredis/_server.py Outdated Show resolved Hide resolved
@upcFrost
Copy link
Contributor Author

Added tests and fixed multiarg calls and type conversion. Redis actually does some strange things with types. String, int and float are all converted to string, while boolean is just ignored.

0: logging.DEBUG,
1: logging.INFO,
2: logging.INFO,
3: logging.WARNING
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the double indirection because redis.LOG_DEBUG has the value 0 in real redis?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, and because user can actually use numbers instead of redis.LOG_* variables, just like in logging, but level values are different

msg = ' '.join([x.decode('utf-8')
if isinstance(x, bytes) else str(x)
for x in args if not isinstance(x, bool)])
LOGGER.log(REDIS_LOG_LEVELS_TO_LOGGING.get(lvl, logging.WARNING), msg)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it necessary to use get rather than just [], given that you've already checked that lvl is in REDIS_LOG_LEVELS.values()?

@@ -4178,6 +4178,45 @@ def test_lua_log(self):
'INFO:%s:notice' % logger.name,
'WARNING:%s:warning' % logger.name])

def test_lua_log_no_message(self):
if not isinstance(self.redis, (fakeredis.FakeRedis, fakeredis.FakeStrictRedis)):
pytest.skip("Works only on fakeredis, as testing real redis will require access to its logs")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this skip necessary? Won't real redis raise the same ResponseError? Same applies to the other tests that expect a ResponseError.


def test_lua_log_defined_vars(self):
if not isinstance(self.redis, (fakeredis.FakeRedis, fakeredis.FakeStrictRedis)):
pytest.skip("Works only on fakeredis, as testing real redis will require access to its logs")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this code gets copy-pasted, it would be nice if it could be wrapped up into a decorator (so that it's stylistically similar to @redis3_only for example).

Copy link
Collaborator

@bmerry bmerry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, looks good now! I'll try to get around to cutting a new release in the next week or so.

@bmerry bmerry merged commit 93e7f14 into jamesls:master Mar 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants