Skip to content

Commit

Permalink
Merge pull request #138 from dparker1005/log-file-uniqid
Browse files Browse the repository at this point in the history
Adding random suffix to log file name
  • Loading branch information
dparker1005 authored Mar 8, 2024
2 parents 631a1fd + 3753e78 commit 3a03906
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
32 changes: 26 additions & 6 deletions includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,20 +273,40 @@ function pmpromc_log( $entry ) {
$logstr = "Logged On: " . date_i18n("m/d/Y H:i:s") . "\n";
$logstr .= $entry;
$logstr .= "\n-------------\n";


$loghandle = fopen( pmpromc_get_log_file_path(), "a+" );
fwrite($loghandle, $logstr);
fclose($loghandle);
}

/**
* Get the file path for the debug log file.
*
* @since TBD
*
* @return string
*/
function pmpromc_get_log_file_path() {
// Check if we have a unique file name saved already.
$pmpromc_file_name = get_option( 'pmpromc_log_file_name' );
if ( empty( $pmpromc_file_name ) ) {
$pmpromc_file_name = 'pmpromc-log-' . uniqid() . '.txt';
update_option( 'pmpromc_log_file_name', $pmpromc_file_name );
}

// Build the debug log file path.
$pmpromc_log_path = PMPROMC_DIR . "/logs/" . $pmpromc_file_name;

/**
* Filter the debug log file path.
* By default this points to /plugins/pmpro-mailchimp/logs/pmpromc-log.txt
*
* @param string $path
*
* @since 2.3.3
*
*/
$pmpromc_log_path = apply_filters( 'pmpromc_log_path', PMPROMC_DIR . "/logs/pmpromc-log.txt" );
$pmpromc_log_path = apply_filters( 'pmpromc_log_path', $pmpromc_log_path );

$loghandle = fopen( $pmpromc_log_path, "a+" );
fwrite($loghandle, $logstr);
fclose($loghandle);
return $pmpromc_log_path;
}

2 changes: 1 addition & 1 deletion includes/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ function pmpromc_option_logging_enabled() {
<option value="0" <?php selected( $logging_enabled, 0 ); ?>><?php esc_html_e( 'No', 'pmpro-mailchimp' ); ?></option>
<option value="1" <?php selected( $logging_enabled, 1 ); ?>><?php esc_html_e( 'Yes', 'pmpro-mailchimp' ); ?></option>
</select>
<p class="description"><?php printf( esc_html__( "Debug log can be found at %s", 'pmpro-mailchimp' ), '<code>/wp-content/plugins/pmpro-mailchimp/logs/pmpromc-log.txt</code>' ); ?>
<p class="description"><?php printf( esc_html__( "Debug log can be found at %s", 'pmpro-mailchimp' ), '<code>' . esc_html( pmpromc_get_log_file_path() ) . '</code>' ); ?>
</p>
<?php
}
Expand Down
Empty file added logs/index.php
Empty file.

0 comments on commit 3a03906

Please sign in to comment.