NAME

App::FileSync::Settings - process-wide settings and logging for App::FileSync

SYNOPSIS

use App::FileSync::Settings;

my $logger = App::FileSync::Settings::logger(verbose => 1);
$logger->error('...');

my $settings = App::FileSync::Settings::load();
my $level = $settings->{log_level};

my $report = App::FileSync::Settings::explain();
printf "%s = %s (%s)\n", $_->{key}, $_->{value}, $_->{label}
    for @{ $report->{settings} };

DESCRIPTION

Settings that apply to the process rather than to one repo - the log level, format and destination, plus the SSH identity, known-hosts file and remote server command - are read through Object::Configure. The repos themselves remain in ~/.filesync/config.json, which filesync init writes; this module does not replace that store.

The settings file is ~/.conf/app-filesync.json when it exists, or the path in FILESYNC_SETTINGS. The section key is App__FileSync, and a UNIVERSAL section in the same directory applies to every class that uses Object::Configure. Environment variables named App__FileSync__key override the file:

# ~/.conf/app-filesync.json
{ "App__FileSync": { "log_level": "debug", "log_format": "%level%: %message%" } }

# or
export App__FileSync__log_level=debug

log_file sends the log to a file instead of standard error; leading directories are created. log_format is a Log::Abstraction format string.

ssh_identity, ssh_known_hosts and server_command are the defaults for every SSH repo, so a per-repo identity, known_hosts or server_command (written by filesync init --identity and friends) only has to be set when it differs. server_command defaults to filesync-server:

{ "App__FileSync": {
    "ssh_identity"    : "~/.ssh/filesync_ed25519",
    "ssh_known_hosts" : "~/.ssh/filesync_known_hosts",
    "server_command"  : "/usr/local/bin/filesync-server"
} }

Command output (sync summaries, plans, --json) is written to standard output by the commands themselves; the logger carries diagnostics on standard error, so a cron job can separate the two. --verbose raises the level to debug and --quiet lowers it to error for that run, overriding the file.

FUNCTIONS

logger

my $logger = App::FileSync::Settings::logger(%args);

Returns a Log::Abstraction writing to standard error (or log_file). config_file, config_dirs, level, verbose and quiet may be passed.

load

Returns the merged settings hashref (without the Object::Configure logger).

config_file

Returns the settings file that would be used, or undef.

explain

my $report = App::FileSync::Settings::explain(%args);

Returns { settings_file => $path_or_undef, settings => \@rows }, with one row per key in @App::FileSync::Settings::SETTING_KEYS. Each row has the effective value, a source of default, file, env or merged, anda human-readable label naming the file section, environment variable or built-in default that supplied it. config_file and config_dirs may be passed, as for load.

explain_repos

my $repos = App::FileSync::Settings::explain_repos(%args);

Resolves ssh_identity, ssh_known_hosts and server_command for every repo in a client config. config is the hashref from App::FileSync::Config::load_client, report is the result of explain, and config_file is the client config path used in labels.

Each entry has repo, transport, server (when the repo records one) and ssh: one {key, value, source, label} row per setting, where source is repo (the repo's own entry), process (the settings reported by explain) or default (ssh's own default, when nothing sets a value). ssh is undef for the local transport, which never runs ssh.

LICENCE

GPL v2 for personal single-user, single-computer use. All other users must apply in writing to the author.