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

log formatting error with string and bytes concatenation #101

Open
ARashitov opened this issue May 5, 2022 · 2 comments
Open

log formatting error with string and bytes concatenation #101

ARashitov opened this issue May 5, 2022 · 2 comments

Comments

@ARashitov
Copy link

About

When I want to format logs I face error[Appendix A] telling that concatenate of str and bytes is impossible, but it works when I remove parameter: formatter=text in my log.ini file[Appendix B]

Appendix A | traceback

"Waiting for application startup."
--- Logging error ---
Traceback (most recent call last):
  File "/home/atmosphere/miniconda3/envs/research_elastic_search/lib/python3.10/logging/handlers.py", line 673, in emit
    s = self.makePickle(record)
  File "/home/atmosphere/miniconda3/envs/research_elastic_search/lib/python3.10/site-packages/logstash/handler_tcp.py", line 25, in makePickle
    return self.formatter.format(record) + b'\n'
TypeError: can only concatenate str (not "bytes") to str
Call stack:
  File "<string>", line 1, in <module>
  File "/home/atmosphere/miniconda3/envs/research_elastic_search/lib/python3.10/multiprocessing/spawn.py", line 116, in spawn_main
    exitcode = _main(fd, parent_sentinel)
  File "/home/atmosphere/miniconda3/envs/research_elastic_search/lib/python3.10/multiprocessing/spawn.py", line 129, in _main
    return self._bootstrap(parent_sentinel)
  File "/home/atmosphere/miniconda3/envs/research_elastic_search/lib/python3.10/multiprocessing/process.py", line 315, in _bootstrap
    self.run()
  File "/home/atmosphere/miniconda3/envs/research_elastic_search/lib/python3.10/multiprocessing/process.py", line 108, in run
    self._target(*self._args, **self._kwargs)
  File "/home/atmosphere/miniconda3/envs/research_elastic_search/lib/python3.10/site-packages/uvicorn/subprocess.py", line 76, in subprocess_started
    target(sockets=sockets)
  File "/home/atmosphere/miniconda3/envs/research_elastic_search/lib/python3.10/site-packages/uvicorn/server.py", line 60, in run
    return asyncio.run(self.serve(sockets=sockets))
  File "/home/atmosphere/miniconda3/envs/research_elastic_search/lib/python3.10/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/home/atmosphere/miniconda3/envs/research_elastic_search/lib/python3.10/asyncio/base_events.py", line 633, in run_until_complete
    self.run_forever()
  File "/home/atmosphere/miniconda3/envs/research_elastic_search/lib/python3.10/asyncio/base_events.py", line 600, in run_forever
    self._run_once()
  File "/home/atmosphere/miniconda3/envs/research_elastic_search/lib/python3.10/asyncio/base_events.py", line 1896, in _run_once
    handle._run()
  File "/home/atmosphere/miniconda3/envs/research_elastic_search/lib/python3.10/asyncio/events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "/home/atmosphere/miniconda3/envs/research_elastic_search/lib/python3.10/site-packages/uvicorn/server.py", line 77, in serve
    await self.startup(sockets=sockets)
  File "/home/atmosphere/miniconda3/envs/research_elastic_search/lib/python3.10/site-packages/uvicorn/server.py", line 88, in startup
    await self.lifespan.startup()
  File "/home/atmosphere/miniconda3/envs/research_elastic_search/lib/python3.10/site-packages/uvicorn/lifespan/on.py", line 45, in startup
    self.logger.info("Waiting for application startup.")

Appendix B | log.ini config file

[handler_logstash]
class=logstash.TCPLogstashHandler
level=INFO
formatter=text
args=('127.0.0.1', '8080', '1')

[formatter_text]
format="%(message)s"
datefmt='%d-%m-%Y %H:%M:%S'
@noahlz
Copy link

noahlz commented Nov 29, 2023

I am in fact facing the same issue. Thank you for posting this.

@manjurulhoque
Copy link

Had to write custom handler to fix this problem.

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

3 participants