Skip to content

Commit

Permalink
Initial import.
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh Nesbitt committed Aug 13, 2009
0 parents commit 5d9e920
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 0 deletions.
20 changes: 20 additions & 0 deletions MIT-LICENSE
@@ -0,0 +1,20 @@
Copyright (c) 2009 [name of plugin creator]

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
80 changes: 80 additions & 0 deletions lib/logger.php
@@ -0,0 +1,80 @@
<?php
/**
* Simple Logger Class
* @author Josh Nesbitt <josh@josh-nesbitt.net>
*
* By default will write to /log/filename.log
*
**/
class Logger {
var $file, $level, $stream;
const INFO = 4;
const WARN = 3;
const DEBUG = 2;
const ERROR = 1;
const FATAL = 0;

function __construct($file, $level)
{
$this->file = $file;
$this->level = $level;
$this->stream = fopen($_SERVER["DOCUMENT_ROOT"] . "/log/$this->file", "a") or die("Cannot write to file '$this->path'");
}

function info($string)
{
if($this->level < self::INFO) return true;
$this->log($string);
}

function warn($string)
{
if($this->level < self::WARN) return true;
$this->log($string);
}

function debug($string)
{
if($this->level < self::DEBUG) return true;
$this->log($string);
}

function error($string)
{
if($this->level < self::ERROR) return true;
$this->log($string);
}

function fatal($string)
{
if($this->level < self::FATAL) return true;
$this->log($string);
}

private function log($string)
{
$this->write("[". date('l jS F Y : h:i:sa') . "] ". $string . "\r\n");
}

private function write($string)
{
return fwrite($this->stream, $string);
}

private function cut()
{
return fclose($this->stream);
}
}

$logger = new Logger("development.log", Logger::INFO);

$logger->info("--> info");
$logger->warn("--> warn");
$logger->debug("--> debug");
$logger->error("--> error");
$logger->fatal("--> fatal");

# TODO: finish me...

?>
7 changes: 7 additions & 0 deletions readme.rdoc
@@ -0,0 +1,7 @@
= Logger

A simple PHP logger class. Because sometimes you only need something simple.

$logger = new Logger("development.log", Logger::INFO);

$logger->info("logging from the info level");

0 comments on commit 5d9e920

Please sign in to comment.