monolog

package module
v0.0.0-...-5e8dbaa Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2026 License: MIT Imports: 14 Imported by: 0

README

Monolog Server Plugin for RoadRunner

A RoadRunner plugin that provides a TCP server for receiving Monolog log records via the SocketHandler.

How it works

The plugin starts a TCP server that accepts newline-delimited JSON log records from Monolog's SocketHandler. Each received record is parsed and pushed to RoadRunner's Jobs plugin for processing by your PHP application.

Configuration

monolog:
  addr: ":9913"
  max_message_size: 10485760  # 10MB
  jobs:
    pipeline: "monolog"
    auto_ack: true
Configuration Options
Option Default Description
addr 127.0.0.1:9913 TCP server listen address
read_timeout 60s Connection read timeout
max_message_size 10485760 (10MB) Maximum message size in bytes
jobs.pipeline (required) Target Jobs pipeline name
jobs.priority 10 Default job priority
jobs.delay 0 Default job delay
jobs.auto_ack false Auto-acknowledge jobs

PHP Client Configuration

Configure Monolog's SocketHandler to send logs to this server:

use Monolog\Handler\SocketHandler;
use Monolog\Formatter\JsonFormatter;

$handler = new SocketHandler('tcp://127.0.0.1:9913');
$handler->setFormatter(new JsonFormatter());
$logger->pushHandler($handler);

Job Format

Each log record is pushed as a job named monolog.log with the following payload structure:

{
  "event": "LOG_RECEIVED",
  "uuid": "unique-id",
  "client_id": 1,
  "remote_addr": "127.0.0.1:54321",
  "received_at": "2024-01-01T00:00:00Z",
  "payload": {
    "message": "Log message",
    "context": {},
    "level": 200,
    "level_name": "INFO",
    "channel": "app",
    "datetime": "2024-01-01T00:00:00+00:00",
    "extra": {}
  },
  "project": "my-project"
}

License

MIT License. See LICENSE for details.

Documentation

Index

Constants

View Source
const (
	PluginName = "monolog"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// TCP server address (default port 9913)
	Addr string `mapstructure:"addr"`
	// Connection read timeout
	ReadTimeout time.Duration `mapstructure:"read_timeout"`
	// Maximum message size in bytes
	MaxMessageSize int64 `mapstructure:"max_message_size"`

	// Jobs integration
	Jobs JobsConfig `mapstructure:"jobs"`
}

Config represents Monolog server configuration

func (*Config) InitDefaults

func (c *Config) InitDefaults() error

InitDefaults sets default values for configuration

type Configurer

type Configurer interface {
	// UnmarshalKey takes a single key and unmarshal it into a Struct
	UnmarshalKey(name string, out any) error
	// Has checks if a config section exists
	Has(name string) bool
}

Configurer interface for configuration access

type Job

type Job struct {
	// Job contains name of job broker (usually PHP class)
	Job string `json:"job"`
	// Ident is unique identifier of the job
	Ident string `json:"id"`
	// Pld is the payload (usually JSON)
	Pld []byte `json:"payload"`
	// Hdr contains headers with key-value pairs
	Hdr map[string][]string `json:"headers"`
	// Options contains job execution options
	Options *JobOptions `json:"options,omitempty"`
}

Job represents a job message to be pushed to Jobs plugin Implements jobs.Message interface

func (*Job) AutoAck

func (j *Job) AutoAck() bool

func (*Job) Delay

func (j *Job) Delay() int64

func (*Job) GroupID

func (j *Job) GroupID() string

func (*Job) Headers

func (j *Job) Headers() map[string][]string

func (*Job) ID

func (j *Job) ID() string

func (*Job) Metadata

func (j *Job) Metadata() string

func (*Job) Name

func (j *Job) Name() string

func (*Job) Offset

func (j *Job) Offset() int64

func (*Job) Partition

func (j *Job) Partition() int32

func (*Job) Payload

func (j *Job) Payload() []byte

func (*Job) Priority

func (j *Job) Priority() int64

func (*Job) Topic

func (j *Job) Topic() string

func (*Job) UpdatePriority

func (j *Job) UpdatePriority(p int64)

type JobOptions

type JobOptions struct {
	// Priority is job priority, default - 10
	Priority int64 `json:"priority"`
	// Pipeline manually specified pipeline
	Pipeline string `json:"pipeline,omitempty"`
	// Delay defines time duration to delay execution for
	Delay int64 `json:"delay,omitempty"`
	// AutoAck use to ack a job right after it arrived from the driver
	AutoAck bool `json:"auto_ack"`
}

JobOptions carry information about how to handle given job

type Jobs

type Jobs interface {
	Push(ctx context.Context, msg jobs.Message) error
}

Jobs is the interface provided by Jobs plugin for pushing jobs

type JobsConfig

type JobsConfig struct {
	Pipeline string `mapstructure:"pipeline"` // Target pipeline in Jobs
	Priority int64  `mapstructure:"priority"` // Default priority for jobs
	Delay    int64  `mapstructure:"delay"`    // Default delay (0 = immediate)
	AutoAck  bool   `mapstructure:"auto_ack"` // Auto-acknowledge jobs
}

JobsConfig configures Jobs plugin integration

type LogRecord

type LogRecord struct {
	Event      string         `json:"event"`             // Always "LOG_RECEIVED"
	UUID       string         `json:"uuid"`              // Unique log record identifier
	ClientID   int            `json:"client_id"`         // TCP connection ID
	RemoteAddr string         `json:"remote_addr"`       // Client IP:port
	ReceivedAt time.Time      `json:"received_at"`       // Server timestamp
	Payload    map[string]any `json:"payload"`           // Parsed Monolog JSON record
	Project    *string        `json:"project,omitempty"` // Project name (from context)
	Error      *string        `json:"error,omitempty"`   // Parse error if any
}

LogRecord represents a parsed Monolog log record for Jobs

type Logger

type Logger interface {
	NamedLogger(name string) *zap.Logger
}

Logger interface for dependency injection

type Plugin

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

Plugin is the Monolog server plugin

func (*Plugin) Collects

func (p *Plugin) Collects() []*dep.In

Collects declares dependencies on other plugins

func (*Plugin) Init

func (p *Plugin) Init(log Logger, cfg Configurer) error

Init initializes the plugin with configuration and logger

func (*Plugin) Name

func (p *Plugin) Name() string

Name returns plugin name for RoadRunner

func (*Plugin) Serve

func (p *Plugin) Serve() chan error

Serve starts the TCP server

func (*Plugin) Stop

func (p *Plugin) Stop(ctx context.Context) error

Stop gracefully stops the plugin

Jump to

Keyboard shortcuts

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