1. Go to this page and download the library: Download marck-devs/simple-logger library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
marck-devs / simple-logger example snippets
LogLevels::log_level_from_string("debug");
class Foo{
private static $log;
public function __construct(){
self::$log = new \MarckDevs\SimpleLogger\SimpleLogger("name", \MarckDevs\SimpleLogger\LogLeves::WARN);
}
public function fun(){
self::$log->log("My message is {message}", ["message" => "hello"]);
self::$log->warn("My message is {test}", ["test" => "test"]);
self::$log->debug("My {cnt} is {message}", ["message" => "hello", "ctn"=>"message"]);
self::$log->error("My message is {message}", ["message" => "hello"]);
}
}
class MyFormatter implements \MarckDevs\SimpleLogger\Interfaces\LogFormatter{
public function format($string, $data = []){
$my_format = "{date}- {lv}- {msg}";
// generate the array with the necessaries keys
$arr = \MarkDevs\SimpleLogger\SimpleFormatter::gen_arr($string, $data);
// format the string
return \MarkDevs\SimpleLogger\SimpleFormatter::set_data($string, $arr);
}
}
class MyDateFormatter implements\MarckDevs\SimpleLogger\Interfaces\DateFormatter{
public function get_date($date /*DateTime object*/): String {
// custom format
$format = "Y-m-d H:i:s"; // php format
return $date->format($format);
}
}