$size ) { $offset = 0; } if ( $offset === $size ) { return; } $max_read = 256 * 1024; // cap each pass at 256 KB $contents = (string) file_get_contents( $path, false, null, $offset, $max_read ); $new_pos = min( $size, $offset + strlen( $contents ) ); if ( '' === $contents ) { update_option( 'apwpm_debug_log_offset', $size, false ); return; } $lines = preg_split( '/\r?\n/', $contents ); $count = 0; foreach ( (array) $lines as $line ) { $line = trim( (string) $line ); if ( '' === $line || $count >= 200 ) { continue; } if ( ! preg_match( '/PHP\s+(Fatal|Parse|Warning|Notice|Deprecated|Strict)/i', $line, $m ) ) { continue; } $kind = strtolower( $m[1] ); $severity = in_array( $kind, array( 'fatal', 'parse' ), true ) ? 'critical' : ( 'warning' === $kind ? 'warning' : 'error' ); APWPM_Logger::log( array( 'action_type' => 'php_log_entry', 'object_type' => 'error', 'object_title' => 'debug.log', 'description' => substr( $line, 0, self::MAX_MESSAGE ), 'severity' => $severity, 'context' => array( 'source' => 'debug.log' ), ) ); $count++; } update_option( 'apwpm_debug_log_offset', (int) $new_pos, false ); } /* ---------------------------------------------------------------- */ protected static function mapwpm_severity( $errno ) { switch ( $errno ) { case E_ERROR: case E_CORE_ERROR: case E_COMPILE_ERROR: case E_USER_ERROR: case E_PARSE: return 'critical'; case E_WARNING: case E_CORE_WARNING: case E_COMPILE_WARNING: case E_USER_WARNING: case E_RECOVERABLE_ERROR: return 'error'; case E_NOTICE: case E_USER_NOTICE: case E_DEPRECATED: case E_USER_DEPRECATED: // Only record notices when WP_DEBUG is on — too noisy otherwise. return ( defined( 'WP_DEBUG' ) && WP_DEBUG ) ? 'warning' : null; default: return null; } } protected static function record( $severity, $message, $file, $line, $errno ) { APWPM_Logger::log( array( 'action_type' => 'php_' . $severity, 'object_type' => 'error', 'object_title' => basename( (string) $file ) . ( $line ? ':' . $line : '' ), 'description' => substr( (string) $message, 0, self::MAX_MESSAGE ), 'severity' => $severity, 'context' => array( 'file' => (string) $file, 'line' => (int) $line, 'errno' => (int) $errno, ), ) ); } }