Skip to content

Commit

Permalink
Add log entries for the application and CLI names
Browse files Browse the repository at this point in the history
Bump npg-python-lib from 0.3.1 to 0.3.3
  • Loading branch information
kjsanger committed Nov 4, 2024
1 parent fa063cd commit 9248ea7
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 2 deletions.
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."""
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

0 comments on commit 9248ea7

Please sign in to comment.