{"modulePath":"github.com/smartcontractkit/chainlink-testing-framework","version":"v1.35.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package logstream\n\n## Constants\n\n```go\nconst NO_TEST = \"no_test\"\n```\n\n```go\nconst (\n\tShorteningFailedErr = \"failed to shorten Grafana URL\"\n)\n```\n\n## Functions\n\n```go\nfunc GetRegexMatchingProcessor(logStream *LogStream, pattern string) (*LogProcessor[int], LogProcessorFn[int], error)\n```\nGetRegexMatchingProcessor creates a LogProcessor that counts the number of logs matching a regex pattern. Function returns the LogProcessor, the processing function, and an error if the regex pattern is invalid.\n\n```go\nfunc NoOpConsumerFn(consumer *ContainerLogConsumer) error\n```\nNoOpConsumerFn is a no-op consumer function\n\n```go\nfunc ShortenUrl(grafanaUrl, urlToShorten, bearerToken string) (string, error)\n```\n\n## Types\n\n```go\ntype ConsumerConsumingFn = func(consumer *ContainerLogConsumer) error\n```\n\n```go\ntype ConsumerLogConsumingFn = func(consumer *ContainerLogConsumer, log LogContent) error\n```\n\n```go\ntype ContainerLogConsumer struct {\n\t// contains filtered or unexported fields\n}\n```\nContainerLogConsumer is a container log lines consumer\n\n```go\nfunc (g *ContainerLogConsumer) Accept(l tc.Log)\n```\nAccept accepts the log message from particular container and saves it to the temp gob file\n\n```go\nfunc (g *ContainerLogConsumer) GetContainer() LogProducingContainer\n```\nGetContainer returns the container that this consumer is connected to\n\n```go\nfunc (g *ContainerLogConsumer) GetStartTime() time.Time\n```\nGetStartTime returns the time of the first log line\n\n```go\nfunc (g *ContainerLogConsumer) MarkAsErrored()\n```\nMarkAsErrored marks the consumer as errored (which makes it stop accepting logs)\n\n```go\nfunc (g *ContainerLogConsumer) ResetTempFile() error\n```\nResetTempFile resets the temp file and gob encoder\n\n```go\ntype FileLogHandler struct {\n\t// contains filtered or unexported fields\n}\n```\nFileLogHandler saves logs to local files\n\n```go\nfunc (h FileLogHandler) GetLogLocation(_ map[string]*ContainerLogConsumer) (string, error)\n```\n\n```go\nfunc (h FileLogHandler) GetTarget() LogTarget\n```\n\n```go\nfunc (h *FileLogHandler) Handle(c *ContainerLogConsumer, content LogContent) error\n```\n\n```go\nfunc (h *FileLogHandler) Init(c *ContainerLogConsumer) error\n```\n\n```go\nfunc (h *FileLogHandler) Teardown() error\n```\n\n```go\ntype HandleLogTarget interface {\n\tHandle(*ContainerLogConsumer, LogContent) error\n\tGetLogLocation(map[string]*ContainerLogConsumer) (string, error)\n\tGetTarget() LogTarget\n\tInit(*ContainerLogConsumer) error\n\tTeardown() error\n}\n```\n\n```go\ntype InMemoryLogHandler struct {\n\t// contains filtered or unexported fields\n}\n```\nInMemoryLogHandler stores logs in memory\n\n```go\nfunc (h InMemoryLogHandler) GetLogLocation(_ map[string]*ContainerLogConsumer) (string, error)\n```\n\n```go\nfunc (h InMemoryLogHandler) GetTarget() LogTarget\n```\n\n```go\nfunc (h *InMemoryLogHandler) Handle(c *ContainerLogConsumer, content LogContent) error\n```\n\n```go\nfunc (h *InMemoryLogHandler) Init(_ *ContainerLogConsumer) error\n```\n\n```go\nfunc (h *InMemoryLogHandler) Teardown() error\n```\n\n```go\ntype LogContent struct {\n\tTestName      string\n\tContainerName string\n\tContent       []byte\n\tTime          time.Time\n}\n```\nLogContent is a representation of log that will be send to Loki\n\n```go\ntype LogNotification struct {\n\tContainer string\n\tPrefix    string\n\tLog       string\n}\n```\nLogNotification notification about log line match for some container\n\n```go\ntype LogProcessor[ReturnType any] struct {\n\t// contains filtered or unexported fields\n}\n```\n\n```go\nfunc NewLogProcessor[ReturnType any](logStream *LogStream) *LogProcessor[ReturnType]\n```\nNewLogProcessor creates a new LogProcessor instance\n\n```go\nfunc (l *LogProcessor[ReturnType]) ProcessContainerLogs(containerName string, processFn func(content LogContent, returnValue *ReturnType) error) (*ReturnType, error)\n```\nProcessContainerLogs reads the logs of a container and processes them with the provided function\n\n```go\ntype LogProcessorFn[ReturnType any] func(content LogContent, returnValue *ReturnType) error\n```\n\n```go\ntype LogProducingContainer interface {\n\tName(ctx context.Context) (string, error)\n\tFollowOutput(consumer tc.LogConsumer)\n\tStartLogProducer(ctx context.Context, opts ...tc.LogProductionOption) error\n\tStopLogProducer() error\n\tGetLogProductionErrorChannel() \u003c-chan error\n\tIsRunning() bool\n\tGetContainerID() string\n\tTerminate(context.Context) error\n}\n```\nLogProducingContainer is a facade that needs to be implemented by any container that wants to be connected to LogStream\n\n```go\ntype LogStream struct {\n\t// contains filtered or unexported fields\n}\n```\nLogStream is a test helper struct to monitor docker container logs for some patterns and push their logs into Loki for further analysis\n\n```go\nfunc NewLogStream(t *testing.T, loggingConfig *config.LoggingConfig, options ...Option) (*LogStream, error)\n```\nNewLogStream creates a new LogStream instance, with Loki client only if Loki log target is enabled (lazy init)\n\n```go\nfunc (m *LogStream) ConnectContainer(ctx context.Context, container LogProducingContainer, prefix string) error\n```\nConnectContainer connects consumer to selected container, starts testcontainers.LogProducer and listens to it's failures in a detached goroutine\n\n```go\nfunc (m *LogStream) ContainerLogs(name string) ([]string, error)\n```\nContainerLogs return all logs for particular container\n\n```go\nfunc (m *LogStream) DisconnectContainer(container LogProducingContainer) error\n```\nDisconnectContainer disconnects particular container\n\n```go\nfunc (m *LogStream) FlushAndShutdown() error\n```\nFlushAndShutdown flushes all logs to their targets and shuts down the log stream in a default sequence\n\n```go\nfunc (m *LogStream) FlushLogsToTargets() error\n```\nFlushLogsToTargets flushes all logs for all consumers (containers) to their targets\n\n```go\nfunc (m *LogStream) GetAllLogsAndConsume(preExecuteFn ConsumerConsumingFn, consumeLogFn ConsumerLogConsumingFn, postExecuteFn ConsumerConsumingFn) (loopErr error)\n```\nGetAllLogsAndConsume gets all logs for all consumers (containers) and consumes them using consumeLogFn\n\n```go\nfunc (m *LogStream) GetConsumers() map[string]*ContainerLogConsumer\n```\nGetConsumers returns all consumers\n\n```go\nfunc (m *LogStream) GetLogLocation() string\n```\nSaveLogTargetsLocations saves all log targets locations to test summary\n\n```go\nfunc (m *LogStream) PrintLogTargetsLocations()\n```\nPrintLogTargetsLocations prints all log targets locations to stdout\n\n```go\nfunc (m *LogStream) SaveLogLocationInTestSummary()\n```\nSaveLogTargetsLocations saves all log targets locations to test summary\n\n```go\nfunc (m *LogStream) SaveLogTargetsLocations(writer LogWriter)\n```\nSaveLogTargetsLocations saves all log targets given writer\n\n```go\nfunc (m *LogStream) Shutdown(context context.Context) error\n```\nShutdown disconnects all containers and stops all consumers\n\n```go\ntype LogTarget string\n```\n\n```go\nconst (\n\tLoki     LogTarget = \"loki\"\n\tFile     LogTarget = \"file\"\n\tInMemory LogTarget = \"in-memory\"\n)\n```\n\n```go\ntype LogWriter = func(testName string, name string, location interface{}) error\n```\n\n```go\ntype LokiLogHandler struct {\n\t// contains filtered or unexported fields\n}\n```\nLokiLogHandler sends logs to Loki\n\n```go\nfunc (h *LokiLogHandler) GetLogLocation(consumers map[string]*ContainerLogConsumer) (string, error)\n```\n\n```go\nfunc (h LokiLogHandler) GetTarget() LogTarget\n```\n\n```go\nfunc (h *LokiLogHandler) Handle(c *ContainerLogConsumer, content LogContent) error\n```\n\n```go\nfunc (h *LokiLogHandler) Init(c *ContainerLogConsumer) error\n```\n\n```go\nfunc (h *LokiLogHandler) Teardown() error\n```\n\n```go\ntype Option func(*LogStream)\n```\n\n```go\nfunc WithCustomLogHandler(logTarget LogTarget, handler HandleLogTarget) Option\n```\nWithCustomLogHandler allows to override default log handler for particular log target\n\n","path":"github.com/smartcontractkit/chainlink-testing-framework/logstream","name":"logstream","synopsis":"","isRedistributable":true}
