How do I prevent a python server from writing to the terminal window?
I need to run a Python web server, while still taking inputs from the user, but when someone visits the website, the information logged to the terminal window is on the same line as the input, making it look like this:
I've tried setting the thread the the servers on to daemon mode, I've tried logging.getLogger("socketserver").setLevel(logging.CRITICAL)
, I've tried logger.propagation = False
, and logger.disable = True
This is my server code:
os.chdir("docs")
port = 8980
Handler = http.server.SimpleHTTPRequestHandler
with socketserver.TCPServer(("", port), Handler) as httpd:
httpd.serve_forever()
python logging webserver
add a comment |
I need to run a Python web server, while still taking inputs from the user, but when someone visits the website, the information logged to the terminal window is on the same line as the input, making it look like this:
I've tried setting the thread the the servers on to daemon mode, I've tried logging.getLogger("socketserver").setLevel(logging.CRITICAL)
, I've tried logger.propagation = False
, and logger.disable = True
This is my server code:
os.chdir("docs")
port = 8980
Handler = http.server.SimpleHTTPRequestHandler
with socketserver.TCPServer(("", port), Handler) as httpd:
httpd.serve_forever()
python logging webserver
add a comment |
I need to run a Python web server, while still taking inputs from the user, but when someone visits the website, the information logged to the terminal window is on the same line as the input, making it look like this:
I've tried setting the thread the the servers on to daemon mode, I've tried logging.getLogger("socketserver").setLevel(logging.CRITICAL)
, I've tried logger.propagation = False
, and logger.disable = True
This is my server code:
os.chdir("docs")
port = 8980
Handler = http.server.SimpleHTTPRequestHandler
with socketserver.TCPServer(("", port), Handler) as httpd:
httpd.serve_forever()
python logging webserver
I need to run a Python web server, while still taking inputs from the user, but when someone visits the website, the information logged to the terminal window is on the same line as the input, making it look like this:
I've tried setting the thread the the servers on to daemon mode, I've tried logging.getLogger("socketserver").setLevel(logging.CRITICAL)
, I've tried logger.propagation = False
, and logger.disable = True
This is my server code:
os.chdir("docs")
port = 8980
Handler = http.server.SimpleHTTPRequestHandler
with socketserver.TCPServer(("", port), Handler) as httpd:
httpd.serve_forever()
python logging webserver
python logging webserver
asked Nov 22 '18 at 1:48


F4TornadoF4Tornado
4817
4817
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
Subclass SimpleHTTPRequestHandler
and override the log_message
method to do nothing:
class QuietHandler(http.server.SimpleHTTPRequestHandler):
def log_message(self, format, *args):
pass
with socketserver.TCPServer(("", 8980), QuietHandler) as httpd:
httpd.serve_forever()
add a comment |
One thing you can try is piping the output into a file, if the file size ever becomes a concern I would try piping it to nul, like:
python3 myserver.py 2> nul
add a comment |
I wasn't quite clear if you wanted to remove the logging message on the command line, or redirect logging to file.
If you're wanting to redirect to file, you can use os.write to print to file.
If you're wanting to turn off the logging messages, and you can't get them off the command line, you could assign that logging to a nullHandler. Something a bit like:
noop = logging.NullHandler()
log.addHandler(noop)
# nothing happens here
log.info('message that will not be logged')
Using a nullHandler is a bit of a large solution, as the ideal would be to have logging going to a .log file for reference, not turning it off or skipping for certain messages.
It doesn't really matter where the message goes, just that it's not visible on the terminal windows.
– F4Tornado
Nov 23 '18 at 3:29
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53422825%2fhow-do-i-prevent-a-python-server-from-writing-to-the-terminal-window%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
Subclass SimpleHTTPRequestHandler
and override the log_message
method to do nothing:
class QuietHandler(http.server.SimpleHTTPRequestHandler):
def log_message(self, format, *args):
pass
with socketserver.TCPServer(("", 8980), QuietHandler) as httpd:
httpd.serve_forever()
add a comment |
Subclass SimpleHTTPRequestHandler
and override the log_message
method to do nothing:
class QuietHandler(http.server.SimpleHTTPRequestHandler):
def log_message(self, format, *args):
pass
with socketserver.TCPServer(("", 8980), QuietHandler) as httpd:
httpd.serve_forever()
add a comment |
Subclass SimpleHTTPRequestHandler
and override the log_message
method to do nothing:
class QuietHandler(http.server.SimpleHTTPRequestHandler):
def log_message(self, format, *args):
pass
with socketserver.TCPServer(("", 8980), QuietHandler) as httpd:
httpd.serve_forever()
Subclass SimpleHTTPRequestHandler
and override the log_message
method to do nothing:
class QuietHandler(http.server.SimpleHTTPRequestHandler):
def log_message(self, format, *args):
pass
with socketserver.TCPServer(("", 8980), QuietHandler) as httpd:
httpd.serve_forever()
answered Nov 22 '18 at 2:10


codycody
6,12621125
6,12621125
add a comment |
add a comment |
One thing you can try is piping the output into a file, if the file size ever becomes a concern I would try piping it to nul, like:
python3 myserver.py 2> nul
add a comment |
One thing you can try is piping the output into a file, if the file size ever becomes a concern I would try piping it to nul, like:
python3 myserver.py 2> nul
add a comment |
One thing you can try is piping the output into a file, if the file size ever becomes a concern I would try piping it to nul, like:
python3 myserver.py 2> nul
One thing you can try is piping the output into a file, if the file size ever becomes a concern I would try piping it to nul, like:
python3 myserver.py 2> nul
answered Nov 22 '18 at 1:55
user2704561user2704561
1815
1815
add a comment |
add a comment |
I wasn't quite clear if you wanted to remove the logging message on the command line, or redirect logging to file.
If you're wanting to redirect to file, you can use os.write to print to file.
If you're wanting to turn off the logging messages, and you can't get them off the command line, you could assign that logging to a nullHandler. Something a bit like:
noop = logging.NullHandler()
log.addHandler(noop)
# nothing happens here
log.info('message that will not be logged')
Using a nullHandler is a bit of a large solution, as the ideal would be to have logging going to a .log file for reference, not turning it off or skipping for certain messages.
It doesn't really matter where the message goes, just that it's not visible on the terminal windows.
– F4Tornado
Nov 23 '18 at 3:29
add a comment |
I wasn't quite clear if you wanted to remove the logging message on the command line, or redirect logging to file.
If you're wanting to redirect to file, you can use os.write to print to file.
If you're wanting to turn off the logging messages, and you can't get them off the command line, you could assign that logging to a nullHandler. Something a bit like:
noop = logging.NullHandler()
log.addHandler(noop)
# nothing happens here
log.info('message that will not be logged')
Using a nullHandler is a bit of a large solution, as the ideal would be to have logging going to a .log file for reference, not turning it off or skipping for certain messages.
It doesn't really matter where the message goes, just that it's not visible on the terminal windows.
– F4Tornado
Nov 23 '18 at 3:29
add a comment |
I wasn't quite clear if you wanted to remove the logging message on the command line, or redirect logging to file.
If you're wanting to redirect to file, you can use os.write to print to file.
If you're wanting to turn off the logging messages, and you can't get them off the command line, you could assign that logging to a nullHandler. Something a bit like:
noop = logging.NullHandler()
log.addHandler(noop)
# nothing happens here
log.info('message that will not be logged')
Using a nullHandler is a bit of a large solution, as the ideal would be to have logging going to a .log file for reference, not turning it off or skipping for certain messages.
I wasn't quite clear if you wanted to remove the logging message on the command line, or redirect logging to file.
If you're wanting to redirect to file, you can use os.write to print to file.
If you're wanting to turn off the logging messages, and you can't get them off the command line, you could assign that logging to a nullHandler. Something a bit like:
noop = logging.NullHandler()
log.addHandler(noop)
# nothing happens here
log.info('message that will not be logged')
Using a nullHandler is a bit of a large solution, as the ideal would be to have logging going to a .log file for reference, not turning it off or skipping for certain messages.
answered Nov 22 '18 at 2:16


scp31442scp31442
265
265
It doesn't really matter where the message goes, just that it's not visible on the terminal windows.
– F4Tornado
Nov 23 '18 at 3:29
add a comment |
It doesn't really matter where the message goes, just that it's not visible on the terminal windows.
– F4Tornado
Nov 23 '18 at 3:29
It doesn't really matter where the message goes, just that it's not visible on the terminal windows.
– F4Tornado
Nov 23 '18 at 3:29
It doesn't really matter where the message goes, just that it's not visible on the terminal windows.
– F4Tornado
Nov 23 '18 at 3:29
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53422825%2fhow-do-i-prevent-a-python-server-from-writing-to-the-terminal-window%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown