Skip to content

Commit

Permalink
Log to syslog socket instead of file
Browse files Browse the repository at this point in the history
  • Loading branch information
Heiko Nickerl committed Jun 23, 2018
1 parent 0379229 commit 6b1e211
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 27 deletions.
9 changes: 1 addition & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ datarootdir=${prefix}/share
datadir=${datarootdir}
appdatadir=${datadir}/${APPNAME}
sysconfdir=${prefix}/etc
localstatedir=${prefix}/var
docdir=${datarootdir}/doc
appdocdir=${docdir}/${APPNAME}
libdir=${exec_prefix}/lib
Expand All @@ -21,8 +20,6 @@ mandir=${datarootdir}/man
man1dir=${mandir}/man1
mimedir=${datadir}/applications
srcdir=.
logdir=${localstatedir}/log
logfile=${logdir}/${APPNAME}.log

configfile=${sysconfdir}/${APPNAME}.conf

Expand All @@ -32,7 +29,6 @@ install: installdirs
$(shell awk 'NR==1 {print; \
print "DATA_DIR='"${appdatadir}"'"; \
print "LIB_DIR='"${applibdir}"'"; \
print "LOG_FILE='"${logfile}"'"; \
print "CONFIG_FILE='"${configfile}"'"} \
NR!=1' \
${srcdir}/bin/${APPNAME} > ${DESTDIR}${bindir}/${APPNAME})
Expand All @@ -44,8 +40,6 @@ install: installdirs
done
${INSTALL_DATA} ${srcdir}/bin/shell-integration.sh bin/shell-integration.fish ${DESTDIR}${appdatadir}
${INSTALL_DATA} ${srcdir}/${APPNAME}.desktop ${DESTDIR}${mimedir}
touch ${DESTDIR}${logfile}
chmod 666 ${DESTDIR}${logfile}
${INSTALL_DATA} ${srcdir}/docs/${APPNAME}.1.gz ${DESTDIR}${man1dir}
${INSTALL_DATA} ${srcdir}/docs/${APPNAME}.conf ${DESTDIR}${configfile}
${INSTALL_DATA} ${srcdir}/docs/${APPNAME}.conf ${DESTDIR}${appdatadir}
Expand All @@ -55,7 +49,7 @@ install: installdirs


installdirs:
${INSTALL} -d ${DESTDIR}${bindir} ${DESTDIR}${applibdir} ${DESTDIR}${appdatadir} ${DESTDIR}${logdir}\
${INSTALL} -d ${DESTDIR}${bindir} ${DESTDIR}${applibdir} ${DESTDIR}${appdatadir} \
${DESTDIR}${appdocdir} ${DESTDIR}${man1dir} ${DESTDIR}${mimedir} ${DESTDIR}${sysconfdir}

uninstall:
Expand All @@ -64,7 +58,6 @@ uninstall:
@rm -rfv ${appdatadir}
@rm -rfv ${mimedir}/${APPNAME}.desktop
@rm -rfv ${man1dir}/${APPNAME}.1.gz
@rm -rfv ${logfile}
@rm -rfv ${bindir}/${APPNAME}
@rm -rfv ${bindir}/${APPNAME}-open
@rm -rfv ${configfile}
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## v0.13.5: June 23, 2018
##### Misc
- Instead of logging to /var/log/sodalite.log, now logging to the syslog socket /dev/log. When running systemd, you can now access the logs with `journalctl -ft sodalite`.

## v0.13.4: June 22, 2018
##### Misc
- Ditch install script in favour of a standardized Makefile
Expand Down
Binary file modified docs/sodalite.1.gz
Binary file not shown.
4 changes: 0 additions & 4 deletions docs/sodalite.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -338,10 +338,6 @@ FILES

: Database of sodalite. If `$XDG_DATA_HOME` is not set, uses `$HOME/.local/share`.

*/var/log/sodalite.log*

: The log.

<!--
ENVIRONMENT
===========
Expand Down
7 changes: 4 additions & 3 deletions sodalite/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
from core.entry import Entry
from util import environment

VERSION = 'sodalite v0.13.5'


logger = logging.getLogger(__name__)

VERSION = 'sodalite v0.13.4'

def _io_to_tty():
global _old_stdin
Expand Down Expand Up @@ -73,7 +75,6 @@ def parse_arguments():
exit(0)

try:
logger.info('Starting sodalite')
_io_to_tty()
from ui import graphics

Expand All @@ -84,5 +85,5 @@ def parse_arguments():
print(environment.exit_cwd)
logger.info("Shutting down")
except KeyboardInterrupt as e:
logger.info('Received SIGINT')
logger.info('Received SIGINT - shutting down')
exit(1)
25 changes: 13 additions & 12 deletions sodalite/util/environment.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
import logging
import logging.handlers
import os

exit_cwd = None
# setup logger
_global_logger = logging.getLogger()
_global_logger.setLevel(logging.DEBUG)
handler = logging.handlers.SysLogHandler(address='/dev/log')
formatter = logging.Formatter('sodalite: %(name)-18s - %(levelname)-5s - %(message)s')
handler.setFormatter(formatter)
_global_logger.addHandler(handler)
logging.getLogger('watchdog').setLevel(logging.INFO)

logger = logging.getLogger(__name__)
logger.info('Starting sodalite')

exit_cwd = None
# program will read following environment variables
ENV_DATA_DIR = 'DATA_DIR'
ENV_BOOKMARK_DIR = 'BOOKMARK_DIR'
ENV_LOG_FILE = 'LOG_FILE'
ENV_DB_PATH = 'DB_PATH'
ENV_CONFIG_FILE = 'CONFIG_FILE'

Expand All @@ -15,7 +25,6 @@
user_data = os.getenv('XDG_DATA_HOME', os.path.join(home, ".local/share/sodalite/"))
bookmark_dir = os.getenv(ENV_BOOKMARK_DIR, os.path.join(user_data, "bookmarks"))
user_config = os.getenv('XDG_CONFIG_HOME', os.path.join(home, ".config/sodalite/"))
log_file = os.getenv(ENV_LOG_FILE, "/var/log/sodalite.log")
db_file = os.getenv(ENV_DB_PATH, os.path.join(user_data, "db.sqlite"))
history_file = os.path.join(user_data, 'history')

Expand All @@ -29,13 +38,5 @@
for directory in dirs:
os.makedirs(directory, exist_ok=True)

logging.basicConfig(filename=log_file, level=logging.DEBUG,
format='%(asctime)s - %(name)-18s - %(levelname)-5s - %(message)s')
logger = logging.getLogger(__name__)
logging.getLogger('watchdog').setLevel(logging.INFO)

logger.info(f"Using database: {db_file}")
logger.info(f"Using config file: {config_file}")



0 comments on commit 6b1e211

Please sign in to comment.