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

Disable colors when logging to a file and running outside Docker #458

Open
mejroslav opened this issue Jul 27, 2023 · 3 comments
Open

Disable colors when logging to a file and running outside Docker #458

mejroslav opened this issue Jul 27, 2023 · 3 comments
Labels
bug Something isn't working

Comments

@mejroslav
Copy link
Contributor

mejroslav commented Jul 27, 2023

Logging to a file when running outside Docker

I found this issue when experimenting with logging to a file using the configuration from documentation:

When logging to a file outside Docker (running the app directly), escape color sequences are present. I tried to explicitly use the optionuse_colors=False here:

asab/asab/log.py

Lines 56 to 60 in 7c76f10

self.FileHandler.setFormatter(StructuredDataFormatter(
fmt=Config["logging:file"]["format"],
datefmt=Config["logging:file"]["datefmt"],
sd_id=Config["logging"]["sd_id"],
))

...but that didn't help.


The config:

[logging:file]
path=./output.log
format=%(asctime)s %(levelname)s %(name)s %(struct_data)s%(message)s,
datefmt=%d-%b-%Y %H:%M:%S.%f
backup_count=3
rotate_every=1d

The app:

#!/usr/bin/env python3
import logging
import asab

L = logging.getLogger(__name__)


class MyApplication(asab.Application):
	async def main(self):
		a, b = 24, 0
		try:
			print(a / b)
		except ZeroDivisionError:
			L.error("Division by zero.", struct_data={"a": a, "b": b})

		self.stop()


if __name__ == "__main__":
	app = MyApplication()
	app.run()

Output:

27-Jul-2023 17:18:39.572756 �[1;36mNOTICE�[0m asab.application is ready.,
27-Jul-2023 17:18:39.572942 �[1;31mERROR�[0m __main__ [sd a="24" b="0"] Division by zero.,
27-Jul-2023 17:18:39.572948 �[1;31mERROR�[0m root Invalid 'rotate_every' configuration value.,
27-Jul-2023 17:18:39.573116 �[1;36mNOTICE�[0m asab.application [sd exit_code="0"] is exiting ...,
@mejroslav mejroslav added the bug Something isn't working label Jul 27, 2023
@ateska
Copy link
Contributor

ateska commented Jul 28, 2023

Can you split this into two issues?

@mejroslav mejroslav changed the title Logging to a file when running outside Docker Disable colors when logging to a file and running outside Docker Aug 8, 2023
@ateska
Copy link
Contributor

ateska commented Sep 29, 2023

Is this solved by #361 ?

If yes, then close this one, please. @mejroslav

@mejroslav
Copy link
Contributor Author

Sorry for the late response, @ateska. Unfortunately, it is not. The color escape sequence is still there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants