PHP code example of sohelaman / hello-log

1. Go to this page and download the library: Download sohelaman/hello-log 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/ */

    

sohelaman / hello-log example snippets


// Composer autoload
og;

// Create a HelloLog instance
$hellolog = new HelloLog('/home/sohel/Documents/Logfile.log');

// Simply print a message, this will not put message in log file
$hellolog->msg('Arthur Curry, I hear you can talk to fish.');

// Put some info in log file
$data = "Luke, I am your father!";
$hellolog->info($data);

// AND YESS!! There are shortcuts too!
$data = array("Diana" => "He said he'll fight with us?", "Bruce" => "More or less.");
$hellolog->i($data); // Same as info()

// Similarly put error or warning into the log
$hellolog->warn("So, you're fast?");
$hellolog->error("That feels like an over simplification.");

// Pass array or object
$hellolog->i($_SERVER);

// Return output instead of putting into log. Pass true as second parameter.
echo $hellolog->i("I'm real when it's useful.", true); // Prints instead of putting into log

$hellolog = new HelloLog();

$hellolog = new HelloLog(<file path>, <file segmentation>);
$hellolog = new HelloLog('/home/sohel/Documents/Logfile.log', 'DAY');

$hellolog = new HelloLog(<file path>, <file segmentation>, <overwrite flag>);
$hellolog = new HelloLog('/home/sohel/Documents/Logfile.log', 'DAY', true);

$hellolog->overwrite(false); // Turns off overwrite flag. So, logs will be appended after this call.
$hellolog->overwrite(true); // Turns on overwrite flag.

$hellolog->setPath('/var/www/logs/New.log');
$hellolog->setSeg('MINUTE'); // 'NONE', 'YEAR', 'MONTH', 'DAY', 'HOUR', 'MINUTE', 'SECOND'

$path = $hellolog->getPath();
$seg = $hellolog->getSeg();

$data = 'I can do this all day!';
$hellolog->info($data); // General info, uses print_r() output
$hellolog->error($data);
$hellolog->warn($data);
$hellolog->debug($data); // Extensive debug, uses var_export() output
$hellolog->json($_SERVER); // Uses JSON string

$hellolog->i($data);
$hellolog->d($data);
$hellolog->j($data);
$hellolog->e($data);
$hellolog->w($data);

$output = $hellolog->d($data, true);
$output = $hellolog->j($data, true);

$hellolog->ugly(); // Disables <pre> wrapper
$hellolog->pretty();

$serverJSON = $hellolog->j($_SERVER, true, true); // Returns JSON string of $_SERVER variable.

echo $hellolog->count(); // Increments the counter by one

echo $hellolog->count('DEC'); // Decrements the counter by one
echo $hellolog->count('RESET'); // Resets the counter to zero
echo $hellolog->count('GET'); // Get the current counter value

$hellolog->time();
echo $hellolog->time(true);

$hellolog->msg('Winter is coming!');
$hellolog->msg(); // This will simply print 'Hello, World!'
<pre>