/** * add Fluent params * @params params */ public function addFluent($params = array()) { $params = array_merge(array('host' => 'localhost', 'port' => '24224', 'tag' => 'systemlog', 'level' => \Slim\Log::DEBUG, 'option' => array()), $params); if (isset($params['tag_with_date'])) { $ts = new \DateTime(); $params['tag'] = $params['tag'] . $ts->format($params['tag_with_date']); } $logger = new \Fluent\Logger\FluentLogger($params['host'], $params['port']); if (isset($params['error_handler'])) { $logger->registerErrorHandler($params['error_handler']); } $this->loggerAry[] = $logger; $this->paramsAry[] = $params; }
public function after_save(\Orm\Model $obj) { $save_data = array(); foreach (array_keys($obj->properties()) as $p) { $save_data[$p] = $obj->{$p}; } $host = empty(self::$td_config['host']) ? null : self::$td_config['host']; $port = empty(self::$td_config['port']) ? null : self::$td_config['port']; $options = empty(self::$td_config['options']) ? array() : self::$td_config['options']; $packer = empty(self::$td_config['packer']) ? null : self::$td_config['packer']; $database = empty(self::$td_config['database']) ? 'default' : self::$td_config['database']; $table_name = $obj->table(); \Fluent\Autoloader::register(); $logger = new \Fluent\Logger\FluentLogger($host, $port, $options, $packer); $res = $logger->post('td.' . $database . '.' . $table_name, $save_data); }
public static function write($level, $msg, $method = null) { $log_threshold = \Config::get('log_threshold'); $config = \Config::get('log', array()); if (isset($config['drivers']['td']['log_threshold'])) { $log_threshold = $config['drivers']['td']['log_threshold']; } if ($level > $log_threshold) { return false; } $levels = array(1 => 'Error', 2 => 'Warning', 3 => 'Debug', 4 => 'Info'); $level = isset($levels[$level]) ? $levels[$level] : $level; if (\Config::get('profiling')) { \Console::log($method . ' - ' . $msg); } $host = empty($config['drivers']['td']['host']) ? null : $config['drivers']['td']['host']; $port = empty($config['drivers']['td']['port']) ? null : $config['drivers']['td']['port']; $options = empty($config['drivers']['td']['options']) ? array() : $config['drivers']['td']['options']; $packer = empty($config['drivers']['td']['packer']) ? null : $config['drivers']['td']['packer']; $database = empty($config['drivers']['td']['database']) ? 'default' : $config['drivers']['td']['database']; $logger = new \Fluent\Logger\FluentLogger($host, $port, $options, $packer); $message = array(); $call = array(); if (!empty($method)) { $call['method'] = $method; } else { $backtrace = debug_backtrace(); $i = 0; for (; $i < count($backtrace); $i++) { $backtrace[$i]['object'] = null; $break = false; if (isset($backtrace[$i]['class'])) { if (!strstr($backtrace[$i]['class'], __NAMESPACE__) and !strstr($backtrace[$i]['class'], 'Fuel\\Core\\Log')) { // if ($level === 'Error') { $msg = print_r($backtrace, true); } $break = true; } } if ($break) { break; } } if (isset($backtrace[$i])) { $call['class'] = isset($backtrace[$i]['class']) ? $backtrace[$i]['class'] : 'null'; $call['type'] = isset($backtrace[$i]['type']) ? $backtrace[$i]['type'] : 'null'; $call['function'] = isset($backtrace[$i]['function']) ? $backtrace[$i]['function'] : 'null'; $call['line'] = isset($backtrace[$i - 1]['line']) ? $backtrace[$i - 1]['line'] : 'null'; } } $message['level'] = $level; $message['date'] = date(\Config::get('log_date_format')); $message['msg'] = $msg; $message['call'] = $call; $res = $logger->post('td.' . $database . '.fuel_log', $message); if (!$res) { return false; } return true; }