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

No support for format #51

Open
saadqc opened this issue Aug 20, 2018 · 6 comments
Open

No support for format #51

saadqc opened this issue Aug 20, 2018 · 6 comments

Comments

@saadqc
Copy link

saadqc commented Aug 20, 2018

I have a custom method to return logstash format. Although initializing it doesn't seem to work.

handler = CMRESHandler(hosts=[{'host': 'localhost', 'port': 9200}],
                               auth_type=CMRESHandler.AuthType.NO_AUTH,
                               es_index_name="my_logs")
handler.setFormatter(LogstashFormatterVersion1())

I noticed in emit method in handlers.py self.format(record) is being called but return dict is not stored anywhere.

@cmanaha
Copy link
Owner

cmanaha commented Sep 24, 2018

Thanks a lot for the feedback.

I'm not entirely sure why do you need a formatter for this handler in particular? Could you give more context of what are you trying to achieve so we get a better understanding ?

This handler is intended to pick up the full record (including the internal dict), serialise into a json doc and sent/store into elastic in bulk format.

Formatters (please read https://docs.python.org/3.5/library/logging.html#formatter-objects) for more reference are responsible for converting a LogRecord to a string (usually) which can be interpreted by either a human or an external system.

For the CMRESHandler, you do not need a formatter, the library will pick up the internal logrecord and inject directly into elastic.

@stephenpaulger
Copy link

@saadqc I'm not sure what your use case is but you may be able to use filters to achieve what you're trying to do while using this log handler.

https://docs.python.org/2/howto/logging-cookbook.html#filters-contextual

@saadqc
Copy link
Author

saadqc commented Dec 12, 2018

@stephenpaulger @cmanaha : I switched to a different package after struggling with this.

I will reproduce this issue and share my findings here. Otherwise close this PR.

Thanks

@stephenpaulger
Copy link

@saadqc Interested to hear what package you've switched to. I've had a different issue with this one when using ElasticSearch 6.5.

@saadqc
Copy link
Author

saadqc commented Dec 12, 2018

@stephenpaulger : it's python-logstash with python's default logging.

        fh = FileHandler(log_file_path)
        fh.setLevel(logging.INFO)
        fh.setFormatter(LogstashFormatterVersion1())

@michielvoo
Copy link

@cmanaha One use case for using a formatter is Elastic Common Schema. The official Python support for ECS in elastic/ecs-logging-python is implemented as a formatter.

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

No branches or pull requests

4 participants