<?php

if (!defined('BASEPATH')) {
    exit('No direct script access allowed');
}

if (!function_exists('logger_add')) {

    function logger_add($key, $value = '')
    {
        // Prepare value
        if (is_array($value)) {
            $value = print_r($value, TRUE);
        } elseif (is_object($value)) {
            ob_start();
            var_dump($value);
            $value = ob_get_clean();
        } elseif (is_bool($value)){
            $value = ($value) ? 'TRUE' : 'FALSE';
        } elseif (is_null($value)){
            $value = 'NULL';
        } else {
            $value = (string) $value;
        }

        $ci = & get_instance();
        $db = clone $ci->db;
        $data = array(
            'key' => $key,
            'value' => $value,
            'ip' => $ci->input->ip_address(),
            'date' => date('Y-m-d H:i:s'),
        );
        $db->insert('logger', $data);

        return $db->insert_id();
    }

}