Skip to content

Commit

Permalink
Update logging support
Browse files Browse the repository at this point in the history
Now use logging.conf file found next to the distrubuted executable. Currently
configured to rotatinffilehandler with 10mb cut off. If no logging.conf file
is found it defaults to previous basic logger.
Also fix names of all module level loggers.
Now users can turn off DEBUG level logging to save space.
  • Loading branch information
cwhelchel committed Oct 29, 2024
1 parent 0edbe2f commit 00ac96a
Show file tree
Hide file tree
Showing 16 changed files with 84 additions and 18 deletions.
5 changes: 5 additions & 0 deletions build-linux.spec
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,8 @@ exe = EXE(pyz,
target_arch=None,
codesign_identity=None,
entitlements_file=None )


import shutil

shutil.copyfile('logging.conf', '{0}/logging.conf'.format(DISTPATH))
5 changes: 5 additions & 0 deletions build-windows.spec
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,8 @@ exe = EXE(pyz,
target_arch=None,
codesign_identity=None,
entitlements_file=None )


import shutil

shutil.copyfile('logging.conf', '{0}/logging.conf'.format(DISTPATH))
35 changes: 35 additions & 0 deletions logging.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
[loggers]
keys=root

[logger_root]
handlers=file
level=DEBUG

[formatters]
keys=simple

[formatter_simple]
format=%(asctime)s = %(levelname)-7.7s [%(name)s]: %(message)s

[handlers]
keys=file,screen

# [handler_file]
# class=FileHandler
# encoding='utf-8'
# formatter=simple
# level=DEBUG
# args=('index.log',)

[handler_file]
class=handlers.RotatingFileHandler
encoding='utf-8'
formatter=simple
level=DEBUG
args=('index.log', 'a', 10000000, 0, 'utf-8')

[handler_screen]
class=StreamHandler
formatter=simple
level=INFO
args=(sys.stdout,)
2 changes: 1 addition & 1 deletion src/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from cat import CAT
from utils.distance import Distance

logging = L.getLogger("api")
logging = L.getLogger(__name__)
# IDTOKENPAT = r"^.*CognitoIdentityServiceProvider\..+\.idToken=([\w\.-]*\;)"


Expand Down
2 changes: 1 addition & 1 deletion src/bands.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from enum import Enum
import logging as L
logging = L.getLogger("bands")
logging = L.getLogger(__name__)


class Bands(Enum):
Expand Down
2 changes: 1 addition & 1 deletion src/cat/cat_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
if __name__ == "__main__":
print("I'm not the program you are looking for.")

logger = logging.getLogger("cat")
logger = logging.getLogger(__name__)


class CAT:
Expand Down
2 changes: 1 addition & 1 deletion src/db/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

Base = declarative_base()

logging = L.getLogger("db")
logging = L.getLogger(__name__)
# show sql
# L.getLogger('sqlalchemy.engine').setLevel(L.INFO)

Expand Down
2 changes: 1 addition & 1 deletion src/db/loc_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import logging as L

logging = L.getLogger('location_query')
logging = L.getLogger(__name__)


class LocationQuery:
Expand Down
2 changes: 1 addition & 1 deletion src/db/models/spots.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
Base = declarative_base()
engine = sa.create_engine("sqlite:///spots.db")

log = L.getLogger("db.spots")
log = L.getLogger(__name__)


class Spot(Base):
Expand Down
2 changes: 1 addition & 1 deletion src/db/spot_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from db.models.spot_comments import SpotComment
from db.models.spots import Spot

logging = L.getLogger("spot_query")
logging = L.getLogger(__name__)


class SpotQuery:
Expand Down
33 changes: 27 additions & 6 deletions src/index.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,39 @@
import os
import sys
import threading
import webview
import logging
import logging.config
import platform
import argparse
from pathlib import Path

from api import JsApi

# put filename='index.log' for deployment
logging.basicConfig(filename='index.log',
encoding='utf-8',
format='%(asctime)s = %(levelname)-7.7s [%(name)s]: %(message)s', # noqa E501
level=logging.DEBUG)
# logging.basicConfig(level=logging.DEBUG)

def configure_logging():

def get_app_global_path():
'''stolen from alembic/versions/__init__.py'''
if getattr(sys, 'frozen', False):
return os.path.abspath(os.path.dirname(sys.executable))
elif __file__:
# were running from source (npm run start) and this file is in
# so we need to back up a little so the code works
return os.path.dirname(__file__) + "../../"

conf = Path(get_app_global_path(), 'logging.conf')
if conf.exists():
logging.config.fileConfig(fname=conf, disable_existing_loggers=False)
else:
logging.basicConfig(
filename='index.log',
encoding='utf-8',
format='%(asctime)s = %(levelname)-7.7s [%(name)s]: %(message)s', # noqa E501
level=logging.DEBUG)


configure_logging()

the_api = JsApi()

Expand Down
2 changes: 1 addition & 1 deletion src/pota/pota.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from utils.callsigns import get_basecall
from version import __version__

logging = L.getLogger("potaApi")
logging = L.getLogger(__name__)


SPOT_URL = "https://api.pota.app/spot/activator"
Expand Down
2 changes: 1 addition & 1 deletion src/sota/sota.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# import urllib.parse
# from utils.callsigns import get_basecall

logging = L.getLogger("sotaApi")
logging = L.getLogger(__name__)

# -1 gets last hour of spots
SPOT_URL = "https://api2.sota.org.uk/api/spots/-1/all"
Expand Down
2 changes: 1 addition & 1 deletion src/upgrades.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# not having this in the file seemed to mess up logging to index.log
# in index.py. alembic issue?
logging = L.getLogger("upgrades")
logging = L.getLogger(__name__)


def do_upgrade():
Expand Down
2 changes: 1 addition & 1 deletion src/utils/adif.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from db.models.user_config import UserConfig
from version import __version__

logging = L.getLogger("adif_log")
logging = L.getLogger(__name__)
BACKUP_LOG_FN = "hunter.adi"


Expand Down
2 changes: 1 addition & 1 deletion src/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.0.7dev-h'
__version__ = '0.0.7dev-i'

0 comments on commit 00ac96a

Please sign in to comment.