diff --git a/README.md b/README.md index 40f02b0..ebd1508 100644 --- a/README.md +++ b/README.md @@ -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: diff --git a/formatter/formatterFactory.go b/formatter/formatterFactory.go index cc781d9..85d4c11 100644 --- a/formatter/formatterFactory.go +++ b/formatter/formatterFactory.go @@ -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 @@ -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 {