Skip to content

Commit

Permalink
add script with logging
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael J. Wilson committed Feb 2, 2024
1 parent 3158ea8 commit cc6efd0
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 14 deletions.
27 changes: 27 additions & 0 deletions python/foundation/scripts/logging.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[loggers]
keys=root,foundation

[handlers]
keys=consoleHandler

[formatters]
keys=simpleFormatter

[logger_root]
level=DEBUG
handlers=consoleHandler

[logger_foundation]
level=DEBUG
handlers=consoleHandler
qualname=foundation
propagate=0

[handler_consoleHandler]
class=StreamHandler
level=DEBUG
formatter=simpleFormatter
args=(sys.stdout,)

[formatter_simpleFormatter]
format=%(name)s @ %(asctime)s - %(levelname)s - %(message)s
21 changes: 21 additions & 0 deletions python/foundation/scripts/myapp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from __future__ import annotations

import logging
import logging.config

from foundation.tools import calculate_pi

logging.config.fileConfig("logging.conf")


logger = logging.getLogger("FOUNDATION")

pi = calculate_pi(6)

logger.debug("debug message")
logger.info("info message")
logger.warning("warn message")
logger.error("error message")
logger.critical("critical message")

logger.info("Found pi to be {pi}", extra={"pi": pi})
19 changes: 5 additions & 14 deletions python/foundation/tools.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,17 @@
from __future__ import annotations

import logging

from pysam import VariantFile

logger = logging.getLogger(__name__)


def calculate_pi(n: int) -> float:
"""
Basic calculation of pi
"""
result = 0.0

# Initialize denominator
k = 1

# Initialize sum
for i in range(1_000_000):
# even index elements are positive
if i % 2 == 0:
result += 4 / k
else:
# odd index elements are negative
result -= 4 / k
result = 3.14159265

return round(result, n)

Expand All @@ -32,7 +24,6 @@ def load_vcf(fpath: str) -> VariantFile:

for rec in vcf.fetch("chr1", 1_000_000, 1_200_000):
assert rec

break

return vcf
Expand Down

0 comments on commit cc6efd0

Please sign in to comment.