Skip to content

Instantly share code, notes, and snippets.

@jeffwray
Forked from troy/send_remote_syslog.php
Created January 22, 2014 16:20
Show Gist options
  • Save jeffwray/8561731 to your computer and use it in GitHub Desktop.
Save jeffwray/8561731 to your computer and use it in GitHub Desktop.
function send_remote_syslog($message, $component = "web", $program = "next_big_thing") {
$sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
foreach(explode("\n", $message) as $line) {
$syslog_message = "<22>" . date('M d H:i:s ') . $program . ' ' . $component . ': ' . $line;
socket_sendto($sock, $syslog_message, strlen($syslog_message), 0, 'logs.papertrailapp.com', MY_PORT);
}
socket_close($sock);
}
send_remote_syslog("Test");
# send_remote_syslog("Any log message");
# send_remote_syslog("Something just happened", "other-component");
# send_remote_syslog("Something just happened", "a-background-job-name", "whatever-app-name");
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment