code

WordPress 디버깅

starcafe 2023. 3. 14. 21:47
반응형

WordPress 디버깅

WordPress 플러그인에서 디버깅메시지를 작성하려면 어떻게 해야 하나요?

WordPress의 디버깅에서는 이 기능을 활성화하는 방법에 대해 설명합니다.wp-content/debug.log파일입니다만, 어떻게 쓸 수 있을까요?다음과 같은 로깅 방법이 있습니까?wp_log($msg)뭐 그런 거요?그런 건 못 찾았어요.

한다면WP_DEBUG_LOG를 true 로 설정하고 -INI설정합니다.

ini_set( 'error_log', WP_CONTENT_DIR . '/debug.log' );

이 파일에 쓰려면 -함수를 사용합니다.

error_log("This message is written to the log file");

이 함수는 WordPress에 한정되지 않으며 모든 PHP 스크립트에서 사용할 수 있습니다.

다음은 사용할 수 있는 간단한 함수입니다.WP_DEBUG가 활성화되어 있는 경우에만 메시지가 기록됩니다.

function log_me($message) {
    if ( WP_DEBUG === true ) {
        if ( is_array($message) || is_object($message) ) {
            error_log( print_r($message, true) );
        } else {
            error_log( $message );
        }
    }
}

에 전화할 수 있습니다.log_me()테마 템플릿에서는 다음과 같이 기능합니다.

log_me( 'This is a message for debugging purposes' );

이 정보는 다음 페이지에 표시됩니다./wp-content/debug.log다음 행과 같이 입력합니다.

[13-Apr-2013 20:59:17 UTC] This is a message for debugging purposes

언급URL : https://stackoverflow.com/questions/15085482/wordpress-debugging

반응형