Skip to content

Commit

Permalink
Implement a panic
Browse files Browse the repository at this point in the history
  • Loading branch information
pchchv committed Jan 31, 2023
1 parent cf65d33 commit 1560820
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,5 +116,4 @@ This will produce:

# **TODO**

* **Panic**
* **Logging to file**
10 changes: 10 additions & 0 deletions golog.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const (
LOG_INFO
LOG_ERROR
LOG_FATAL
LOG_PANIC
)

var (
Expand All @@ -28,6 +29,7 @@ var (
LOG_INFO: LogDefault,
LOG_ERROR: LogDefault,
LOG_FATAL: LogDefault,
LOG_PANIC: LogDefault,
}

// The current maximum length printed for caller information. This is updated each time something gets printed
Expand All @@ -39,6 +41,7 @@ var (
LOG_INFO: "[INFO] ",
LOG_ERROR: "[ERROR]",
LOG_FATAL: "[FATAL]",
LOG_PANIC: "[PANIC]",
}

LevelOutputs = map[Level]*os.File{
Expand All @@ -47,6 +50,7 @@ var (
LOG_INFO: os.Stdout,
LOG_ERROR: os.Stderr,
LOG_FATAL: os.Stderr,
LOG_PANIC: os.Stderr,
}
)

Expand Down Expand Up @@ -102,6 +106,12 @@ func Errorb(framesBackward int, format string, a ...interface{}) {
}
}

func Panic(format string, a ...interface{}) {
s := fmt.Sprintf(format, a...)
log(LOG_PANIC, 3, s)
panic(s)
}

// Stack tries to print the stack trace of the given error using the %+v format string.
// When using the https://github.com/pkg/errors package, a full error stack trace will be output.
// If normal errors are used, just print the error.
Expand Down

0 comments on commit 1560820

Please sign in to comment.