log

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2022 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ElasticSearchLogger

type ElasticSearchLogger struct {
	*clog.CachedLogger
	// contains filtered or unexported fields
}

ElasticSearchLogger is logger that dumps execution logs to ElasticSearch service. ElasticSearch is a popular search index. It is often used to store and index execution logs by itself or as a part of ELK (ElasticSearch - Logstash - Kibana) stack.

Authentication is not supported in this version.

Configuration parameters:

- level: maximum log level to capture - source: source (context) name - connection(s):

  • discovery_key: (optional) a key to retrieve the connection from IDiscovery
  • protocol: connection protocol: http or https
  • host: host name or IP address
  • port: port int
  • uri: resource URI or connection string with all parameters in it

- options:

  • interval: interval in milliseconds to save log messages (default: 10 seconds)
  • max_cache_size: maximum int of messages stored in this cache (default: 100)
  • index: ElasticSearch index name (default: "log")
  • daily: true to create a new index every day by adding date suffix to the index (default: false)
  • reconnect: reconnect timeout in milliseconds (default: 60 sec)
  • timeout: invocation timeout in milliseconds (default: 30 sec)
  • max_retries: maximum int of retries (default: 3)
  • index_message: true to enable indexing for message object (default: false)
  • include_type_name: Will create using a "typed" index compatible with ElasticSearch 6.x (default: false)

References:

- *:context-info:*:*:1.0 (optional) ContextInfo to detect the context id and specify counters source - *:discovery:*:*:1.0 (optional) IDiscovery services to resolve connection

Example:

logger := NewElasticSearchLogger();
logger.Configure(contex.Background(), cconf.NewConfigParamsFromTuples(
    "connection.protocol", "http",
    "connection.host", "localhost",
    "connection.port", "9200"
));

logger.Open(contex.Background(), "123")

logger.Error(contex.Background(), "123", ex, "Error occured: %s", ex.message);
logger.Debug(contex.Background(), "123", "Everything is OK.");

func NewElasticSearchLogger

func NewElasticSearchLogger() *ElasticSearchLogger

NewElasticSearchLogger method creates a new instance of the logger. Retruns *ElasticSearchLogger pointer on new ElasticSearchLogger

func (*ElasticSearchLogger) Close

func (c *ElasticSearchLogger) Close(ctx context.Context, correlationId string) (err error)

Close method are closes component and frees used resources.

Parameters:
	- ctx context.Context	operation context
	- correlationId  string	(optional) transaction id to trace execution through call chain.

Returns error or nil, if no errors occured.

func (*ElasticSearchLogger) Configure

func (c *ElasticSearchLogger) Configure(ctx context.Context, config *cconf.ConfigParams)

Configure are configures component by passing configuration parameters.

Parameters:
	- ctx context.Context	operation context
	- config  *cconf.ConfigParams   configuration parameters to be set.

func (*ElasticSearchLogger) IsOpen

func (c *ElasticSearchLogger) IsOpen() bool

IsOpen method are checks if the component is opened. Returns true if the component has been opened and false otherwise.

func (*ElasticSearchLogger) Open

func (c *ElasticSearchLogger) Open(ctx context.Context, correlationId string) (err error)

Open method are ppens the component.

Parameters:
	- ctx context.Context	operation context
	- correlationId string 	(optional) transaction id to trace execution through call chain.

Returns error or nil, if no errors occured.

func (*ElasticSearchLogger) Save

func (c *ElasticSearchLogger) Save(ctx context.Context, messages []clog.LogMessage) (err error)

Save method are saves log messages from the cache.

Parameters:
	- ctx context.Context	operation context
	- messages []clog.LogMessage a list with log messages

Retruns error or nil for success.

func (*ElasticSearchLogger) SetReferences

func (c *ElasticSearchLogger) SetReferences(ctx context.Context, references cref.IReferences)

SetReferences method are sets references to dependent components.

Parameters:
	- ctx context.Context	operation context
	- references cref.IReferences 	references to locate the component dependencies.

Jump to

Keyboard shortcuts

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