logger

package module
v0.0.0-...-12585ad Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2022 License: MIT Imports: 10 Imported by: 0

README

RRv2 Logger plugin

PHP Client

Roadrunner Worker

Configuration
# Logging settings (docs: https://roadrunner.dev/docs/beep-beep-logging)
logs:
  # Logging mode can be "development", "production" or "raw". Do not forget to change this value for production environment.
  #
  # Development mode (which makes DPanicLevel logs panic), uses a console encoder, writes to standard error, and
  # disables sampling. Stacktraces are automatically included on logs of WarnLevel and above.
  #
  # Default: "development"
  mode: development

  # Logging level can be "panic", "error", "warn", "info", "debug".
  #
  # Default: "debug"
  level: debug

  # Encoding format can be "console" or "json" (last is preferred for production usage).
  #
  # Default: "console"
  encoding: console

  # Output can be file (eg.: "/var/log/rr_errors.log"), "stderr" or "stdout".
  #
  # Default: "stderr"
  output: stderr

  # Errors only output can be file (eg.: "/var/log/rr_errors.log"), "stderr" or "stdout".
  #
  # Default: "stderr"
  err_output: stderr

  # You can configure each plugin log messages individually (key is plugin name, and value is logging options in same
  # format as above).
  #
  # Default: <empty map>
  channels:
    http:
      mode: development
      level: panic
      encoding: console
      output: stdout
      err_output: stderr
    server:
      mode: production
      level: info
      encoding: json
      output: stdout
      err_output: stdout
    rpc:
      mode: raw
      level: debug
      encoding: console
      output: stderr
      err_output: stdout
Minimal dependencies:
  1. Config plugin to read and populate plugin's configuration.
Worker sample:
<?php

require __DIR__ . '/vendor/autoload.php';

// Create a new Worker from global environment
$worker = \Spiral\RoadRunner\Worker::create();

while ($data = $worker->waitPayload()) {
    // Received Payload
    var_dump($data);

    // Respond Answer
    $worker->respond(new \Spiral\RoadRunner\Payload('DONE'));
}
Tips:
  1. Use development logger mode only for the dev. It uses more resources even with panic level and not suitable for the production.
  2. You can configure log parameters for the every plugin you use (see: channels in the configuration)

Documentation

Index

Constants

View Source
const PluginName = "logs"

PluginName declares plugin name.

Variables

This section is empty.

Functions

func ColoredLevelEncoder

func ColoredLevelEncoder(level zapcore.Level, enc zapcore.PrimitiveArrayEncoder)

ColoredLevelEncoder colorizes log levels.

func ColoredNameEncoder

func ColoredNameEncoder(s string, enc zapcore.PrimitiveArrayEncoder)

ColoredNameEncoder colorizes service names.

Types

type ChannelConfig

type ChannelConfig struct {
	// Dedicated channels per logger. By default logger allocated via named logger.
	Channels map[string]Config `mapstructure:"channels"`
}

ChannelConfig configures loggers per channel.

type Config

type Config struct {
	// Mode configures logger based on some default template (development, production, off).
	Mode Mode `mapstructure:"mode"`

	// Level is the minimum enabled logging level. Note that this is a dynamic
	// level, so calling ChannelConfig.Level.SetLevel will atomically change the log
	// level of all loggers descended from this config.
	Level string `mapstructure:"level"`

	// Logger line ending. Default: "\n" for the all modes except production
	LineEnding string `mapstructure:"line_ending"`

	// Encoding sets the logger's encoding. InitDefault values are "json" and
	// "console", as well as any third-party encodings registered via
	// RegisterEncoder.
	Encoding string `mapstructure:"encoding"`

	// Output is a list of URLs or file paths to write logging output to.
	// See Open for details.
	Output []string `mapstructure:"output"`

	// ErrorOutput is a list of URLs to write internal logger errors to.
	// The default is standard error.
	//
	// Note that this setting only affects internal errors; for sample code that
	// sends error-level logs to a different location from info- and debug-level
	// logs, see the package-level AdvancedConfiguration example.
	ErrorOutput []string `mapstructure:"errorOutput"`

	// File logger options
	FileLogger *FileLoggerConfig `mapstructure:"file_logger_options"`
}

func (*Config) BuildLogger

func (cfg *Config) BuildLogger() (*zap.Logger, error)

BuildLogger converts config into Zap configuration.

func (*Config) InitDefault

func (cfg *Config) InitDefault()

InitDefault Initialize default logger

type FileLoggerConfig

type FileLoggerConfig struct {
	// Filename is the file to write logs to.  Backup log files will be retained
	// in the same directory.  It uses <processname>-lumberjack.log in
	// os.TempDir() if empty.
	LogOutput string `mapstructure:"log_output"`

	// MaxSize is the maximum size in megabytes of the log file before it gets
	// rotated. It defaults to 100 megabytes.
	MaxSize int `mapstructure:"max_size"`

	// MaxAge is the maximum number of days to retain old log files based on the
	// timestamp encoded in their filename.  Note that a day is defined as 24
	// hours and may not exactly correspond to calendar days due to daylight
	// savings, leap seconds, etc. The default is not to remove old log files
	// based on age.
	MaxAge int `mapstructure:"max_age"`

	// MaxBackups is the maximum number of old log files to retain.  The default
	// is to retain all old log files (though MaxAge may still cause them to get
	// deleted.)
	MaxBackups int `mapstructure:"max_backups"`

	// Compress determines if the rotated log files should be compressed
	// using gzip. The default is not to perform compression.
	Compress bool `mapstructure:"compress"`
}

FileLoggerConfig structure represents configuration for the file logger

func (*FileLoggerConfig) InitDefaults

func (fl *FileLoggerConfig) InitDefaults() *FileLoggerConfig

type Mode

type Mode string

Mode represents available logger modes

type StdLogAdapter

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

StdLogAdapter can be passed to the http.Server or any place which required standard logger to redirect output to the logger plugin

func NewStdAdapter

func NewStdAdapter(log *zap.Logger) *StdLogAdapter

NewStdAdapter constructs StdLogAdapter

func (*StdLogAdapter) Write

func (s *StdLogAdapter) Write(p []byte) (n int, err error)

Write io.Writer interface implementation

type ZapLogger

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

ZapLogger manages zap logger.

func (*ZapLogger) Init

func (z *ZapLogger) Init(cfg config.Configurer) error

Init logger service.

func (*ZapLogger) Name

func (z *ZapLogger) Name() string

Name returns user-friendly plugin name

func (*ZapLogger) NamedLogger

func (z *ZapLogger) NamedLogger(name string) (*zap.Logger, error)

NamedLogger returns logger dedicated to the specific channel. Similar to Named() but also reads the core params.

func (*ZapLogger) Provides

func (z *ZapLogger) Provides() []interface{}

Provides declares factory methods.

func (*ZapLogger) Serve

func (z *ZapLogger) Serve() chan error

func (*ZapLogger) ServiceLogger

func (z *ZapLogger) ServiceLogger(n endure.Named) (*zap.Logger, error)

ServiceLogger returns logger dedicated to the specific channel. Similar to Named() but also reads the core params.

func (*ZapLogger) Stop

func (z *ZapLogger) Stop() error

Jump to

Keyboard shortcuts

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