xk6slog

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2024 License: MIT Imports: 8 Imported by: 0

README

xk6-slog

Extension for k6. Designed for logging during k6 tests. Uses slog module

Requirements

go install go.k6.io/xk6/cmd/xk6@latest

Build

From local repository:

xk6 build --with xk6-slog=.

From remote repository:

xk6 build --with github.com/Gwinkamp/xk6-slog

Usage

In load testing scenarios:

import { sleep } from "k6";
import slog from 'k6/x/slog';

export const options = {
  target: 1,
  duration: '10s',
};

export default function () {
  const consoleLogger = new slog.Logger({
    output: 'console',
    format: 'text',
    level: 'DEBUG',
  });

  const fileLogger = new slog.Logger({
    output: 'file',
    filepath: './k6_logs.log',
    format: 'json',
    level: 'WARNING',
  });

  consoleLogger.debug('example log');
  fileLogger.warn("test message", { operation: 'main', message: 'Example log', test: 123 });

  sleep(1);
}

To run this script, you need to run the k6 executable file, which was previously built with the xk6 build command

./k6 run scripts/example.js

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Logger

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

func NewLogger

func NewLogger(opts LoggerOpts) *Logger

func (*Logger) Debug

func (l *Logger) Debug(msg string, fields map[string]interface{})

func (*Logger) Error

func (l *Logger) Error(msg string, fields map[string]interface{})

func (*Logger) Info

func (l *Logger) Info(msg string, fields map[string]interface{})

func (*Logger) Warn

func (l *Logger) Warn(msg string, fields map[string]interface{})

type LoggerOpts

type LoggerOpts struct {
	Output   string
	Format   string
	Level    string
	Filepath string
}

func (LoggerOpts) CreateSLogHandler

func (opts LoggerOpts) CreateSLogHandler() slog.Handler

type SlogExt

type SlogExt struct{}

func (*SlogExt) XLogger

func (b *SlogExt) XLogger(call goja.ConstructorCall, rt *goja.Runtime) *goja.Object

XLogger creates a new Logger instance with the given options. Usage in k6 scripts: `const logger = new Logger(...);`

Jump to

Keyboard shortcuts

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