socket

package module
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 8, 2019 License: Apache-2.0 Imports: 14 Imported by: 0

README

socker2stdout

Listen on a TCP or Unix socket and send to stdout.

Why?

This was written to handle wanting to write to stdout from inside a container from a PHP application. However, php-fpm prefixes each line with a preamble. So, this allows one to configure PHP loggers - such as monolog - to log to a tcp socket and still capture stdout.

socket2stdout handles log lines greater than PIPE_BUF. Some tools may interleave lines with large messages.

Usage

$ ./socket2stdout -h
copy lines from a socket to stdout

Usage:
  socket2stdout [flags]

Flags:
      --addr string       tcp address (default "127.0.0.1:4444")
      --aux-addr string   listen address for aux handler. metrics, healthchecks, etc (default ":9090")
      --unix string       unix address. takes precedence if both unix and tcp are set

An example using monolog to log to this socket:

$logger = new Monolog\Logger("example");
$handler = new Monolog\Handler\SocketHandler('tcp://127.0.0.1:1313');
$formatter = new Monolog\Formatter\JsonFormatter();
$handler->setFormatter($formatter);
$logger->pushHandler($handler);

Building

go build .

Also availible at https://quay.io/repository/bakins/socket2stdout

Documentation

Overview

Package socket implements a simple server that copies line buffered content from a socket to stdout.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetAuxAddress

func SetAuxAddress(addr string) func(*Server) error

SetAuxAddress will set the address for the metrics listener.

func SetTCPAddress

func SetTCPAddress(addr string) func(*Server) error

SetTCPAddress will set the TCP address to accept line oriented data. Only TCP or Unix address may be set. If both are set, Unix takes precedence.

func SetUnixAddress

func SetUnixAddress(addr string) func(*Server) error

SetUnixAddress will set the Unix address to accept line oriented data. Only TCP or Unix address may be set. If both are set, Unix takes precedence.

Types

type OptionsFunc

type OptionsFunc func(*Server) error

OptionsFunc is a function passed to new for setting options on a new server.

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server copies data from a socket to stdout

func New

func New(options ...OptionsFunc) (*Server, error)

New creates a new server

func (*Server) Run

func (s *Server) Run() error

Run will start the listener. This will run until a SIGINT or SIGTERM are received.

func (*Server) Stop

func (s *Server) Stop()

Stop will stop the server

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL