473,320 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How to disable console display while enabling logging to a file.

I have the following code in a module that I want to call from any other application module.
The code I have also displays the debug message on the console when I invoke it like this:
def main():
logger = custom_logger('test1', 'log', 'test.log', False)
logger.debug('log to file only')

Not sure how to turn off the console.
Any thoughts?
Thanks.

custom_logger(logdir, logfile, logname, logconsole)
logger = logging.getLogger(logname)

formatter = logging.Formatter(fmt='%(asctime)s [%(name)-2s] %(message)s', datefmt='%Y-%m-%d %H:%M:%S')

rotatingfilehandler = RotatingFileHandler(logdir+'/'+logfile,
maxBytes=MAX_LOGSIZE,
backupCount=MAX_ROTATE_LOGS)
rotatingfilehandler.setFormatter(formatter)
logger.addHandler(rotatingfilehandler)

screen_handler = logging.StreamHandler(stream=sys.stdout)
screen_handler.setFormatter(formatter)

if logconsole:
logger.addHandler(screen_handler)
else:
logger.removeHandler(screen_handler)

return logger
Aug 7 '19 #1
0 1105

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Victor | last post by:
Hi I need to open an html file from the file system and embed that html file within my main aspx form. I have 2 questions: 1) How do I open the html file? I tried the File.open(Path, mode) didnt...
3
by: jiayanxiang | last post by:
Is there any sample code to use Javascript to load and display a text file? It will be best if the user can select files using some kind of explorer. If that's complex, a text box to specify the...
3
by: Chris Saunders | last post by:
May be a dumb question but I have been unable to find the answer on my own. I wish to display a help file (*.chm) can anyone help? I attempted using "displaying help file" as a search in MSDN but...
3
by: johnny | last post by:
How do I pipe the output, generated from os.system(some_command), to the logging file?
11
by: nickyeng | last post by:
I have a html file contains a form asking user to select a choice and press enter to pass the data to server. In server there, i have a cgi script(C language) that accepts the input from browser...
1
by: 848lu | last post by:
PHP - display from txt file with explode function hi, i am trying to display all data from a txt file with a function of explode but does not work..... <? #reads a text file outputs it to...
9
by: tomhawkins1 | last post by:
Hi I currently have a site where users can upload files. These files can be doc, wmv, jpeg, xls, dwf, dwf and dwg. These files are uploaded to /home/**user**/uploads and not /home/...
3
by: =?Utf-8?B?QmlsbHkgWmhhbmc=?= | last post by:
I have a asp.net app, in the page there is a scan activex which could scan and save a jpg file in client harddisk. How could we access and display this jpg file on the fly using js in the client...
4
by: kkshansid | last post by:
what is the best way to display a word file on a php page in the same format as it is on word format ? word file has some very well diplay of data in tabular format php page has includes...
2
by: harika143 | last post by:
in console loggers are not printing. can any body tell me the reason. i set the classpath for log4j.jar are log4j.xml. but i am not getting.
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.