MyLog

package module
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2023 License: MIT Imports: 6 Imported by: 0

README

MyLog

MyLog is a Go package designed to enable fast logging via Kafka.

Installation

To use MyLog in your Go project, you can simply run:

go get github.com/heyitsfranky/MyLog@latest

Usage

Here's a basic example of how to use MyLog:

package main

import (
	"fmt"
	"github.com/heyitsfranky/MyLog"
)

func main() {
	configFilePath := "path/to/your/config.yaml"

	// Initialize MyLog with the configuration file
	if err := MyLog.Init(configFilePath); err != nil {
		fmt.Printf("Error initializing MyLog: %s\n", err)
		return
	}
    // Create a intricate log event asynchronously
	body := map[string]interface{}{"msg": "hello world!", "id": 42}
	MyLog.CreateEvent(body, "main()", 0, true)
	// (or synchronously)
	MyLog.CreateEvent(body, "main()", 0, false)
    
    // Create predefined log events asynchronously
	MyLog.CreateInfoEvent("This is an informational message", "MyPackage::main()")
	MyLog.CreateWarningEvent("This is a warning message", "somefn()")
	MyLog.CreateErrorEvent("This is an error message", "foobar()")
	MyLog.CreateCriticalEvent("This is a critical error message", "MyClass.hello()")
}

Configuration

To load the initial settings for event communication via kafka, a configuration file must be given that contains:

client-origin: your-app-name,
kafka-broker: localhost:9092,

An up-to-date template can always be found under 'configs/config.yaml'.

License

This package is distributed under the MIT License. Feel free to contribute or report issues on GitHub.

Happy coding!

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateCriticalEvent

func CreateCriticalEvent(body string, caller string)

func CreateErrorEvent

func CreateErrorEvent(body string, caller string)

func CreateEvent

func CreateEvent(body interface{}, caller string, level int, async bool) error

func CreateInfoEvent

func CreateInfoEvent(body string, caller string)

these functions are just used to create simple, fast logs

func CreateWarningEvent

func CreateWarningEvent(body string, caller string)

func Init

func Init(configPath string) error

Types

type InitData

type InitData struct {
	KafkaBroker  string `yaml:"kafka_broker"`
	ClientOrigin string `yaml:"client_origin"`
}
var Data *InitData

type LogData

type LogData struct {
	Body   interface{} `json:"body"`
	Origin string      `json:"origin"`
	Caller string      `json:"caller"`
	Level  int         `json:"level"`
}

Jump to

Keyboard shortcuts

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