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

Custom message in logging queries #285

Closed
Marlysson opened this issue Jan 2, 2021 · 9 comments
Closed

Custom message in logging queries #285

Marlysson opened this issue Jan 2, 2021 · 9 comments
Labels
enhancement A feature that exists, works as intended but needs to be improved

Comments

@Marlysson
Copy link
Contributor

Define a custom messsage to logging queries.

formatter = logging.Formatter('%(asctime)-15s - %(module)s - %(process)d - %(thread)d- %(levelname)s - %(message)s')
I can't find relevant documents and cases
@josephmancuso
Copy link
Member

@Marlysson
Copy link
Contributor Author

@josephmancuso Can we change the current default message that are being used inside code?

@josephmancuso
Copy link
Member

which one?

@josephmancuso
Copy link
Member

josephmancuso commented Jan 2, 2021

if you mean the one that is printing out in the connection classes, that really shouldn't be there. I just put that there for now so I can easily debug things as we test it

@Marlysson
Copy link
Contributor Author

Marlysson commented Jan 2, 2021

Yep, that one! Then the message putted in formatter should be cascade until base code...
I will take a look that!

@josephmancuso
Copy link
Member

yeah the one printing will be removed soon. You can look into adding some more options to the formatter tho. I think currently it only does query and query time

@Marlysson
Copy link
Contributor Author

Marlysson commented Jan 2, 2021

@josephmancuso What do you think of this, change the "format" of define logging to encapsulate all of initial configs:

from:

logger = logging.getLogger('masoniteorm.connection.queries')
logger.setLevel(logging.DEBUG)

formatter = logging.Formatter(
    'It executed the query %(query)s'
)

stream_handler = logging.StreamHandler()
file_handler   = logging.FileHandler("queries.log")

logger.addHandler(stream_handler)
logger.addHandler(file_handler)

to:

...
formatter = "It executed the query %(query)s" # Message with more placeholders
handlers = [logging.StreamHandler(), logging.FileHandler("queries.log")]

logger = Logger.configure(formatter, handlers=handlers)

@josephmancuso
Copy link
Member

yeah that's fine

@Marlysson
Copy link
Contributor Author

Marlysson commented Jan 2, 2021

@josephmancuso this logger to logging queries will be used to all types of infos or just sql queries?

Ask this because if to just sql query just need the "info" level of log, if not, then I need create other levels.

I'll open the PR to analysis.

@josephmancuso josephmancuso added the enhancement A feature that exists, works as intended but needs to be improved label Jan 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement A feature that exists, works as intended but needs to be improved
Projects
None yet
Development

No branches or pull requests

2 participants