HLDSLogs v0.1.1 HLDSLogs.LogProducer View Source

A GenStage producer that connects to a HLDS server and sets up log forwarding to itself. Should only be calling this module directly if you want to manage the supervision of these processes yourself, otherwise the functions in HLDSLogs will create processes under a dynamic supervisor.

When a process is started, it is provided with host:port informtion for the HLDS server, and self-referenial host:port information to provide to the HLDS server. The self-referencial host information must be reachable from the HLDS server.

Log Forwarding

HLDS provides a mechanisim for forwarding logged messages over UDP to a designated host:port. This is set up with the logaddress console commands. This module will use HLDSRcon to set up an rcon connection to the HLDS server, then it will issue the logaddress_add command with the self-referencial host information it was provided - this will cause HLDS to forward all log entries to this process.

Producer

This producer will create a single event, represented by the HLDSLogs.LogEntry struct, for each log entry it recieves. It does not respond to consumer demand, and instead creates events as soon as possible, based on the log activity from the HLDS server.

Example Consumer

This example module is set up to simply forward log bodies from HLDS to Logger.info/1.

defmodule LoggerConsumer do
  use GenStage

  require Logger

  def start_link() do
    GenStage.start_link(__MODULE__, :ok)
  end

  def init(:ok) do
    {:consumer, nil}
  end

  def handle_events(events, _from, nil) do
    events
    |> Enum.map(fn log_entry -> log_entry.body end)
    |> Enum.map(&Logger.info/1)
    {:noreply, [], nil}
  end
end

Link to this section Summary

Functions

Get the UDP port used by the processes socket to recieve log messages. Useful to determine port when OS assigned

Creates a producer that will connect to the server

Link to this section Functions

Link to this function handle_call(atom, from, state) View Source

Get the UDP port used by the processes socket to recieve log messages. Useful to determine port when OS assigned.

Link to this function start_link(arg) View Source
start_link(
  {%HLDSRcon.ServerInfo{host: term(), password: term(), port: term()},
   %HLDSLogs.ListenInfo{host: term(), port: term()}}
) :: GenServer.on_start()

Creates a producer that will connect to the server.

Server and listener information is given in a tuple, where the first element is a HLDSRcon.ServerInfo struct defining the HLDS host:port information, and the second element in the tuple is a HLDSLogs.ListenInfo struct defining the host:port information for this process.

The HLDSLogs.ListenInfo struct is used to create a UDP socket by this process, and for informing the HLDS server where to forward logs. If a port is not specified, a port will be select by the OS.