Skip to content

Commit

Permalink
Move setup_logging to helpers.py
Browse files Browse the repository at this point in the history
This allows to reuse this function in another service.
  • Loading branch information
tvoirand committed Dec 6, 2024
1 parent 3046512 commit 0afd5ba
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
16 changes: 2 additions & 14 deletions scripts/birdnet_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import os.path
import re
import signal
import sys
import threading
from queue import Queue
from subprocess import CalledProcessError
Expand All @@ -12,13 +11,13 @@
from inotify.constants import IN_CLOSE_WRITE

from server import load_global_model, run_analysis
from utils.helpers import get_settings, ParseFileName, get_wav_files, ANALYZING_NOW
from utils.helpers import get_settings, ParseFileName, get_wav_files, ANALYZING_NOW, setup_logging
from utils.reporting import extract_detection, summary, write_to_file, write_to_db, apprise, bird_weather, heartbeat, \
update_json_file

shutdown = False

log = logging.getLogger(__name__)
log = logging.getLogger(os.path.splitext(os.path.basename(os.path.realpath(__file__)))[0])


def sig_handler(sig_num, curr_stack_frame):
Expand Down Expand Up @@ -129,17 +128,6 @@ def handle_reporting_queue(queue):
log.info('handle_reporting_queue done')


def setup_logging():
logger = logging.getLogger()
formatter = logging.Formatter("[%(name)s][%(levelname)s] %(message)s")
handler = logging.StreamHandler(stream=sys.stdout)
handler.setFormatter(formatter)
logger.addHandler(handler)
logger.setLevel(logging.INFO)
global log
log = logging.getLogger('birdnet_analysis')


if __name__ == '__main__':
signal.signal(signal.SIGINT, sig_handler)
signal.signal(signal.SIGTERM, sig_handler)
Expand Down
11 changes: 11 additions & 0 deletions scripts/utils/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import subprocess
from configparser import ConfigParser
from itertools import chain
import logging
import sys

from tzlocal import get_localzone

Expand Down Expand Up @@ -101,3 +103,12 @@ def get_wav_files():
open_recs = get_open_files_in_dir(rec_dir)
files = [file for file in files if file not in open_recs]
return files


def setup_logging():
logger = logging.getLogger()
formatter = logging.Formatter("[%(name)s][%(levelname)s] %(message)s")
handler = logging.StreamHandler(stream=sys.stdout)
handler.setFormatter(formatter)
logger.addHandler(handler)
logger.setLevel(logging.INFO)

0 comments on commit 0afd5ba

Please sign in to comment.