All pages
Powered by GitBook
1 of 3

Loading...

Loading...

Loading...

Loggers

An extra library of logger implementations that are not included in the standard Ergo Framework library. This library contains packages with a narrow specialization. It also includes packages that have external dependencies, as Ergo Framework adheres to a "zero dependency" policy

Colored

This package implements the gen.LoggerBehavior interface and provides the ability to output log messages to standard output with color highlighting.

Below is a demonstration of log messages (from nodes, processes, and meta-processes) with different logging levels:

Format

<time> <level> <log source> [process name] [process behavior]: <log message>

When logging, the package also highlights in color the types gen.Atom, gen.PID, gen.ProcessID, gen.Ref, gen.Alias, gen.Event.

Available options

Sets the format for the timestamp of log messages. You can use any existing format (see ) or define your own. By default, the time is displayed in nanoseconds

  • ShortLevelName Displays the shortened name of the log level

  • IncludeBehavior Includes the name of the process behavior in the log message

  • IncludeName includes the registered name of the process in the log message

Example

This package is not intended for use with intensive logging and may impact node performance. For log messages with the level gen.LogLevelTrace, color highlighting is applied only to the timestamp and the source of the log message; color highlighting is turned off for the body of the log message

time package
package main

import (
	"ergo.services/ergo"
	"ergo.services/ergo/gen"

	"ergo.services/logger/colored"
)

func main() {
	logger := gen.Logger{
		Name:   "colored",
		Logger: colored.CreateLogger(colored.Options{}),
	}

	nopt := gen.NodeOptions{}
	nopt.Log.Loggers = []gen.Logger{logger}
	
	// disable default logger to get rid of duplicating log-messages
	nopt.Log.DefaultLogger.Disable = true

	node, err := ergo.StartNode("demo@localhost", nopt)
	if err != nil {
		panic(err)
	}
	node.Log().Warning("Hello World!!!")
	node.Wait()
}

Rotate

This package implements the gen.LoggerBehavior interface and provides the capability to log messages to a file, with support for log file rotation at a specified interval.

Available options

  • Period Specifies the rotation period (minimum value: time.Minute)

  • TimeFormat Sets the format for the timestamp in log messages. You can choose any existing format (see ) or define your own. By default, timestamps are in nanoseconds

  • IncludeBehavior includes the process behavior in the log

  • IncludeName includes the registered process name

  • ShortLevelName enables shortnames for the log levels

  • Path directory for the log files, default: ./log

  • Prefix defines the log files name prefix (<Path>/<Prefix>.YYYYMMDDHHMi.log[.gz])

  • Compress Enables gzip compression for log files

  • Depth Specifies the number of log files in rotation

Example

time package
package main

import (
	"time"

	"ergo.services/ergo"
	"ergo.services/ergo/gen"
	"ergo.services/logger/rotate"
)

func main() {
	var options gen.NodeOptions
	ropt := rotate.Options{Period: time.Minute, Compress: false}
	rlog, err := rotate.CreateLogger(ropt)
	if err != nil {
		panic(err)
	}
	logger := gen.Logger{
		Name:   "rotate",
		Logger: rlog,
	}
	options.Log.Loggers = append(options.Log.Loggers, logger)

	node, err := ergo.StartNode("demo@localhost", options)
	if err != nil {
		panic(err)
	}
	node.Wait()
}