Chat Logging in PHP / Linux

Discussion in 'Starbound Modding' started by Ayeso, Dec 6, 2013.

  1. Netist

    Netist Orbital Explorer

    Welcome to Linux.
     
  2. Halaster

    Halaster Space Spelunker

    Thanks to both The_Fool and Netist.
    May not be as clean as you would both do it, but with the input from you both it should be much more secure and more useful as well for me now with the additional timing information added to chat. I had not really used sed really much before. A few years at least.

    I ended up doing a slight combination of the two:

    Code:
    tail -F /root/steam/starbound/linux64/starbound_server.log | sed -n '/^Info:\s\+\ / {
    s/Info/Chat/ig
    s/&/\&/ig
    s/</\&lt;/ig
    s/>/\&gt;/ig
    x
    s/^.*$/date +"%G-%m-%d %H:%M:%S | "/
    e
    G
    s/\n//
    p
    x
    }
    '
    That script is running in a screen I can easily start and stop, and the screen outputs to chat.log, which is what I am parsing with my PHP now.
    The PHP was modified to be much more simple as well using:
    PHP:
    <?PHP
    $file_handle 
    fopen("/log/chat.log""r");

    while (!
    feof($file_handle))
            {
            
    $chat_line fgets($file_handle);
            echo 
    $chat_line"<br>";
            }
    fclose($file_handle);

    ?>
     

Share This Page