Created
April 8, 2020 14:13
-
-
Save Preston-Landers/4a7868e465499f7fc99186ab10ad803c to your computer and use it in GitHub Desktop.
Test of concurrent-log-handler issue 24
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging | |
from concurrent.futures.process import ProcessPoolExecutor | |
from concurrent_log_handler import ConcurrentRotatingFileHandler | |
class Foo(): | |
def func(self, *args): | |
print("Called func") | |
logger.info("Foo says: %r", *args) | |
def get_logger(loggerFilename): | |
logger = logging.getLogger() | |
rotateHandler = ConcurrentRotatingFileHandler(loggerFilename, "a", 512 * 1024, 100) | |
# format of the log | |
formatter = logging.Formatter( | |
"%(asctime)s %(process)d %(funcName)16s %(levelname)8s %(message)s") | |
rotateHandler.setFormatter(formatter) | |
logger.addHandler(rotateHandler) | |
# mode of the log | |
logger.setLevel(logging.INFO) | |
return logger | |
loggerFilename = "c:/temp/testlog.log" | |
logger = get_logger(loggerFilename) | |
if __name__ == "__main__": | |
c1 = Foo() | |
c2 = Foo() | |
print("Starting") | |
with ProcessPoolExecutor(max_workers=6) as executor: | |
executor.submit(c1.func, (1, 2, 3)) | |
executor.submit(c2.func, (4, 5, 6)) | |
print("Done") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment