Skip to content

Commit

Permalink
Add app_log_to_syslog app helper function
Browse files Browse the repository at this point in the history
  • Loading branch information
bergercookie committed Aug 30, 2023
1 parent db6808b commit ccfeb30
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 43 deletions.
22 changes: 19 additions & 3 deletions syncall/app_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
`sys.exit()` to avoid dumping stack traces to the user.
"""

import inspect
import logging
import os
import subprocess
Expand All @@ -14,7 +15,15 @@
from typing import Any, Mapping, NoReturn, Optional, Sequence, Tuple, Type, cast
from urllib.parse import quote

from bubop import PrefsManager, format_list, logger, non_empty, read_gpg_token, valid_path
from bubop import (
PrefsManager,
format_list,
log_to_syslog,
logger,
non_empty,
read_gpg_token,
valid_path,
)
from bubop.crypto import write_gpg_token
from item_synchronizer.resolution_strategy import (
AlwaysFirstRS,
Expand Down Expand Up @@ -212,7 +221,7 @@ def inform_about_combination_name_usage(combination_name: str):
exec_name = Path(sys.argv[0]).stem
logger.success(
"Sync completed successfully. You can now use the"
f' {"/".join(COMBINATION_FLAGS)} option to refer to this particular combination\n\n '
f" {'/'.join(COMBINATION_FLAGS)} option to refer to this particular combination\n\n "
f" {exec_name} {COMBINATION_FLAGS[1]} {combination_name}"
)

Expand All @@ -223,7 +232,7 @@ def inform_about_app_extras(extras: Sequence[str]) -> NoReturn:
extras_str = ",".join(extras)
logger.error(
"\nYou have to install the"
f' {extras_str} {"extra" if len(extras) == 1 else "extras"} for {exec_name} to'
f" {extras_str} {'extra' if len(extras) == 1 else 'extras'} for {exec_name} to"
' work.\nWith pip, you can do it with something like: "pip3 install'
f' syncall[{extras_str}]"\nExiting.'
)
Expand Down Expand Up @@ -331,3 +340,10 @@ def gkeep_read_username_password_token(
gkeep_token = fetch_from_pass_manager(gkeep_token_pass_path, allow_fail=True)

return gkeep_user, gkeep_passwd, gkeep_token


def app_log_to_syslog():
caller_frame = inspect.stack()[1]
calling_file = Path(caller_frame[1])
fname = calling_file.stem
log_to_syslog(name=fname)
16 changes: 7 additions & 9 deletions syncall/scripts/fs_gkeep_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,7 @@
from typing import Optional, Sequence

import click
from bubop import (
check_optional_mutually_exclusive,
format_dict,
log_to_syslog,
logger,
loguru_tqdm_sink,
)
from bubop import check_optional_mutually_exclusive, format_dict, logger, loguru_tqdm_sink

from syncall import inform_about_app_extras
from syncall.cli import opt_filename_extension, opt_gkeep_ignore_labels
Expand All @@ -32,7 +26,11 @@
list_named_combinations,
report_toplevel_exception,
)
from syncall.app_utils import gkeep_read_username_password_token, write_to_pass_manager
from syncall.app_utils import (
app_log_to_syslog,
gkeep_read_username_password_token,
write_to_pass_manager,
)
from syncall.cli import (
opt_combination,
opt_custom_combination_savename,
Expand Down Expand Up @@ -92,7 +90,7 @@ def main(
"""
# setup logger ----------------------------------------------------------------------------
loguru_tqdm_sink(verbosity=verbose)
log_to_syslog(name="fs_gkeep_sync")
app_log_to_syslog()
logger.debug("Initialising...")
inform_about_config = False

Expand Down
12 changes: 3 additions & 9 deletions syncall/scripts/tw_asana_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,10 @@

import asana
import click
from bubop import (
check_optional_mutually_exclusive,
format_dict,
log_to_syslog,
logger,
loguru_tqdm_sink,
)
from bubop import check_optional_mutually_exclusive, format_dict, logger, loguru_tqdm_sink

from syncall import inform_about_app_extras
from syncall.app_utils import error_and_exit
from syncall.app_utils import app_log_to_syslog, error_and_exit

try:
from syncall import AsanaSide, TaskWarriorSide
Expand Down Expand Up @@ -85,7 +79,7 @@ def main(
):
loguru_tqdm_sink(verbosity=verbose)

log_to_syslog(name="tw_asana_sync")
app_log_to_syslog()
logger.debug("Initialising...")
inform_about_config = False

Expand Down
5 changes: 2 additions & 3 deletions syncall/scripts/tw_caldav_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@
check_optional_mutually_exclusive,
check_required_mutually_exclusive,
format_dict,
log_to_syslog,
logger,
loguru_tqdm_sink,
)

from syncall import inform_about_app_extras
from syncall.app_utils import error_and_exit
from syncall.app_utils import app_log_to_syslog, error_and_exit
from syncall.cli import (
opt_caldav_calendar,
opt_caldav_passwd_cmd,
Expand Down Expand Up @@ -97,7 +96,7 @@ def main(
"""

loguru_tqdm_sink(verbosity=verbose)
log_to_syslog(name="tw_caldav_sync")
app_log_to_syslog()
logger.debug("Initialising...")
inform_about_config = False

Expand Down
11 changes: 3 additions & 8 deletions syncall/scripts/tw_gcal_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,10 @@
from typing import List

import click
from bubop import (
check_optional_mutually_exclusive,
format_dict,
log_to_syslog,
logger,
loguru_tqdm_sink,
)
from bubop import check_optional_mutually_exclusive, format_dict, logger, loguru_tqdm_sink

from syncall import inform_about_app_extras
from syncall.app_utils import app_log_to_syslog

try:
from syncall import GCalSide, TaskWarriorSide
Expand Down Expand Up @@ -86,7 +81,7 @@ def main(
"""
# setup logger ----------------------------------------------------------------------------
loguru_tqdm_sink(verbosity=verbose)
log_to_syslog(name="tw_gcal_sync")
app_log_to_syslog()
logger.debug("Initialising...")
inform_about_config = False

Expand Down
16 changes: 7 additions & 9 deletions syncall/scripts/tw_gkeep_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@
from typing import Sequence

import click
from bubop import (
check_optional_mutually_exclusive,
format_dict,
log_to_syslog,
logger,
loguru_tqdm_sink,
)
from bubop import check_optional_mutually_exclusive, format_dict, logger, loguru_tqdm_sink

from syncall import inform_about_app_extras
from syncall.app_utils import gkeep_read_username_password_token, write_to_pass_manager
from syncall.app_utils import (
app_log_to_syslog,
gkeep_read_username_password_token,
write_to_pass_manager,
)

try:
from syncall import GKeepTodoSide, TaskWarriorSide
Expand Down Expand Up @@ -86,7 +84,7 @@ def main(
"""
# setup logger ----------------------------------------------------------------------------
loguru_tqdm_sink(verbosity=verbose)
log_to_syslog(name="tw_gkeep_sync")
app_log_to_syslog()
logger.debug("Initialising...")
inform_about_config = False

Expand Down
4 changes: 2 additions & 2 deletions syncall/scripts/tw_notion_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
from bubop import (
check_optional_mutually_exclusive,
format_dict,
log_to_syslog,
logger,
loguru_tqdm_sink,
verbosity_int_to_std_logging_lvl,
)

from syncall import inform_about_app_extras
from syncall.app_utils import app_log_to_syslog

try:
from syncall import NotionSide, TaskWarriorSide
Expand Down Expand Up @@ -81,7 +81,7 @@ def main(
"""
# setup logger ----------------------------------------------------------------------------
loguru_tqdm_sink(verbosity=verbose)
log_to_syslog(name="tw_notion_sync")
app_log_to_syslog()
logger.debug("Initialising...")
inform_about_config = False

Expand Down

0 comments on commit ccfeb30

Please sign in to comment.