-
-
Save sawantuday/115d59b55af21b77e8f59a1666a36754 to your computer and use it in GitHub Desktop.
Send UDP remote syslog message from PHP (RFC 3164)
This file contains hidden or 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
# replace PAPERTRAIL_HOSTNAME and PAPERTRAIL_PORT | |
# see http://help.papertrailapp.com/ for additional PHP syslog options | |
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, PAPERTRAIL_HOSTNAME, PAPERTRAIL_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