Skip to content

Commit

Permalink
Bugfix/documentation (#4)
Browse files Browse the repository at this point in the history
* adding info

* adding info

Co-authored-by: ext_christleo <[email protected]>
  • Loading branch information
cdleo and ext_christleo authored Feb 15, 2022
1 parent 6fa8c77 commit d3e3877
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 27 deletions.
39 changes: 20 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,32 +34,33 @@ func Tracem(e error, message string) error
func Tracef(e error, format string, args ...interface{}) error
```

Additionally, we provide a package called e2hformat in order to get the error information, over different formats
Currently,
Additionally, we provide a package called **e2hformat** in order to retrieve the error information, over different formats.

To starters, you must call the `NewFormatter(format Format) (Formatter, error)` function, indicating the desired format, to get the instance of this type.

```go
type Formatter interface {
// This function returns an string containing the description of the very first error in the stack
Source(err error) string
Format(err error, params Params) string
}

type Params struct {
Beautify bool
InvertCallstack bool
PathHidingMethod HidingMethod
PathHidingValue string
// This function returns the error stack information
Format(err error, params Params) string
}


// This function returns an string containing the description of the very first error in the stack
func Source(err error) string

// This function returns the error stack information in a JSON format
func FormatJSON(err error, rootFolder2Show string, indented bool) []byte

// This function returns the error stack information in a pretty format
func FormatPretty(err error, rootFolder2Show string) string
```

Currently allowed formats:
- **Format_Raw**: Non-hierarchical text format, with some decorators to get it human readable
- **Format_JSON**: JSON standard format

Once you have the formatter, you could change some details of output style modifying the values of the Params struct,
according to the following table:
| Param | Definition | Allowed values | Default value |
|---|---|---|---|
| Beautify | Sets if the output will be beautified | True / False | False |
| InvertCallstack | Sets if shows the last call or the origin error first | True (last call first) / False (origin error first) | False |
| PathHidingMethod | Sets the way in with the filepaths are managed | HidingMethod_None / HidingMethod_FullBaseline / HidingMethod_ToFolder | HidingMethod_None |
| PathHidingValue | Value to use, according to the selected 'PathHidingMethod' | A DirPath string | "" |

## Usage

The use of this module is very simple, as you may see:
Expand Down
19 changes: 11 additions & 8 deletions formatter/formatterFactory.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,17 @@ import (
"strings"
)

// Level defines log levels.
type Format int8
type HidingMethod int8

// Allowed output formats.
const (
// Disabled disables the logger.
Format_Raw Format = iota

// Mensajes de muy baja frecuencia que se deben mostrar siempre (como el copyright)
Format_JSON
)

type HidingMethod int8

//Allowed path treatments
const (
HidingMethod_None HidingMethod = iota

Expand All @@ -29,10 +28,14 @@ const (
)

type Params struct {
Beautify bool
InvertCallstack bool
//Sets if the output will be beautified
Beautify bool
//Sets if at top of the stack shows the last trace (invert = true) or the origin error (invert = false)
InvertCallstack bool
//Sets the way in with the filepaths are managed.
PathHidingMethod HidingMethod
PathHidingValue string
//Value to use, according to the selected 'PathHidingMethod'
PathHidingValue string
}

type Formatter interface {
Expand Down

0 comments on commit d3e3877

Please sign in to comment.