quocvuongdn

#php: log to file path logs/date_folder/time_file.log

Dec 1st, 2014
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.45 KB | None | 0 0
  1. <?php
  2.  
  3. logger();
  4.  
  5. function logger(){
  6.  
  7.     #Write log contents by date/time
  8.     $content = "Log by time";
  9.     $now = time();
  10.     $ymd = 'logs/'.date('Y-m-d', $now);
  11.     $template = date('H:m:s', $now)." - ".$content;
  12.     $file_name = $ymd.'/'.date('H', $now).'.log';
  13.     if(!is_dir($ymd)){
  14.         mkdir($ymd, 0777, true);
  15.     }
  16.     $current = $template . PHP_EOL;
  17.     $f = fopen($file_name, 'a');
  18.     fwrite($f, $current);
  19.     fclose($f);
  20.     #End write log contents by date/time
  21. }
Advertisement
Add Comment
Please, Sign In to add comment