Skip to content

Commit

Permalink
allow logger daemon process to be killed with the main thread, thus a…
Browse files Browse the repository at this point in the history
…llowing us to continue logging during shutdown
  • Loading branch information
hunterjm authored and blakeblackshear committed May 6, 2021
1 parent 3a171d1 commit 482399d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 13 deletions.
2 changes: 0 additions & 2 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
{
"name": "Frigate Dev",
"context": "..",
"dockerComposeFile": "../docker-compose.yml",
"service": "dev",
"workspaceFolder": "/opt/frigate",
"shutdownAction": "stopCompose",
"extensions": [
"ms-python.python",
"visualstudioexptteam.vscodeintellicode",
Expand Down
4 changes: 4 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ services:
- .:/opt/frigate:cached
- ./config/config.yml:/config/config.yml:ro
- ./debug:/media/frigate
- type: tmpfs # Optional: 1GB of memory, reduces SSD/SD Card wear
target: /tmp/cache
tmpfs:
size: 1000000000
ports:
- "1935:1935"
- "5000:5000"
Expand Down
14 changes: 3 additions & 11 deletions frigate/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
def listener_configurer():
root = logging.getLogger()
console_handler = logging.StreamHandler()
formatter = logging.Formatter("%(name)-30s %(levelname)-8s: %(message)s")
formatter = logging.Formatter(
"[%(asctime)s] %(name)-30s %(levelname)-8s: %(message)s", "%Y-%m-%d %H:%M:%S"
)
console_handler.setFormatter(formatter)
root.addHandler(console_handler)
root.setLevel(logging.INFO)
Expand All @@ -27,20 +29,10 @@ def root_configurer(queue):


def log_process(log_queue):
stop_event = mp.Event()

def receiveSignal(signalNumber, frame):
stop_event.set()

signal.signal(signal.SIGTERM, receiveSignal)
signal.signal(signal.SIGINT, receiveSignal)

threading.current_thread().name = f"logger"
setproctitle("frigate.logger")
listener_configurer()
while True:
if stop_event.is_set() and log_queue.empty():
break
try:
record = log_queue.get(timeout=5)
except queue.Empty:
Expand Down

0 comments on commit 482399d

Please sign in to comment.