Skip to content

Commit

Permalink
Merge pull request #127 from alleyinteractive/feature/relative-time
Browse files Browse the repository at this point in the history
Display the relative time for the log
  • Loading branch information
srtfisher authored Aug 26, 2024
2 parents dcf0a83 + d503295 commit fa8169a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
2 changes: 1 addition & 1 deletion logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: Alley Logger
* Plugin URI: https://github.com/alleyinteractive/logger
* Description: A Monolog-based logging tool for WordPress. Supports storing log message in a custom post type or in individual posts and terms.
* Version: 2.4.3
* Version: 2.4.4
* Author: Alley Interactive
* Author URI: https://alley.com/
* Requires at least: 5.9
Expand Down
23 changes: 15 additions & 8 deletions template-parts/log-display.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,6 @@ function ai_logger_render_table( array $data ): void {
<?php
}
}

$ai_logger_date_format = 'M d, Y h:i:s A O';

?>
<div class="ai-log-display">
<h4><?php esc_html_e( 'Log Summary', 'ai-logger' ); ?></h4>
Expand Down Expand Up @@ -218,16 +215,26 @@ function ai_logger_render_table( array $data ): void {
<td><?php esc_html_e( 'Channel', 'ai-logger' ); ?></td>
<td><?php echo esc_html( $log['channel'] ?? '' ); ?></td>
</tr>
<?php $ai_logger_date_format = get_option( 'date_format' ) . ' ' . get_option( 'time_format' ); ?>
<tr>
<td><?php esc_html_e( 'Timestamp', 'ai-logger' ); ?></td>
<td><?php echo esc_html( $log['datetime']->format( $ai_logger_date_format ) ); ?></td>
</tr>
<tr>
<td><?php esc_html_e( 'Timestamp Local', 'ai-logger' ); ?></td>
<td>
<?php echo esc_html( $log['datetime']->setTimezone( wp_timezone() )->format( $ai_logger_date_format ) ); ?>
<?php
echo esc_html(
sprintf(
/* translators: 1: Date and time, 2: Human readable time difference */
__( '%1$s (%2$s ago)', 'ai-logger' ),
$log['datetime']->setTimezone( wp_timezone() )->format( $ai_logger_date_format ),
human_time_diff( $log['datetime']->getTimestamp() ),
),
);
?>
</td>
</tr>
<tr>
<td><?php esc_html_e( 'Timestamp UTC', 'ai-logger' ); ?></td>
<td><?php echo esc_html( $log['datetime']->format( $ai_logger_date_format ) ); ?></td>
</tr>
</table>

<?php if ( ! empty( $log['context'] ) ) : ?>
Expand Down

0 comments on commit fa8169a

Please sign in to comment.