log

package
v0.0.1-6 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2023 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CloudWatchLogger

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

Logger that writes log messages to AWS Cloud Watch Log.

Configuration parameters

  • stream: (optional) Cloud Watch Log stream (default: context name)
  • group: (optional) Cloud Watch Log group (default: context instance ID or hostname)
  • connections:
  • discovery_key: (optional) a key to retrieve the connection from IDiscovery
  • region: (optional) AWS region
  • credentials:
  • store_key: (optional) a key to retrieve the credentials from ICredentialStore
  • access_id: AWS access/client id
  • access_key: AWS access/client id
  • options:
  • interval: interval in milliseconds to save current counters measurements (default: 5 mins)
  • reset_timeout: timeout in milliseconds to reset the counters. 0 disables the reset (default: 0)

References

  • \*:context-info:\*:\*:1.0 (optional) ContextInfo to detect the context id and specify counters source
  • \*:discovery:\*:\*:1.0 (optional) IDiscovery services to resolve connections
  • \*:credential-store:\*:\*:1.0 (optional) Credential stores to resolve credentials

See Counter (in the Pip.Services components package) See CachedCounters (in the Pip.Services components package) See CompositeLogger (in the Pip.Services components package)

Example:

	logger := NewLogger();
	logger.Configure(context.Background(), NewConfigParamsFromTuples(
	    "stream", "mystream",
	    "group", "mygroup",
	    "connection.region", "us-east-1",
	    "connection.access_id", "XXXXXXXXXXX",
	    "connection.access_key", "XXXXXXXXXXX",
	))
	logger.SetReferences(context.Background(), NewReferencesFromTuples(
	    NewDescriptor("pip-services", "logger", "console", "default", "1.0"),
	    NewConsoleLogger()
	))

	err:= logger.Open(context.Background(), "123")
	    ...

logger.SetLevel(Debug);

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

func NewCloudWatchLogger

func NewCloudWatchLogger() *CloudWatchLogger

Creates a new instance of this logger.

func (*CloudWatchLogger) Close

func (c *CloudWatchLogger) Close(ctx context.Context) error

Closes component and frees used resources.

Parameters:
	- ctx context.Context	execution context to trace execution through call chain.
	- Returns       error or nil no errors occured.

func (*CloudWatchLogger) Configure

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

Configure method configures component by passing configuration parameters.

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

func (*CloudWatchLogger) IsOpen

func (c *CloudWatchLogger) IsOpen() bool

Checks if the component is opened. Returns true if the component has been opened and false otherwise.

func (*CloudWatchLogger) Open

func (c *CloudWatchLogger) Open(ctx context.Context) error

Opens the component. Parameters:

  • ctx context.Context execution context to trace execution through call chain.
  • Returns error or nil no errors occured.

func (*CloudWatchLogger) Save

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

Saves log messages from the cache.

Parameters:
	- ctx context.Context	operation context.
	- messages  a list with log messages
	- Returns   error or nil for success.

func (*CloudWatchLogger) SetReferences

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

SetReferences method sets references to dependent components.

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

See IReferences (in the Pip.Services commons package)

func (*CloudWatchLogger) Write

func (c *CloudWatchLogger) Write(ctx context.Context, level clog.LevelType, ex error, message string)

Writes a log message to the logger destination.

Parameters:
	- ctx context.Context	execution context to trace execution through call chain.
	- level             a log level.
	- error             an error object associated with this message.
	- message           a human-readable message to log.

Jump to

Keyboard shortcuts

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