Skip to content
This repository has been archived by the owner on Mar 17, 2020. It is now read-only.

Commit

Permalink
ログ機能を追加
Browse files Browse the repository at this point in the history
  • Loading branch information
miyukki committed Jan 4, 2014
1 parent 7f83270 commit ce930d0
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ Route.php
# Own Environment
environment/*

# Own Log
log/*

# Own Tests
Test.php
test.php
1 change: 1 addition & 0 deletions Config.sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
'public' => dirname(__FILE__).'/public',
'vendor' => dirname(__FILE__).'/vendor',
'controller' => dirname(__FILE__).'/controller',
'log' => dirname(__FILE__).'/log',
),
);
1 change: 1 addition & 0 deletions Core.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
require(BASE_DIR.'/core/Environment.class.php');
require(BASE_DIR.'/core/Logic.class.php');
require(BASE_DIR.'/core/Controller.class.php');
require(BASE_DIR.'/core/Log.class.php');

switch (Environment::get()) {
case Environment::PRODUCTION:
Expand Down
6 changes: 6 additions & 0 deletions core/Event.class.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
<?php

class Event {
public function __construct() {

}

public static function addEventListener($event_name, $event_handler) {

}

public function __destruct() {
echo View::getBuffer();
Log::finalize();
}
}
$event = new Event();
57 changes: 57 additions & 0 deletions core/Log.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

/**
* Log
*
* ログを管理するクラスです
*
* @package ApplestFramework
* @author miyukki<[email protected]>
*/
class Log {
private static $delay_mode = true;
private static $output_mode = false;

private static $logs = array();

public static function delay() {
self::$delay_mode = false;
}
public static function output() {
self::$output_mode = true;
}

public static function dump($object) {
ob_start();
var_dump($object);
$dump_str = ob_get_contents();
ob_end_clean();
self::write($dump_str);
}

public static function info($log_text) {
self::write('INFO', $log_text);
}

public static function warn() {
self::write('WARN', $log_text);
}

public static function error() {
self::write('ERROR', $log_text);
}

private static function write($level, $log_text) {
// self::$logs[] = '['.$level.'] '.date('Y:m:d H:i:s').' '.$log_text;
self::$logs[] = sprintf('[%s] %s %s', $level, date('Y:m:d H:i:s'), $log_text);
}

public static function finalize() {
$log_str = '';
foreach (self::$logs as $log) {
$log_str .= $log.PHP_EOL;
}
$log_name = date('Ymd').'.log';
file_put_contents(Config::get('path.log').'/'.$log_name, $log_str, FILE_APPEND);
}
}
Empty file added log/.gitempty
Empty file.

0 comments on commit ce930d0

Please sign in to comment.