-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Tjoosten
authored and
Tjoosten
committed
Feb 4, 2015
1 parent
c986e40
commit 1a3f735
Showing
5 changed files
with
92 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.DS_Store |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |