# wp-discourse/trunk/tests/phpunit/helpers/logging.php

WP Discourse, version trunk. 43 lines.

- Page: https://pluginprobe.com/plugins/wp-discourse/trunk/code/tests/phpunit/helpers/logging.php
- Raw: https://pluginprobe.com/plugins/wp-discourse/trunk/raw/tests/phpunit/helpers/logging.php
- Modified: 2025-04-16T00:30:42+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/wp-discourse/trunk/code/tests/phpunit/helpers/logging.php#L10-L20`.

```php
<?php
/**
 * Class \Test\Logging
 *
 * @package WPDiscourse
 */

namespace WPDiscourse\Test;

use WPDiscourse\Logs\FileManager;

/**
 * Logging methods for WPDiscourse unit tests
 */
trait Logging {
    /**
     * Get last line in latest log file.
     */
    protected function get_last_log() {
		$manager   = new FileManager();
		$log_files = glob( $manager->logs_dir . '/*.log' );
		if ( empty( $log_files ) ) {
			return '';
			}
		$log_file = $log_files[0];
		return shell_exec( "tail -n 1 $log_file" );
    }

    /**
     * Clear all logs.
     */
    protected function clear_logs() {
		$manager   = new FileManager();
		$log_files = glob( $manager->logs_dir . '/*.log' );

		foreach ( $log_files as $file ) {
			if ( is_file( $file ) ) {
				unlink( $file );
			}
			}
    }
}

```
