Skip to content

Commit 6cfae11

Browse files
change file name, format and size
1 parent 396ccbb commit 6cfae11

File tree

4 files changed

+11
-8
lines changed

4 files changed

+11
-8
lines changed

src/class-tiny-diagnostics.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ public function create_diagnostic_zip() {
210210

211211
// Add diagnostic info.
212212
$info = self::collect_info();
213-
$zip->addFromString( 'diagnostics.json', wp_json_encode( $info, JSON_PRETTY_PRINT ) );
213+
$zip->addFromString( 'tiny-diagnostics.json', wp_json_encode( $info, JSON_PRETTY_PRINT ) );
214214

215215
// Add log files.
216216
$logger = Tiny_Logger::get_instance();

src/class-tiny-image.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ public function compress() {
253253
$size->add_tiny_meta_error( $e );
254254
$failed++;
255255
Tiny_Logger::error('compress failed', array(
256-
'error' => $e,
256+
'error' => $e->get_message(),
257257
'size' => $size_name,
258258
'image_id' => $this->id,
259259
));

src/class-tiny-logger.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class Tiny_Logger {
3131
const LOG_LEVEL_ERROR = 'error';
3232
const LOG_LEVEL_DEBUG = 'debug';
3333

34-
const MAX_LOG_SIZE = 5242880; // 5MB
34+
const MAX_LOG_SIZE = 2 * 1024 * 1024; // 2MB
3535

3636
private static $instance = null;
3737

@@ -176,11 +176,14 @@ private function log( $level, $message, $context = array() ) {
176176
$timestamp = current_time( 'Y-m-d H:i:s' );
177177
$level_str = strtoupper( $level );
178178
$context_str = ! empty( $context ) ? ' ' . wp_json_encode( $context ) : '';
179-
$log_entry = "[{$timestamp}] [{$level_str}] {$message}{$context_str}\\n";
180-
179+
$log_entry = "[{$timestamp}] [{$level_str}] {$message}{$context_str}" . PHP_EOL;
181180
$file = fopen( $this->log_file_path, 'a' );
182181
if ( $file ) {
183-
fwrite( $file, $log_entry );
182+
if ( flock( $file, LOCK_EX ) ) {
183+
fwrite( $file, $log_entry );
184+
fflush( $file );
185+
flock( $file, LOCK_UN );
186+
}
184187
fclose( $file );
185188
}
186189
}

test/unit/TinyLoggerTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,12 @@ public function test_removes_full_log_and_creates_new()
102102
$log_dir = $this->vfs->getChild($log_dir_path);
103103

104104
vfsStream::newFile('tiny-compress.log')
105-
->withContent(LargeFileContent::withMegabytes(5.1))
105+
->withContent(LargeFileContent::withMegabytes(2.1))
106106
->at($log_dir);
107107

108108
$logger = Tiny_Logger::get_instance();
109109

110-
assertTrue(filesize($logger->get_log_file_path()) > 5242880, 'log file should be larger than 5MB');
110+
assertTrue(filesize($logger->get_log_file_path()) > 2097152, 'log file should be larger than 2MB');
111111

112112
Tiny_Logger::error('This should be logged');
113113

0 commit comments

Comments
 (0)