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

Add option for logger not to print to console #13

Closed
fractaledmind opened this issue Jul 15, 2014 · 1 comment
Closed

Add option for logger not to print to console #13

fractaledmind opened this issue Jul 15, 2014 · 1 comment

Comments

@fractaledmind
Copy link
Contributor

In building my next workflow, I've implemented the caching functionality of alfred-workflow; however, this also means that every time I run test code from Sublime that uses caching, all the data I'm printing for my benefit is trapped and clustered within every call that alfred-workflow makes to the cache. I love the robust logging of what's happing in the script, and it's great for debug another user's problems (open the log and send me the output), but I really need a way to shut off the console printing when I'm building.

I tried to comment out these lines in the @property logger(self) code:

console = logging.StreamHandler()
...
console.setFormatter(fmt)
...
logger.addHandler(console)

However, this shut down all console printing (aside from direct print commands). So when an error would occur, it wouldn't print the full Python error report.

So, how can I tell alfred-workflow not to print its logs, but still ensure that Python is printing its logs to the console?

@deanishe
Copy link
Owner

I'm afraid I don't really understand exactly what you're trying to achieve. At any rate, you shouldn't be messing with the code in workflow.py to alter logging behaviour: that isn't how Python's logging library works.

If you want to reduce/turn off logging from a Workflow instance, do wf.logger.setLevel(logging.INFO) (or logging.WARNING/logging.ERROR etc.), or straight up delete the existing handlers and replace them with a NullHandler.

So, how can I tell alfred-workflow not to print its logs, but still ensure that Python is printing its logs to the console?

"Python" does not print logs to the console or anywhere else. Only configured loggers do. You should probably read the logging tutorial, but basically you want to configure your own logger instance (in an entirely different namespace) and use that while telling Workflow.logger to be quiet (as described above).

While I'm not entirely sure what the problem is, I strongly suspect it stems from a lack of familiarity with the logging library and not from anything that Alfred-Workflow should be doing differently (it restricts its own logging to the workflow namespace).

If you need any advice, feel free to ask me via a PM on the Alfred forum.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants