Skip to content

Commit

Permalink
Final commit before V1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Tjoosten authored and Tjoosten committed Feb 4, 2015
1 parent c986e40 commit 1a3f735
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 96 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.DS_Store
96 changes: 0 additions & 96 deletions Logger-helper.php

This file was deleted.

2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# User-logger-codeigniter

A simple lightweight logging system for user handlings in Codeigniter.
23 changes: 23 additions & 0 deletions config/logger_config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

/**
* The configuration file for the logger helper.
*
* @package Logge helper.
* @copyright Tim Joosten
* @since V1.0.0
*
* -----------------------------------------------------
* EXPLANATION OF THE VARIABLES.
* -----------------------------------------------------
*
* $config['chmod'] = The chmod rights.
* $config['date_format'] = The date notification for the file name. (it will convert to timestamp).
* $config['time_format'] = The time format for the time notifications in the file.
*
*/

$config['chmod'] = "777";

$config['date_format'] = "Y/m/d";
$config['time_format'] = "h:i:sa";
66 changes: 66 additions & 0 deletions helpers/logger_helper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php defined('BASEPATH') OR exit('No direct script access allowed');

/**
* @package Logger
* @author Tim Joosten
* @license Closed source license
* @since 2015
*/

/**
* Constructor
*/
function __construct() {
parent::__construct();
}

/**
* log_user
*
* Log the user handling to the file.
*
* @param $user, string, the user doing the handle.
* @param $message, string, the handling the user is doing.
*/
if (! function_exists('user_log')) {
function user_log($user, $message) {
// Set instance and load config.
$CI =& get_instance();
$CI->load->config('logger_config', TRUE);

$Date = strtotime(date($CI->config->item('date_format')));

$Filepath = './application/logs/log-'. $Date .'.php';

if(! file_exists($Filepath)) {
// File doesn't exists so we need to first write it.
$Fileheader = "<?php defined('BASEPATH') OR exit('No direct script access allowed'); ?>\n\n";
$LogMessage = '['. date($CI->config->item('time_format')). ']: '. $user .' --> '. $message ."\n";

// Open the log file
$Logfile = fopen($Filepath, "a");

// Write to the file.
fwrite($Logfile, $Fileheader);
fwrite($Logfile, $LogMessage);
// Close file
fclose($Logfile);

// Setting rights to the file
chmod($Filepath, $CI->config->item('chmod'));

return TRUE;
} else {
// The file exists sp we are write te log message only.
$LogMessage = '['. date($CI->config->item('time_format')). ']: '. $user .' --> '. $message ."\n";

// Open the log file
$Logfile = fopen($Filepath, "a");

// Write to the file.
fwrite($Logfile, $LogMessage);
// Close file
fclose($Logfile);
}
}
}

0 comments on commit 1a3f735

Please sign in to comment.