-
Notifications
You must be signed in to change notification settings - Fork 578
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test for cog stream draining file logging
* This tests exposes the issue that cog stream drainer can’t drain due to file logging in the logging module.
- Loading branch information
Showing
3 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
5 changes: 5 additions & 0 deletions
5
test-integration/test_integration/fixtures/file-logging-stream-drain-project/cog.yaml
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
build: | ||
python_version: "3.11" | ||
python_packages: | ||
- "pillow==8.3.2" | ||
predict: "predict.py:Predictor" |
22 changes: 22 additions & 0 deletions
22
test-integration/test_integration/fixtures/file-logging-stream-drain-project/predict.py
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from cog import BasePredictor, File | ||
import logging | ||
import os | ||
from PIL import Image | ||
|
||
|
||
class Predictor(BasePredictor): | ||
def setup(self): | ||
logFormatter = logging.Formatter("%(asctime)s [%(threadName)-12.12s] [%(levelname)-5.5s] %(message)s") | ||
rootLogger = logging.getLogger() | ||
|
||
fileHandler = logging.FileHandler("{0}/{1}.log".format(os.path.dirname(__file__), "mylog.log")) | ||
fileHandler.setFormatter(logFormatter) | ||
rootLogger.addHandler(fileHandler) | ||
|
||
consoleHandler = logging.StreamHandler() | ||
consoleHandler.setFormatter(logFormatter) | ||
rootLogger.addHandler(consoleHandler) | ||
|
||
def predict(self) -> list[Image]: | ||
logging.info("Do some logging.") | ||
return [] |
This file contains 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