Created
July 12, 2010 06:26
-
-
Save jwpage/472181 to your computer and use it in GitHub Desktop.
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
<?php | |
/* log.txt format | |
--- | |
{ | |
'version' : 0.0.1 | |
} | |
--- | |
[2010-07-12T15:47:40+10:00] (0h, 0m, 11s) | |
*/ | |
define('LOG_FILE', 'log.txt'); | |
define('TIMEZONE', 'Australia/Brisbane'); | |
date_default_timezone_set(TIMEZONE); | |
$file = file_get_contents(LOG_FILE); | |
// Fetch any frontmatter from the beginning of the file. | |
// Uhh... for future use? | |
preg_match_all("/---$(.*)---$/mis", $file, $data); | |
$frontmatter = json_encode($data[1], true); | |
$c = preg_match_all("/\[(.*?)\][^\(]*$/", $file, $last_entry); | |
if($c > 0) { | |
$diff = time()-strtotime($last_entry[1][0]); | |
$hours = floor($diff/3600); | |
$mins = floor($diff%3600/60); | |
$secs = $diff%3600%60; | |
$log = " ({$hours}h, {$mins}m, {$secs}s)"; | |
} | |
unset($argv[0]); | |
$message = trim(implode(" ", $argv)); | |
if(strlen($message) > 0) { | |
if(strpos($message, "#") === false) { | |
echo "WARNING: I highly recommend you add hashtags to your messages.\n"; | |
} | |
$log .= "\n[".date('c')."]\t".$message; | |
} | |
file_put_contents(LOG_FILE, $log, FILE_APPEND); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment