Skip to content

Commit

Permalink
Use Local Loggers (#256)
Browse files Browse the repository at this point in the history
* Use Local Loggers

* remove hardcoded loggers

* set first party logger by `__name__`

* add missing logger

* remove unneeded `if-main` blocks

* restore `if-main` block for testing

* test formatting

* pt-2

* pt-3

* pt-4

* remove `hostname`

* format time

* set handler after

* move back, remove line numbers

* remove `coloredlogs` dep

* <bot> update dependencies*.log files(s)

---------

Co-authored-by: wipacdevbot <[email protected]>
  • Loading branch information
ric-evans and wipacdevbot authored Dec 22, 2023
1 parent fd1a0b7 commit 3750d16
Show file tree
Hide file tree
Showing 19 changed files with 84 additions and 100 deletions.
4 changes: 0 additions & 4 deletions dependencies-from-Dockerfile.log
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ cffi==1.15.0
chardet==4.0.0
click==8.0.3
colorama==0.4.4
coloredlogs==15.0.1
configobj==5.0.6
cov-core==1.15.0
coverage==6.2
Expand All @@ -42,7 +41,6 @@ healpy==1.15.0
htchirp==3.0
htcondor==23.2.0
html5lib==1.1
humanfriendly==10.0
hypothesis==6.36.0
icecube-skyreader==1.2.8
idna==3.3
Expand Down Expand Up @@ -174,8 +172,6 @@ cffi==1.15.0
chardet==4.0.0
click==8.0.3
colorama==0.4.4
coloredlogs==15.0.1
└── humanfriendly [required: >=9.1, installed: 10.0]
configobj==5.0.6
cov-core==1.15.0
coverage==6.2
Expand Down
4 changes: 0 additions & 4 deletions dependencies-from-Dockerfile_no_cvmfs.log
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ cffi==1.15.0
chardet==4.0.0
click==8.0.3
colorama==0.4.4
coloredlogs==15.0.1
configobj==5.0.6
cov-core==1.15.0
coverage==6.2
Expand All @@ -42,7 +41,6 @@ healpy==1.15.0
htchirp==3.0
htcondor==23.2.0
html5lib==1.1
humanfriendly==10.0
hypothesis==6.36.0
icecube-skyreader==1.2.8
idna==3.3
Expand Down Expand Up @@ -174,8 +172,6 @@ cffi==1.15.0
chardet==4.0.0
click==8.0.3
colorama==0.4.4
coloredlogs==15.0.1
└── humanfriendly [required: >=9.1, installed: 10.0]
configobj==5.0.6
cov-core==1.15.0
coverage==6.2
Expand Down
4 changes: 0 additions & 4 deletions dependencies-from-Dockerfile_pulsar.log
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ cffi==1.15.0
chardet==4.0.0
click==8.0.3
colorama==0.4.4
coloredlogs==15.0.1
configobj==5.0.6
cov-core==1.15.0
coverage==6.2
Expand All @@ -42,7 +41,6 @@ healpy==1.15.0
htchirp==3.0
htcondor==23.2.0
html5lib==1.1
humanfriendly==10.0
hypothesis==6.36.0
icecube-skyreader==1.2.8
idna==3.3
Expand Down Expand Up @@ -174,8 +172,6 @@ cffi==1.15.0
chardet==4.0.0
click==8.0.3
colorama==0.4.4
coloredlogs==15.0.1
└── humanfriendly [required: >=9.1, installed: 10.0]
configobj==5.0.6
cov-core==1.15.0
coverage==6.2
Expand Down
7 changes: 2 additions & 5 deletions skymap_scanner/client/client.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""The Client service."""


import argparse
import asyncio
import json
Expand All @@ -11,7 +12,7 @@

from .. import config as cfg

LOGGER = logging.getLogger("skyscan.client")
LOGGER = logging.getLogger(__name__)


def main() -> None:
Expand Down Expand Up @@ -92,7 +93,3 @@ def main() -> None:
)
)
LOGGER.info("Done.")


if __name__ == "__main__":
main()
4 changes: 3 additions & 1 deletion skymap_scanner/client/reco_icetray.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Reco a single pixel."""


# pylint: skip-file

import argparse
Expand Down Expand Up @@ -30,7 +31,7 @@
from ..utils.pixel_classes import RecoPixelVariation, pframe_tuple
from ..utils.utils import save_GCD_frame_packet_to_file

LOGGER = logging.getLogger("skyscan.client.reco")
LOGGER = logging.getLogger(__name__)


def frame_for_logging(frame: icetray.I3Frame) -> str:
Expand Down Expand Up @@ -294,5 +295,6 @@ def main() -> None:
LOGGER.info("Done reco'ing pixel.")


# This entrypoint is only used in CI testing
if __name__ == "__main__":
main()
13 changes: 11 additions & 2 deletions skymap_scanner/config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""Configuration constants."""


import dataclasses as dc
import logging
from pathlib import Path
from typing import Final, List

Expand Down Expand Up @@ -147,11 +149,18 @@ def __post_init__(self) -> None:

def configure_loggers() -> None:
"""Set up loggers with common configurations."""
hand = logging.StreamHandler()
hand.setFormatter(
logging.Formatter(
"%(asctime)s.%(msecs)03d [%(levelname)8s] %(name)s[%(process)d] %(message)s",
datefmt="%Y-%m-%d %H:%M:%S",
)
)
logging.getLogger().addHandler(hand)
logging_tools.set_level(
ENV.SKYSCAN_LOG, # type: ignore[arg-type]
first_party_loggers="skyscan",
first_party_loggers=__name__.split(".", maxsplit=1)[0],
third_party_level=ENV.SKYSCAN_LOG_THIRD_PARTY, # type: ignore[arg-type]
use_coloredlogs=True,
future_third_parties=["google", "pika"],
specialty_loggers={
ewms_pilot.pilot.LOGGER: ENV.SKYSCAN_EWMS_PILOT_LOG, # type: ignore[attr-defined, dict-item]
Expand Down
6 changes: 0 additions & 6 deletions skymap_scanner/server/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +0,0 @@
"""Init."""


import logging

LOGGER = logging.getLogger("skyscan.server")
5 changes: 4 additions & 1 deletion skymap_scanner/server/collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


import itertools
import logging
import time
from bisect import bisect
from typing import Any, Dict, List, Optional, Set, Tuple
Expand All @@ -16,9 +17,11 @@
RecoPixelVariation,
SentPixelVariation,
)
from . import LOGGER
from .reporter import Reporter

LOGGER = logging.getLogger(__name__)


StrDict = Dict[str, Any]


Expand Down
9 changes: 6 additions & 3 deletions skymap_scanner/server/pixels.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
"""Tools for picking pixels to scan."""


# fmt: off
# pylint: skip-file

import logging
from typing import List, Optional, Set, Tuple

import healpy # type: ignore[import]
import healpy # type: ignore[import-untyped]
import numpy
from icecube import icetray # type: ignore[import]
from icecube import icetray # type: ignore[import-not-found]

from ..utils.pixel_classes import NSidesDict
from . import LOGGER
from .utils import NSideProgression

LOGGER = logging.getLogger(__name__)


def __healpix_pixel_upgrade(nside, pix) -> list:
pix_nested = healpy.ring2nest(nside, pix)
Expand Down
6 changes: 3 additions & 3 deletions skymap_scanner/server/reporter.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
"""Contains a class for reporting progress and result for a scan."""

# pylint: disable=import-error


import bisect
import dataclasses as dc
import datetime as dt
import itertools
import json
import logging
import math
import statistics
import time
Expand All @@ -21,9 +20,10 @@
from ..utils import to_skyscan_result
from ..utils.pixel_classes import NSidesDict
from ..utils.utils import pyobj_to_string_repr
from . import LOGGER
from .utils import NSideProgression, connect_to_skydriver, nonurgent_request

LOGGER = logging.getLogger(__name__)

StrDict = Dict[str, Any]


Expand Down
11 changes: 5 additions & 6 deletions skymap_scanner/server/start_scan.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""The Skymap Scanner Server."""


# pylint: disable=invalid-name,import-error
# fmt:quotes-ok

Expand Down Expand Up @@ -36,7 +37,6 @@
SentPixelVariation,
pframe_tuple,
)
from . import LOGGER
from .collector import Collector, ExtraRecoPixelVariationException
from .pixels import choose_pixels_to_reconstruct
from .reporter import Reporter
Expand All @@ -47,6 +47,9 @@
kill_switch_check_from_skydriver,
)

LOGGER = logging.getLogger(__name__)


StrDict = Dict[str, Any]


Expand Down Expand Up @@ -472,7 +475,7 @@ async def _serve_and_collect(
msg["reco_pixel_variation"], msg["runtime"]
)
except ExtraRecoPixelVariationException as e:
logging.error(e)
LOGGER.error(e)

# if we've got enough pixfins, let's get a jump on the next round
if max_nside_thresholded := collector.get_max_nside_thresholded():
Expand Down Expand Up @@ -747,7 +750,3 @@ def _nside_and_pixelextension(val: str) -> Tuple[int, int]:
)
)
LOGGER.info("Done.")


if __name__ == "__main__":
main()
3 changes: 2 additions & 1 deletion skymap_scanner/server/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
from rest_tools.client import CalcRetryFromWaittimeMax, RestClient

from .. import config as cfg
from . import LOGGER

LOGGER = logging.getLogger(__name__)


def connect_to_skydriver(urgent: bool) -> RestClient:
Expand Down
6 changes: 0 additions & 6 deletions skymap_scanner/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +0,0 @@
"""Init."""


import logging

LOGGER = logging.getLogger("skyscan.utils")
13 changes: 9 additions & 4 deletions skymap_scanner/utils/data_handling.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
from .. import config as cfg # type: ignore[import]
from pathlib import Path
"""data_handling.py."""


import logging
import subprocess
from typing import Dict, List, Union
from pathlib import Path
from typing import List

from .. import config as cfg

from . import LOGGER
LOGGER = logging.getLogger(__name__)


class DataStager:
Expand Down
7 changes: 5 additions & 2 deletions skymap_scanner/utils/extract_json_message.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
"""Tools for extracting json messages."""


# fmt: off
# pylint: skip-file

import json
import logging
import os
from typing import Tuple

from icecube import full_event_followup, icetray # type: ignore[import]
from icecube import full_event_followup, icetray # type: ignore[import-not-found]
from skyreader import EventMetadata

from .. import config as cfg
from . import LOGGER
from .load_scan_state import load_scan_state
from .prepare_frames import prepare_frames
from .utils import (
Expand All @@ -22,6 +23,8 @@
save_GCD_frame_packet_to_file,
)

LOGGER = logging.getLogger(__name__)


def extract_GCD_diff_base_filename(frame_packet):
# check the base filename (it should be the same for all "Diff" objects)
Expand Down
34 changes: 5 additions & 29 deletions skymap_scanner/utils/load_scan_state.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
"""Tools for loading the scan state."""


# fmt: off
# mypy: ignore-errors
# pylint: skip-file

import logging
import os
from typing import List

from icecube import icetray
from icecube import icetray # type: ignore[import-not-found]
from skyreader import EventMetadata

from .. import config as cfg
from . import LOGGER
from .pixel_classes import RecoPixelFinal, RecoPixelVariation
from .utils import hash_frame_packet, load_framepacket_from_file

LOGGER = logging.getLogger(__name__)


def load_cache_state(
event_metadata: EventMetadata,
Expand Down Expand Up @@ -179,29 +181,3 @@ def load_GCDQp_state(event_metadata: EventMetadata, cache_dir="./cache/") -> dic
cfg.STATEDICT_GCDQP_PACKET: frame_packet,
cfg.STATEDICT_BASELINE_GCD_FILE: source_baseline_GCD,
}


if __name__ == "__main__":
from optparse import OptionParser

parser = OptionParser()
usage = """%prog [options]"""
parser.set_usage(usage)
parser.add_option("-c", "--cache-dir", action="store", type="string",
default="./cache/", dest="CACHEDIR", help="The cache directory to use")

# get parsed args
(options,args) = parser.parse_args()

if len(args) != 1:
raise RuntimeError("You need to specify exatcly one event ID")
eventID = args[0]

# do the work
packets = load_cache_state(
eventID,
args.reco_algo, # TODO: add --reco-algo (see start_scan.py)
cache_dir=options.CACHEDIR
)

print(("got:", packets))
Loading

0 comments on commit 3750d16

Please sign in to comment.