From 9d261e6bd19b416d3d8e69ee82aef89ff2f04d88 Mon Sep 17 00:00:00 2001 From: Maya Date: Fri, 7 May 2021 11:55:26 +0300 Subject: [PATCH 1/3] Move migration logger initialization --- cvat/apps/engine/log.py | 12 ++++++++++++ cvat/apps/engine/migrations/0038_manifest.py | 20 +++++--------------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/cvat/apps/engine/log.py b/cvat/apps/engine/log.py index d8804e26cd4..a9aad9cb4b9 100644 --- a/cvat/apps/engine/log.py +++ b/cvat/apps/engine/log.py @@ -3,6 +3,7 @@ # SPDX-License-Identifier: MIT import logging +import sys from cvat.settings.base import LOGGING from .models import Job, Task, Project @@ -24,6 +25,17 @@ def _get_job(jid): except Exception: raise Exception('{} key must be a job identifier'.format(jid)) +def get_logger(logger_name, log_file): + logger = logging.getLogger(name=logger_name) + logger.setLevel(logging.INFO) + file_handler = logging.FileHandler(log_file) + formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') + file_handler.setFormatter(formatter) + logger.addHandler(file_handler) + logger.addHandler(logging.StreamHandler(sys.stdout)) + logger.addHandler(logging.StreamHandler(sys.stderr)) + return logger + class ProjectLoggerStorage: def __init__(self): self._storage = dict() diff --git a/cvat/apps/engine/migrations/0038_manifest.py b/cvat/apps/engine/migrations/0038_manifest.py index 05a5b11b0b8..b1ebd1e66c5 100644 --- a/cvat/apps/engine/migrations/0038_manifest.py +++ b/cvat/apps/engine/migrations/0038_manifest.py @@ -2,30 +2,20 @@ import glob import itertools -import logging import os -import sys from re import search from django.conf import settings from django.db import migrations +from cvat.apps.engine.log import get_logger from cvat.apps.engine.models import (DimensionType, StorageChoice, StorageMethodChoice) from cvat.apps.engine.media_extractors import get_mime from utils.dataset_manifest import ImageManifestManager, VideoManifestManager -def get_logger(): - migration = os.path.basename(__file__).split(".")[0] - logger = logging.getLogger(name=migration) - logger.setLevel(logging.INFO) - file_handler = logging.FileHandler(os.path.join(settings.MIGRATIONS_LOGS_ROOT, f"{migration}.log")) - formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') - file_handler.setFormatter(formatter) - logger.addHandler(file_handler) - logger.addHandler(logging.StreamHandler(sys.stdout)) - logger.addHandler(logging.StreamHandler(sys.stderr)) - return logger +MIGRATION_NAME = os.path.splitext(os.path.basename(__file__))[0] +MIGRATION_LOG = os.path.join(settings.MIGRATIONS_LOGS_ROOT, f"{MIGRATION_NAME}.log") def _get_query_set(apps): Data = apps.get_model("engine", "Data") @@ -33,7 +23,7 @@ def _get_query_set(apps): return query_set def migrate2meta(apps, shema_editor): - logger = get_logger() + logger = get_logger(MIGRATION_NAME, MIGRATION_LOG) query_set = _get_query_set(apps) for db_data in query_set: try: @@ -74,7 +64,7 @@ def migrate2meta(apps, shema_editor): logger.error(str(ex)) def migrate2manifest(apps, shema_editor): - logger = get_logger() + logger = get_logger(MIGRATION_NAME, MIGRATION_LOG) logger.info('The data migration has been started for creating manifest`s files') query_set = _get_query_set(apps) logger.info('Need to update {} data objects'.format(len(query_set))) From 94abf2017537210e853bf50c9218f0ce9ca4516c Mon Sep 17 00:00:00 2001 From: Maya Date: Fri, 7 May 2021 11:59:52 +0300 Subject: [PATCH 2/3] Update CHANGELOG --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 806d551c342..2477cc54a62 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,9 +14,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - A script to convert some kinds of DICOM files to regular images () - Helm chart prototype () - ### Changed +- Place of migration logger initialization () + ### Deprecated ### Removed From 94cc54caf8264e78546c51048edabab60e490353 Mon Sep 17 00:00:00 2001 From: Maya Date: Fri, 7 May 2021 12:04:44 +0300 Subject: [PATCH 3/3] Update license header --- cvat/apps/engine/log.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cvat/apps/engine/log.py b/cvat/apps/engine/log.py index a9aad9cb4b9..98d5c8e2e48 100644 --- a/cvat/apps/engine/log.py +++ b/cvat/apps/engine/log.py @@ -1,4 +1,4 @@ -# Copyright (C) 2018 Intel Corporation +# Copyright (C) 2018-2021 Intel Corporation # # SPDX-License-Identifier: MIT