php發送log至syslog server

範例

<?php
function BSD_Syslog($msg,$severity=7, $program="php-test",$remote_ip='127.0.0.1',$remote_port=514){
  date_default_timezone_set('Asia/Taipei');
  $facility=5;
  $severity=7;
  $PRI = $facility*8+$severity;
  $HEADER=date('M d H:i:s ') . $program;
  $syslog_message = "<{$PRI}>{$HEADER} {$msg}";
  $sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
  socket_sendto($sock, $syslog_message, strlen($syslog_message), 0, $remote_ip, (int)$remote_port);
  socket_close($sock);
}
BSD_Syslog("test: ".rand()%10000);

其中facility的值如下:

         Code

          0             kernel messages
          1             user-level messages
          2             mail system
          3             system daemons
          4             security/authorization messages
          5             messages generated internally by syslogd
          6             line printer subsystem
          7             network news subsystem
          8             UUCP subsystem
          9             clock daemon
         10             security/authorization messages
         11             FTP daemon
         12             NTP subsystem
         13             log audit
         14             log alert
         15             clock daemon (note 2)
         16             local use 0  (local0)
         17             local use 1  (local1)
         18             local use 2  (local2)
         19             local use 3  (local3)
         20             local use 4  (local4)
         21             local use 5  (local5)
         22             local use 6  (local6)
         23             local use 7  (local7)

severity的值如下:


         Code
          0       Emergency: system is unusable
          1       Alert: action must be taken immediately
          2       Critical: critical conditions
          3       Error: error conditions
          4       Warning: warning conditions
          5       Notice: normal but significant condition
          6       Informational: informational messages
          7       Debug: debug-level messages

在macos使用qemu安裝windows

安裝Qemu

brew install qemu

建立硬碟

qemu-img create -f raw ~/qemu/disk.img 20G
qemu-img info ~/qemu/disk.img

修正Qemu錯誤

原生安裝好的qemu執行虛擬機時,會出現qemu-system-x86_64: Error: HV_ERROR的錯誤,
修正方式如下:

# 參考 https://stackoverflow.com/a/64993771/4802467
cat << EOF > app.entitlements
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>com.apple.security.hypervisor</key>
    <true/>
</dict>
</plist>
EOF
md5 $(which qemu-system-x86_64)
codesign -s - --entitlements app.entitlements --force $(which qemu-system-x86_64)
md5 $(which qemu-system-x86_64)
rm -f app.entitlements

開啟虛擬機

qemu-system-x86_64 \
  -m 4G \
  -vga virtio \
  -display default,show-cursor=on \
  -usb \
  -device usb-tablet \
  -machine type=q35,accel=hvf \
  -smp 2 \
  -drive file=/Users/slanla/qemu/disk.img,index=0,format=raw,if=virtio \
  -drive file=windows.iso,index=1,media=cdrom \
  -drive file=virtio-win-drivers-20120712-1.iso,index=2,media=cdrom \
  -cpu Nehalem

資源下載

virtio-win-drivers-20120712-1.iso