|
4 | 4 | from logging.handlers import RotatingFileHandler |
5 | 5 | from os.path import expanduser |
6 | 6 |
|
7 | | -from superannotate.lib.core.config import Config |
8 | | -from superannotate.lib.core.enums import AnnotationStatus |
9 | | -from superannotate.lib.core.enums import ApprovalStatus |
10 | | -from superannotate.lib.core.enums import FolderStatus |
11 | | -from superannotate.lib.core.enums import ImageQuality |
12 | | -from superannotate.lib.core.enums import ProjectStatus |
13 | | -from superannotate.lib.core.enums import ProjectType |
14 | | -from superannotate.lib.core.enums import SegmentationStatus |
15 | | -from superannotate.lib.core.enums import TrainingStatus |
16 | | -from superannotate.lib.core.enums import UploadState |
17 | | -from superannotate.lib.core.enums import UserRole |
| 7 | +from lib.core.config import Config |
| 8 | +from lib.core.enums import AnnotationStatus |
| 9 | +from lib.core.enums import ApprovalStatus |
| 10 | +from lib.core.enums import FolderStatus |
| 11 | +from lib.core.enums import ImageQuality |
| 12 | +from lib.core.enums import ProjectStatus |
| 13 | +from lib.core.enums import ProjectType |
| 14 | +from lib.core.enums import SegmentationStatus |
| 15 | +from lib.core.enums import TrainingStatus |
| 16 | +from lib.core.enums import UploadState |
| 17 | +from lib.core.enums import UserRole |
| 18 | + |
18 | 19 |
|
19 | 20 | CONFIG = Config() |
| 21 | +BACKEND_URL = "https://api.superannotate.com" |
20 | 22 | HOME_PATH = expanduser("~/.superannotate") |
21 | 23 |
|
22 | 24 | CONFIG_JSON_PATH = f"{HOME_PATH}/config.json" |
|
32 | 34 |
|
33 | 35 | def setup_logging(level=DEFAULT_LOGGING_LEVEL, file_path=LOG_FILE_LOCATION): |
34 | 36 |
|
35 | | - global _loggers |
36 | | - if not _loggers.get("sa"): |
37 | | - logger = logging.getLogger("sa") |
38 | | - logger.propagate = True |
39 | | - logger.setLevel(level) |
40 | | - stream_handler = logging.StreamHandler() |
41 | | - formatter = Formatter("SA-PYTHON-SDK - %(levelname)s - %(message)s") |
42 | | - stream_handler.setFormatter(formatter) |
43 | | - logger.addHandler(stream_handler) |
44 | | - try: |
45 | | - log_file_path = os.path.join(file_path, "sa.log") |
46 | | - open(log_file_path, "w").close() |
47 | | - if os.access(log_file_path, os.W_OK): |
48 | | - file_handler = RotatingFileHandler( |
49 | | - log_file_path, |
50 | | - maxBytes=5 * 1024 * 1024, |
51 | | - backupCount=5, |
52 | | - mode="a", |
53 | | - ) |
54 | | - file_formatter = Formatter( |
55 | | - "SA-PYTHON-SDK - %(levelname)s - %(asctime)s - %(message)s" |
56 | | - ) |
57 | | - file_handler.setFormatter(file_formatter) |
58 | | - logger.addHandler(file_handler) |
59 | | - except OSError: |
60 | | - pass |
61 | | - finally: |
62 | | - _loggers["sa"] = logger |
| 37 | + logger = logging.getLogger("sa") |
| 38 | + for handler in logger.handlers[:]: # remove all old handlers |
| 39 | + logger.removeHandler(handler) |
| 40 | + logger.propagate = True |
| 41 | + logger.setLevel(level) |
| 42 | + stream_handler = logging.StreamHandler() |
| 43 | + formatter = Formatter("SA-PYTHON-SDK - %(levelname)s - %(message)s") |
| 44 | + stream_handler.setFormatter(formatter) |
| 45 | + logger.addHandler(stream_handler) |
| 46 | + try: |
| 47 | + log_file_path = os.path.join(file_path, "sa.log") |
| 48 | + open(log_file_path, "w").close() |
| 49 | + if os.access(log_file_path, os.W_OK): |
| 50 | + file_handler = RotatingFileHandler( |
| 51 | + log_file_path, |
| 52 | + maxBytes=5 * 1024 * 1024, |
| 53 | + backupCount=5, |
| 54 | + mode="a", |
| 55 | + ) |
| 56 | + file_formatter = Formatter( |
| 57 | + "SA-PYTHON-SDK - %(levelname)s - %(asctime)s - %(message)s" |
| 58 | + ) |
| 59 | + file_handler.setFormatter(file_formatter) |
| 60 | + logger.addHandler(file_handler) |
| 61 | + except OSError as e: |
| 62 | + logging.error(e) |
63 | 63 |
|
64 | 64 |
|
65 | | -BACKEND_URL = "https://api.superannotate.com" |
66 | | - |
67 | 65 | DEFAULT_IMAGE_EXTENSIONS = ["jpg", "jpeg", "png", "tif", "tiff", "webp", "bmp"] |
68 | 66 | DEFAULT_FILE_EXCLUDE_PATTERNS = ["___save.png", "___fuse.png"] |
69 | 67 | DEFAULT_VIDEO_EXTENSIONS = ["mp4", "avi", "mov", "webm", "flv", "mpg", "ogg"] |
|
0 commit comments