Skip to content

Commit

Permalink
fix: only log a message once
Browse files Browse the repository at this point in the history
New handlers were registered every time the get_logger function was called, which caused the same log line to be printed multiple times in the log.

Initialise the logger once and just let get_logger return a reference instead.
  • Loading branch information
Realiserad committed Oct 18, 2024
1 parent 42d2c27 commit d5a3975
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 22 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "fish_ai"
version = "0.13.1"
version = "0.13.2"
authors = [{ name = "Bastian Fredriksson", email = "realiserad@gmail.com" }]
description = "Provides core functionality for fish-ai, an AI plugin for the fish shell."
readme = "README.md"
Expand Down
43 changes: 22 additions & 21 deletions src/fish_ai/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,34 +25,35 @@
from os import access, R_OK
from re import match

logger = logging.getLogger()

def get_args():
return list.copy(sys.argv[1:])
if path.exists('/dev/log'):
# Syslog on Linux
handler = SysLogHandler(address='/dev/log')
logger.addHandler(handler)
elif path.exists('/var/run/syslog'):
# Syslog on macOS
handler = SysLogHandler(address='/var/run/syslog')
logger.addHandler(handler)

if get_config('log'):
handler = RotatingFileHandler(path.expanduser(get_config('log')),
backupCount=0,
maxBytes=1024*1024)
logger.addHandler(handler)

if get_config('debug') == 'True':
logger.setLevel(logging.DEBUG)


def get_logger():
logger = logging.getLogger()

if path.exists('/dev/log'):
# Syslog on Linux
handler = SysLogHandler(address='/dev/log')
logger.addHandler(handler)
elif path.exists('/var/run/syslog'):
# Syslog on macOS
handler = SysLogHandler(address='/var/run/syslog')
logger.addHandler(handler)

if get_config('log'):
handler = RotatingFileHandler(path.expanduser(get_config('log')),
backupCount=0,
maxBytes=1024*1024)
logger.addHandler(handler)

if get_config('debug') == 'True':
logger.setLevel(logging.DEBUG)
return logger


def get_args():
return list.copy(sys.argv[1:])


def get_os():
if platform.system() == 'Linux':
if isfile('/etc/os-release'):
Expand Down

0 comments on commit d5a3975

Please sign in to comment.