Skip to content

Commit 1779624

Browse files
committed
minor changes & README updated
1 parent 137b01b commit 1779624

File tree

2 files changed

+31
-28
lines changed

2 files changed

+31
-28
lines changed

README.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,15 @@ Try(error, mode, message)
2323
where, mode can be true or false
2424
If mode=true, process will exit and if mode=false, process will generate a warning message.
2525
```
26-
This will write the same message to logs and also will show on terminal in that particular format.
26+
* This will write the same message to logs and also will show on terminal if some message is given.
27+
* If no message is given, it will only log and do not show on terminal.
28+
* To show original error on terminal, use `Cprint(err)`. If err!=nil, it will be shown on terminal.
29+
* If you want to log `info`(other information), do:
30+
```
31+
Try(nil, false, message)
32+
```
2733

28-
* To automatically generate `log.txt` file and write logs in it, call function `Flog()`.
34+
<br>To automatically generate `log.txt` file and write logs in it, call function `Flog()`.
2935
```
3036
Examples:
3137
Try(err, true, "logging this") //it will log this message in case of err=nil, and if err!=nil then will log this message with error in file.
@@ -35,11 +41,6 @@ OUTPUT:
3541
2021/4/12 14:34:23 main.go:24: [INFO] generating logs
3642
```
3743

38-
<br> If you want to log `info`(other information), do:
39-
```
40-
Try(err, false, message)
41-
```
42-
4344
### How to create formatted texts on console:
4445
* To show colors on **WINDOWS CMD** also, call function `Cwindows()`.
4546
```

gohelper.go

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func Flog() error {
4444
return err
4545
}
4646
log.SetOutput(f)
47-
log.SetFlags(log.Lshortfile | log.Ldate | log.Ltime)
47+
log.SetFlags(log.LstdFlags)
4848
// defer f.Close()
4949
return nil
5050
}
@@ -59,23 +59,23 @@ func Try(err error, mode bool, msg ...interface{}) { //err,exit/noexit,msg
5959
if msgs != "" {
6060
if mode == true {
6161
Cprint(E, msgs)
62-
log.Println("[ERR]", msgs, err)
62+
log.Println("[ERROR]", msgs, "-", err)
6363
os.Exit(0)
6464
}
6565
Cprint(W, msgs)
66-
log.Println("[WARN]", msgs, err)
66+
log.Println("[WARN] ", msgs, "-", err)
6767
return
6868
}
6969
if mode == true {
70-
Cprint(E, err)
71-
log.Println("[ERR]", err)
70+
// Cprint(E, err)
71+
log.Println("[ERROR]", err)
7272
os.Exit(0)
7373
}
74-
Cprint(W, err)
75-
log.Println("[WARN]", err)
74+
// Cprint(W, err)
75+
log.Println("[WARN] ", err)
7676
return
7777
} else if msgs != "" {
78-
log.Println("[INFO]", msgs)
78+
log.Println("[INFO] ", msgs)
7979
}
8080
}
8181

@@ -85,19 +85,21 @@ func Cprint(mode string, msg ...interface{}) {
8585
for _, v := range msg {
8686
msgs = msgs + fmt.Sprintf("%v ", v)
8787
}
88-
switch mode {
89-
case N: //normal
90-
fmt.Println("\n" + CYAN + "[" + GREEN + "+" + CYAN + "] " + GREEN + msgs + RESET)
91-
case E: //error
92-
fmt.Println("\n" + CYAN + "[" + RED + BLINK + "-" + RESET + CYAN + "] " + RED + BGBLACK + BOLD + "ERROR" + RESET + " " + RED + msgs + RESET)
93-
case W: //warning
94-
fmt.Println("\n" + CYAN + "[" + YELLOW + BLINK + "!" + RESET + CYAN + "] " + YELLOW + BGBLACK + BOLD + "WARN" + RESET + " " + YELLOW + msgs + RESET)
95-
case T: //text
96-
fmt.Println("\n" + CYAN + "[" + PURPLE + "*" + CYAN + "] " + PURPLE + msgs + RESET)
97-
case I: //info
98-
fmt.Println("\n" + CYAN + "[" + BLUE + "i" + CYAN + "] " + BLUE + msgs + RESET)
99-
case S: //shell
100-
fmt.Print("\n" + CYAN + "[" + PURPLE + "*" + CYAN + "] " + PURPLE + msgs + "\n" + GREEN + ">> " + RESET)
88+
if msgs != "<nil> " {
89+
switch mode {
90+
case N: //normal
91+
fmt.Println("\n" + CYAN + "[" + GREEN + "+" + CYAN + "] " + GREEN + msgs + RESET)
92+
case E: //error
93+
fmt.Println("\n" + CYAN + "[" + RED + BLINK + "-" + RESET + CYAN + "] " + RED + BGBLACK + BOLD + "ERROR" + RESET + " " + RED + msgs + RESET)
94+
case W: //warning
95+
fmt.Println("\n" + CYAN + "[" + YELLOW + BLINK + "!" + RESET + CYAN + "] " + YELLOW + BGBLACK + BOLD + "WARN" + RESET + " " + YELLOW + msgs + RESET)
96+
case T: //text
97+
fmt.Println("\n" + CYAN + "[" + PURPLE + "*" + CYAN + "] " + PURPLE + msgs + RESET)
98+
case I: //info
99+
fmt.Println("\n" + CYAN + "[" + BLUE + "i" + CYAN + "] " + BLUE + msgs + RESET)
100+
case S: //shell
101+
fmt.Print("\n" + CYAN + "[" + PURPLE + "*" + CYAN + "] " + PURPLE + msgs + "\n" + GREEN + ">> " + RESET)
102+
}
101103
}
102104
}
103105

0 commit comments

Comments
 (0)