-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlog-for-docker.php
More file actions
42 lines (35 loc) · 1.07 KB
/
log-for-docker.php
File metadata and controls
42 lines (35 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
/*
Plugin Name: Log For Docker
Description: Save the log suitable for the docker environment. You can check the output with the docker logs command.
Version: 1.0
Author: Kazunao Anahara
Author URI: https://www.pressman.ne.jp/
License: GPLv2
*/
if ( ! defined( 'ABSPATH' ) ) exit;
class Log_For_Docker {
public static function log( $message ) {
self::_write( self::_message( $message ), 'php://stdout' );
}
public static function error( $message ) {
self::_write( self::_message( $message, true ), 'php://stderr' );
}
protected function _message( $message, $is_error=false ) {
$message = apply_filters( 'pre_docker_Log_message', $message, $is_error );
$message = self::_print_r( $message );
$message = apply_filters( 'docker_Log_message', $message, $is_error );
return $message;
}
protected static function _write( $output, $path ) {
$std = fopen( $path, 'w' );
fwrite( $std, $output );
fclose( $std );
}
protected static function _print_r( $message ) {
if( !is_string( $message ) ){
$message = print_r( $message , true );
}
return $message;
}
}