ajax 사용시 로그를 서버에 저장하려는데 어떻게 하나요??

매출이 오르면 내리는 수수료! 지금 수수료센터에서 전자결제(PG)수수료 비교견적 신청해 보세요!
ajax 사용시 로그를 서버에 저장하려는데 어떻게 하나요??

QA

ajax 사용시 로그를 서버에 저장하려는데 어떻게 하나요??

본문

else {

                        $('#load').show();

                        setTimeout(function() {

                            $('#result').hide();

                            $('#load').hide();

                            alert('검색하신 모델명이 없습니다.');

                            $('#fail_guide').show();

                        },3000);    

                    }

 

이 부분에 검색했던 문자열을 로그 파일로 저장하려고합니다

이 질문에 댓글 쓰기 :

답변 1

에러 메시지 같은거 로그에 남긴단거에요?

검색한 기록을 로그에 남긴다는건가요?

php 단 코드를 이렇게 했는데 안됩니다

<?php
$model_code = $_GET['model_code'];
// required headers
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");

// include database file
include_once 'mongodb_config.php';

$dbname = 'product';
$collection = 'productAll';


//DB connection
$db = new DbManager();
$conn = $db->getConnection();

// read all records
$filter = ['model_code' => ['$regex' => '^'.$model_code.'$', '$options' => 'i']];
$option = ['limit' => 1];
$read = new MongoDB\Driver\Query($filter, $option);

//fetch records
$records = $conn->executeQuery("$dbname.$collection", $read);

echo json_encode(iterator_to_array($records), JSON_UNESCAPED_UNICODE);

function log_write($str){

    //디렉토리 경로
    $log_dir = '/var/www/html/estimate/log';
    //$log_dir = "/home/root...등의 절대경로 ";


    $log_txt = "\r\n";
    $log_txt .= '(' . date("Y-m-d H:i:s") . ')' . "\r\n";
    $log_txt .= $str;

    $log_file = fopen($log_dir . 'search.log', 'a');
    fwrite($log_file, $log_txt . "\r\n\r\n");
    fclose($log_file);

}

log_write($model_code);
?>

생성은 됐습니다!!!
이제 if문에 조건을 줘야하는데 몽고디비 조회 값이 없을때만 사용해야합니다

// read all records
$filter = ['model_code' => ['$regex' => '^'.$model_code.'$', '$options' => 'i']];
$option = ['limit' => 1];
$read = new MongoDB\Driver\Query($filter, $option);

//fetch records
$records = $conn->executeQuery("$dbname.$collection", $read);

echo json_encode(iterator_to_array($records), JSON_UNESCAPED_UNICODE);

if(???????) {
$dir = "/var/www/html/estimate/log". date('Y/n/d');

    if(!is_dir($dir))
    {
        mkdir($dir,0777,true);
        chmod($dir,0777,true);
    }



    $log_txt = date('Y_m_d_H:i:s') . ' | '. '검색모델명'. ' : '.$model_code;

    $log_dir = $dir."/";

    $file_name = date('Y_m_d');

    $log_file = fopen($log_dir."/".$file_name.".txt", "a");

    fwrite($log_file, $log_txt."\r\n");

    fclose($log_file);
}

답변을 작성하시기 전에 로그인 해주세요.
전체 45
QA 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT