noaencoderjson

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2025 License: Apache-2.0 Imports: 7 Imported by: 0

README

Noa Encoder Json

JSON encoder for Noa Log. Supports encoding Log entries into JSON format for writing into log files.

Installation

go get -u github.com/noa-log/noa-encoder-json

Quick Start

package main

import (
    "errors"
    "github.com/noa-log/noa"
    noaencoderjson "github.com/noa-log/noa-encoder-json"
)

func main() {
    // Create a new logger instance
    logger := noa.NewLog()
    // Set the encoder to the JSON encoder
    logger.SetEncoder(noaencoderjson.NewJSONEncoder(logger))

    // You can also set different encoders for print and write
    // logger.Encoder.Print = noa.NewTextEncoder(logger)
    // logger.Encoder.Write = noaencoderjson.NewJSONEncoder(logger)

    // Print Log
    logger.Info("Test", "This is an info message")
    logger.Error("Test", errors.New("an example error"))
}

License

This project is open-sourced under the Apache License 2.0. Please comply with the terms when using it.

Documentation

Overview

* @Author: nijineko * @Date: 2025-06-10 12:57:28 * @LastEditTime: 2025-06-10 23:02:39 * @LastEditors: nijineko * @Description: noa json log encoder * @FilePath: \noa-encoder-json\jsonEncoder.go

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ErrorLog

type ErrorLog struct {
	Message     string               `json:"message"`
	StackFrames []ErrorLogStackFrame `json:"stack_frames,omitempty"`
}

error log format

type ErrorLogStackFrame

type ErrorLogStackFrame struct {
	Function     string `json:"function"`
	File         string `json:"file"`
	Line         int    `json:"line"`
	PackageName  string `json:"package_name"`
	FunctionName string `json:"function_name"`
}

error log stack frame format

type JSONEncoder

type JSONEncoder struct {
	Log *noa.LogConfig
}

JSONEncoder struct

func NewJSONEncoder

func NewJSONEncoder(Log *noa.LogConfig) *JSONEncoder

*

  • @description: Create a new JSONEncoder instance
  • @param {noa.LogConfig} Log noa log instance
  • @return {*JSONEncoder} JSONEncoder instance

func (*JSONEncoder) FileExtension

func (e *JSONEncoder) FileExtension() string

*

  • @description: Get file extension for the encoded file
  • @return {string} file extension

func (*JSONEncoder) Print

func (je *JSONEncoder) Print(c *encoder.Context)

print json log data

func (*JSONEncoder) Write

func (je *JSONEncoder) Write(FileHandle *os.File, c *encoder.Context) error

write log data to file

func (*JSONEncoder) WriteFileExtension

func (je *JSONEncoder) WriteFileExtension() string

return file extension for the encoded file

type JSONLog

type JSONLog struct {
	Time       int64  `json:"time"`
	TimeFormat string `json:"time_format"`
	Level      int    `json:"level"`
	Source     string `json:"source"`
	Data       []any  `json:"data"`
}

json log format

Jump to

Keyboard shortcuts

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