Add
{code} {code} == == * * _ _ [] * #

200

2017-01-12 15:02:51
class LogEm {
    const TILL_RETURN = 1;
    const TILL_COMMIT_ROLLBACK = 2;
    private $cb;
    static $log_id = null;
    function __construct($cb) {
        $this->cb = $cb;
    }
    function __destruct() {
        call_user_func_array($this->cb, [self::$log_id]);
        self::$log_id = null;
    }
    static function delLog() {
        Logs::delLog(CLASS_DB, self::$log_id);
    }
    static function sql($till, $file, $line, $msg = '') {
        file_put_contents('/tmp/emakhrov.log', sprintf("%s:%s %s\n", $file, $line, $msg), FILE_APPEND);
        if (self::$log_id !== null) return null;
        self::$log_id = \Logs::addLog(CLASS_DB, new LogFile('/tmp/sql_emakhrov.log'));
        if ($till == self::TILL_RETURN) return new self(array(__CLASS__, 'delLog'));
        ConnectionManager::addCommitCallBack(array(__CLASS__, 'delLog'), []);
        ConnectionManager::addRollbackCallBack(array(__CLASS__, 'delLog'), []);
    }
}


examples:
$ololo = LogEm::SQL(LogEm::TILL_RETURN, __METHOD__, __LINE__, $this->real_command);

LogEm::sql(LogEm::TILL_COMMIT_ROLLBACK, __FILE__, __LINE__);