Skip to main content

GitHub GitHub Workflow Status (with branch) Coverage PyPI - Downloads

Introduction

This project provides easy to use wrapper around the Google Cloud Platform logging library to simplify creation of the traced logs.

Quick Start

from surquest.GCP.logger import Logger

logger = Logger()
logger.log(
    severity="INFO",
    msg="This is a test message",           # log message
    **{                                     # context information as KWARGS
        "key1": "value1",
        "key2": "value2"
    }
)

# Alternatively you can set the severity via the method name
logger.debug(msg="This is a DEBUG message")
logger.info(msg="This is a INFO message")
logger.warning(msg="This is a WARNING message")
logger.error(msg="This is a ERROR message")
logger.critical(msg="This is a CRITICAL message")

FastAPI integration

Following example shows how to integrate the Tracer class with FastAPI endpoints:

from surquest.GCP.logger import Logger
import requests
from fastapi import FastAPI, Depends, Query, Path

app = FastAPI()

@app.get("/exchange/currencies/{base}/{quote}")
async def exchange(
        base: str = Path(..., description="Base currency"),
        quote: str = Path(..., description="Quote currency"),
        amount: float = Query(..., gt=0, description="Amount to exchange"),
        logger: Logger = Depends(Logger)
):
    
    # get exchange rate from external API
    response = requests.get(
            f"https://api.exchangeratesapi.io/v1/latest?base={base}&symbols={quote}",
            params={
                "base": base,
                "symbols": quote,
                "access_key": "<your_api_key>" # please set your own API key
            }
        ).json()["rates"][quote]
    
    if 200 <= response.status_code < 300:
        
        exchange_rate = response.json()["rates"][quote]
        logger.info(
            msg="Retrieval of Exchange rates finished successfully",
            **{
                "currencies": {
                    "base": base,
                    "quote": quote
                },
                "exchangeRate": exchange_rate
            }
        )
        
    else:
        
        logger.error(
            msg="Failed to retrieve exchange rate",
            base=base,
            quote=quote,
            amount=amount,
            response=response
        )
        
        return {
            "info": "Failed to retrieve exchange rate",
            "error": response.text
        }
    
    result = amount * exchange_rate
        
    return {
        "currencies": {
            "base": base,
            "quote": quote
        },
        "amount": {
            "base": amount,
            "quote": result
        }
    }

Local development

You are more than welcome to contribute to this project. To make your start easier we have prepared a docker image with all the necessary tools to run it as interpreter for Pycharm or to run tests.

Build docker image

docker build `
     --tag surquest/gcp/logger `
     --file package.base.dockerfile `
     --target test .

Run tests

docker run --rm -it `
 -v "${pwd}:/opt/project" `
 -e "GOOGLE_APPLICATION_CREDENTIALS=/opt/project/credentials/keyfile.json" `
 -w "/opt/project/test" `
 surquest/gcp/logger pytest

Metadata

Release files for surquest-GCP-logger 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for surquest-GCP-logger 0.1.0
File Size Uploaded Provenance Actions
surquest_gcp_logger-0.1.0.tar.gz 8.5 kB Without provenance Details for surquest_gcp_logger-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for surquest-GCP-logger 0.1.0
File Interpreter ABI Platform Actions
surquest_gcp_logger-0.1.0-py2.py3-none-any.whl Python 3, Python 2 none any Details for surquest_gcp_logger-0.1.0-py2.py3-none-any.whl

Total release size: 14.1 kB

Release files / surquest_gcp_logger-0.1.0.tar.gz

Download URL surquest_gcp_logger-0.1.0.tar.gz
Size 8.5 kB
Tags Source
SHA-256 checksum
How to use checksums
f0a5affed49c9abc508e095c9ac5695af85aafca8671b27df25b6c0afab212f6
BLAKE2b-256 checksum
How to use checksums
2fac08c7cdcec713244b71a99af9f849ac59d4053c4b3bbf0164b8bd4c5a449a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.16

Release files / surquest_gcp_logger-0.1.0-py2.py3-none-any.whl

Download URL surquest_gcp_logger-0.1.0-py2.py3-none-any.whl
Size 5.6 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
162a186243d8f474311a5a31701dfaddd7bbaa3fa397b875c0d6b9e2eddee306
BLAKE2b-256 checksum
How to use checksums
c3893e134713f45f01cab956dafb4f53bd61557a82890c1673cfa11f36b1979c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.16

Security for surquest-GCP-logger 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page