Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add log entries for the application and CLI names #386

Merged
merged 1 commit into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cryptography==43.0.3
npg_id_generation@https://github.com/wtsi-npg/npg_id_generation/releases/download/5.0.1/npg_id_generation-5.0.1.tar.gz
npg-python-lib@https://github.com/wtsi-npg/npg-python-lib/releases/download/0.3.1/npg_python_lib-0.3.1.tar.gz
npg-python-lib@https://github.com/wtsi-npg/npg-python-lib/releases/download/0.3.3/npg_python_lib-0.3.3.tar.gz
partisan@https://github.com/wtsi-npg/partisan/releases/download/2.13.0/partisan-2.13.0.tar.gz
pymysql==1.1.1
python-dateutil==2.9.0.post0
Expand Down
20 changes: 20 additions & 0 deletions src/npg_irods/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,30 @@


import importlib.metadata
import sys

import structlog

__version__ = importlib.metadata.version("npg-irods-python")


# If this proves generally useful, it could be moved to npg-python-lib
def add_appinfo_structlog_processor():
"""Add a custom structlog processor reporting executable information to the
configuration."""

def _add_executable_info(_logger, _method_name, event: dict):
"""Add executable name and version to all log entries."""
event["application"] = "npg-irods-python"
event["executable"] = sys.argv[0]
event["version"] = version()
return event

c = structlog.get_config()
c["processors"] = [_add_executable_info] + c["processors"]
structlog.configure(**c)


def version() -> str:
"""Return the current version."""
return __version__
19 changes: 19 additions & 0 deletions src/npg_irods/cli/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,20 @@
# -*- coding: utf-8 -*-
#
# Copyright © 2024 Genome Research Ltd. All rights reserved.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#


"""Command line interface for npg-irods-python."""
3 changes: 2 additions & 1 deletion src/npg_irods/cli/apply_ont_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from npg.log import configure_structlog
from sqlalchemy.orm import Session

from npg_irods import db, version
from npg_irods import add_appinfo_structlog_processor, db, version
from npg_irods.ont import apply_metadata

description = """
Expand Down Expand Up @@ -76,6 +76,7 @@
colour=args.colour,
json=args.json,
)
add_appinfo_structlog_processor()
log = structlog.get_logger("main")


Expand Down
3 changes: 2 additions & 1 deletion src/npg_irods/cli/check_checksums.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from npg.cli import add_io_arguments, add_logging_arguments
from npg.log import configure_structlog

from npg_irods import version
from npg_irods import add_appinfo_structlog_processor, version
from npg_irods.utilities import check_checksums

description = """
Expand Down Expand Up @@ -88,6 +88,7 @@
colour=args.colour,
json=args.json,
)
add_appinfo_structlog_processor()
log = structlog.get_logger("main")


Expand Down
3 changes: 2 additions & 1 deletion src/npg_irods/cli/check_common_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from npg.cli import add_io_arguments, add_logging_arguments
from npg.log import configure_structlog

from npg_irods import version
from npg_irods import add_appinfo_structlog_processor, version
from npg_irods.utilities import check_common_metadata

description = """
Expand Down Expand Up @@ -87,6 +87,7 @@
colour=args.colour,
json=args.json,
)
add_appinfo_structlog_processor()
log = structlog.get_logger("main")


Expand Down
3 changes: 2 additions & 1 deletion src/npg_irods/cli/check_consent_withdrawn.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from npg.cli import add_io_arguments, add_logging_arguments
from npg.log import configure_structlog

from npg_irods import version
from npg_irods import add_appinfo_structlog_processor, version
from npg_irods.utilities import (
check_consent_withdrawn,
)
Expand Down Expand Up @@ -84,6 +84,7 @@
colour=args.colour,
json=args.json,
)
add_appinfo_structlog_processor()
log = structlog.get_logger("main")


Expand Down
3 changes: 2 additions & 1 deletion src/npg_irods/cli/check_replicas.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from npg.cli import add_io_arguments, add_logging_arguments
from npg.log import configure_structlog

from npg_irods import version
from npg_irods import add_appinfo_structlog_processor, version
from npg_irods.utilities import check_replicas

description = """
Expand Down Expand Up @@ -96,6 +96,7 @@
colour=args.colour,
json=args.json,
)
add_appinfo_structlog_processor()
log = structlog.get_logger("main")


Expand Down
3 changes: 2 additions & 1 deletion src/npg_irods/cli/copy_confirm.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from npg.log import configure_structlog
from partisan.exception import RodsError

from npg_irods import version
from npg_irods import add_appinfo_structlog_processor, version
from npg_irods.common import rods_path
from npg_irods.exception import ChecksumError
from npg_irods.utilities import copy
Expand Down Expand Up @@ -95,6 +95,7 @@
colour=args.colour,
json=args.json,
)
add_appinfo_structlog_processor()
log = structlog.get_logger("main")


Expand Down
11 changes: 10 additions & 1 deletion src/npg_irods/cli/locate_data_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,15 @@
from partisan.irods import AVU, DataObject, RodsItem, query_metadata
from sqlalchemy.orm import Session

from npg_irods import db, illumina, ont, pacbio, sequenom, version
from npg_irods import (
add_appinfo_structlog_processor,
db,
illumina,
ont,
pacbio,
sequenom,
version,
)

from npg_irods.db.mlwh import (
find_consent_withdrawn_samples,
Expand Down Expand Up @@ -770,6 +778,7 @@ def main():
colour=args.colour,
json=args.json,
)
add_appinfo_structlog_processor()

args.func(args)

Expand Down
3 changes: 2 additions & 1 deletion src/npg_irods/cli/repair_checksums.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from npg.cli import add_io_arguments, add_logging_arguments
from npg.log import configure_structlog

from npg_irods import version
from npg_irods import add_appinfo_structlog_processor, version
from npg_irods.utilities import repair_checksums

description = """
Expand Down Expand Up @@ -93,6 +93,7 @@
colour=args.colour,
json=args.json,
)
add_appinfo_structlog_processor()
log = structlog.get_logger("main")


Expand Down
3 changes: 2 additions & 1 deletion src/npg_irods/cli/repair_common_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from npg.cli import add_io_arguments, add_logging_arguments
from npg.log import configure_structlog

from npg_irods import version
from npg_irods import add_appinfo_structlog_processor, version
from npg_irods.utilities import repair_common_metadata

description = """
Expand Down Expand Up @@ -90,6 +90,7 @@
colour=args.colour,
json=args.json,
)
add_appinfo_structlog_processor()
log = structlog.get_logger("main")


Expand Down
3 changes: 2 additions & 1 deletion src/npg_irods/cli/repair_replicas.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from npg.cli import add_io_arguments, add_logging_arguments
from npg.log import configure_structlog

from npg_irods import version
from npg_irods import add_appinfo_structlog_processor, version
from npg_irods.utilities import repair_replicas

description = """
Expand Down Expand Up @@ -92,6 +92,7 @@
colour=args.colour,
json=args.json,
)
add_appinfo_structlog_processor()
log = structlog.get_logger("main")


Expand Down
3 changes: 2 additions & 1 deletion src/npg_irods/cli/safe_remove_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from npg.cli import add_logging_arguments
from npg.log import configure_structlog

from npg_irods import version
from npg_irods import add_appinfo_structlog_processor, version
from npg_irods.utilities import write_safe_remove_script

description = """
Expand Down Expand Up @@ -84,6 +84,7 @@
colour=args.colour,
json=args.json,
)
add_appinfo_structlog_processor()
log = structlog.get_logger("main")


Expand Down
3 changes: 2 additions & 1 deletion src/npg_irods/cli/update_secondary_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from npg.conf import IniData
from npg.log import configure_structlog

from npg_irods import db, version
from npg_irods import add_appinfo_structlog_processor, db, version
from npg_irods.utilities import update_secondary_metadata

description = """
Expand Down Expand Up @@ -109,6 +109,7 @@ def main():
colour=args.colour,
json=args.json,
)
add_appinfo_structlog_processor()

dbconfig = IniData(db.Config).from_file(args.db_config.name, "mlwh_ro")
engine = sqlalchemy.create_engine(
Expand Down
3 changes: 2 additions & 1 deletion src/npg_irods/cli/withdraw_consent.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from npg.cli import add_logging_arguments
from npg.log import configure_structlog

from npg_irods import version
from npg_irods import add_appinfo_structlog_processor, version
from npg_irods.utilities import (
withdraw_consent,
)
Expand Down Expand Up @@ -89,6 +89,7 @@
colour=args.colour,
json=args.json,
)
add_appinfo_structlog_processor()
log = structlog.get_logger("main")


Expand Down
3 changes: 2 additions & 1 deletion src/npg_irods/cli/write_html_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from partisan.exception import RodsError
from yattag import indent

from npg_irods import version
from npg_irods import add_appinfo_structlog_processor, version
from npg_irods.html_reports import ont_runs_html_report_this_year

description = """Writes an HTML report summarising data in iRODS.
Expand Down Expand Up @@ -80,6 +80,7 @@
colour=args.colour,
json=args.json,
)
add_appinfo_structlog_processor()
log = structlog.get_logger("main")


Expand Down