MarcusBarnes / mik

The Move to Islandora Kit is an extensible PHP command-line tool for converting source content and metadata into packages suitable for importing into Islandora (or other digital repository and preservations systems).
GNU General Public License v3.0
34 stars 11 forks source link

Use relative file locations? #411

Open whikloj opened 7 years ago

whikloj commented 7 years ago

Just wondering how you felt about relative file locations? Especially for logs and the like? I see you specify your log location directly from the settings file in several locations so you'd need to centralize that a bit.

But otherwise I was thinking something like changing this https://github.com/MarcusBarnes/mik/blob/master/mik#L102-L106

to

// Set up logger ErrorException stream for main mik script.
$pathToLog = $settings['LOGGING']['path_to_log'];
if (!empty($pathToLog)) {
    $pathToLog = realpath($pathToLog);
    $logDir = dirname($pathToLog);
    if (!file_exists($logDir)) {
        if (! mkdir($logDir)) {
            throw new Exception(
              "Log directory (${logDir}) does not exist, unable to create"
            );
        }
    }
}
$log = new Logger('ErrorException');
$logStreamHandler= new StreamHandler($pathToLog, Logger::ERROR);
$log->pushHandler($logStreamHandler);
mjordan commented 7 years ago

@whikloj can you give an example value for ['LOGGING']['path_to_log']? Would it be something like "/path_to/my/logs"?

The main mik script already does define a relative path to problem_records.log:

https://github.com/MarcusBarnes/mik/blob/master/mik#L192-L199

Is that the kind of thing you're proposing? If so, we probably should clean up the code there and create a utility function to get the path in the interests of DRY. A reusable function would also let post-write hook scripts, etc. use it.