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

Logging config overwritten #85

Open
Fruchtzwerg94 opened this issue May 21, 2020 · 2 comments
Open

Logging config overwritten #85

Fruchtzwerg94 opened this issue May 21, 2020 · 2 comments

Comments

@Fruchtzwerg94
Copy link

overwrites an already set logging configuration if the module is imported afterwards. Whats the reason of this line of code here?

@ramezanifar
Copy link

ramezanifar commented Oct 8, 2020

To @Pithikos
I would like to thank you for this wonderful module. It is super easy to use. Really good job.
I also recommend allowing to pass a logger handle as an argument to the class for a custom configuration instead of logging.basicConfig().

To @Fruchtzwerg94
For me, it does not overwrite a custom configuration but it prints a message twice. To solve that issue I used:
logger.propagate = False

This is a simple sample :

import logging
from websocket_server import WebsocketServer

def new_client(client, server):
	server.send_message_to_all("Hey all, a new client has joined us")

#------------------------------------------------------------
# A custom logger
logger = logging.getLogger('my_custom_logger')
ch = logging.StreamHandler()
formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
ch.setFormatter(formatter)
logger.addHandler(ch)
logger.setLevel(logging.INFO)
logger.propagate = False  # Without this, the next message will be printed twice
#------------------------------------------------------------
logger.info("Ready to start the server")

server = WebsocketServer(13254, host='127.0.0.1', loglevel=logging.INFO)
server.set_fn_new_client(new_client)
server.run_forever()

@tysonite
Copy link

Yeah. Agree, nice module/library. It would be nice to fix global logging, though. Hopefully, someone can provide PR...

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