Skip to content

Commit 9479d05

Browse files
committed
feat: First package version
1 parent 37aa2c7 commit 9479d05

File tree

18 files changed

+816
-0
lines changed

18 files changed

+816
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.idea

LICENSE.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023-Present Krypton
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

PLACEHOLDERS.md

Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
# Placeholders
2+
3+
This is the list of placeholders and aliases that will get replaced in your logging messages and prefix.
4+
5+
## Placeholders
6+
7+
### Caller
8+
9+
| Name | Value |
10+
|---------------------------|------------------------------------------------------------|
11+
| `${caller:function}` | The name of the function and file where it has been logged |
12+
| `${caller:shortfunction}` | The name of the function where it has been logged |
13+
| `${caller:file}` | The name of the file where it has been logged |
14+
| `${caller:line}` | The line in the file where it has been logged |
15+
16+
### Logging Level
17+
18+
| Name | Value |
19+
|---------------------------|------------------------------------------------------------|
20+
| `${level:color}` | The color representing the logging level |
21+
| `${level:name}` | The name representing the logging level |
22+
| `${level:shortname}` | The short name representing the logging level |
23+
24+
### Date & Time Now
25+
26+
| Name | Value |
27+
|---------------------------|-----------------------------------------------------------------|
28+
| `${now:date}` | The current date, default format is `Jan 02, 2006` |
29+
| `${now:time}` | The current time, default format is `15:04:05` |
30+
| `${now:datetime}` | The current datetime, default format is `Jan 02, 2006 15:04:05` |
31+
32+
### System
33+
34+
| Name | Value |
35+
|---------------------------|------------------------------------------------------------|
36+
| `${sys:architecture}` | The runtime architecture of the system |
37+
| `${sys:hostname}` | The hostname of the system |
38+
| `${sys:operating_system}` | The runtime operating system |
39+
| `${sys:username}` | The username of the system |
40+
| `${sys:groupid}` | The group ID of the current user |
41+
| `${sys:userid}` | The user ID of the current user |
42+
43+
### Foreground Colors
44+
45+
| Name | Value |
46+
|----------------------|------------------------------------|
47+
| `${fg:black}` | The black foreground color |
48+
| `${fg:red}` | The red foreground color |
49+
| `${fg:green}` | The green foreground color |
50+
| `${fg:yellow}` | The yellow foreground color |
51+
| `${fg:blue}` | The blue foreground color |
52+
| `${fg:purple}` | The purple foreground color |
53+
| `${fg:cyan}` | The cyan foreground color |
54+
| `${fg:white}` | The white foreground color |
55+
| `${fg:gray}` | The gray foreground color |
56+
| `${fg:brightred}` | The bright red foreground color |
57+
| `${fg:brightgreen}` | The bright green foreground color |
58+
| `${fg:brightyellow}` | The bright yellow foreground color |
59+
| `${fg:brightblue}` | The bright blue foreground color |
60+
| `${fg:brightpurple}` | The bright purple foreground color |
61+
| `${fg:brightcyan}` | The bright cyan foreground color |
62+
| `${fg:brightwhite}` | The bright white foreground color |
63+
64+
### Background Colors
65+
66+
| Name | Value |
67+
|----------------------|------------------------------------|
68+
| `${bg:black}` | The black background color |
69+
| `${bg:red}` | The red background color |
70+
| `${bg:green}` | The green background color |
71+
| `${bg:yellow}` | The yellow background color |
72+
| `${bg:blue}` | The blue background color |
73+
| `${bg:purple}` | The purple background color |
74+
| `${bg:cyan}` | The cyan background color |
75+
| `${bg:white}` | The white background color |
76+
| `${bg:gray}` | The gray background color |
77+
| `${bg:brightred}` | The bright red background color |
78+
| `${bg:brightgreen}` | The bright green background color |
79+
| `${bg:brightyellow}` | The bright yellow background color |
80+
| `${bg:brightblue}` | The bright blue background color |
81+
| `${bg:brightpurple}` | The bright purple background color |
82+
| `${bg:brightcyan}` | The bright cyan background color |
83+
| `${bg:brightwhite}` | The bright white background color |
84+
85+
### Special Effects
86+
87+
| Name | Value |
88+
|---------------------------|------------------------------------------------------------|
89+
| `${effect:bold}` | The bold effect |
90+
| `${effect:dim}` | The dim effect |
91+
| `${effect:underline}` | The underline effect |
92+
| `${effect:blink}` | The blink effect |
93+
| `${effect:inverse}` | The inverse effect |
94+
| `${effect:strikethrough}` | The strikethrough effect |
95+
| `${effect:reset}` | Resets the styles |
96+
97+
## Aliases
98+
99+
### Caller
100+
| Name | Alias of |
101+
|--------------------|---------------------------|
102+
| `${function}` | `${caller:function}` |
103+
| `${shortfunction}` | `${caller:shortfunction}` |
104+
| `${file}` | `${caller:file}` |
105+
| `${line}` | `${caller:line}` |
106+
107+
### Date & Time Now
108+
109+
| Name | Alias of |
110+
|-----------------------|---------------------------|
111+
| `${date}` | `${now:date}` |
112+
| `${time}` | `${now:time}` |
113+
| `${datetime}` | `${now:datetime}` |
114+
115+
### System
116+
117+
| Name | Alias of |
118+
|-----------------------|---------------------------|
119+
| `${sys:arch}` | `${sys:architecture}` |
120+
| `${architecture}` | `${sys:architecture}` |
121+
| `${arch}` | `${sys:architecture}` |
122+
| `${sys:os}` | `${sys:operating_system}` |
123+
| `${operating_system}` | `${sys:operating_system}` |
124+
| `${os}` | `${sys:operating_system}` |
125+
| `${hostname}` | `${sys:hostname}` |
126+
| `${username}` | `${sys:username}` |
127+
| `${groupid}` | `${sys:groupid}` |
128+
| `${userid}` | `${sys:userid}` |
129+
130+
### Foreground Colors
131+
132+
| Name | Alias of |
133+
|-----------------------|---------------------------|
134+
| `${black}` | `${fg:black}` |
135+
| `${red}` | `${fg:red}` |
136+
| `${green}` | `${fg:green}` |
137+
| `${yellow}` | `${fg:yellow}` |
138+
| `${blue}` | `${fg:blue}` |
139+
| `${purple}` | `${fg:purple}` |
140+
| `${cyan}` | `${fg:cyan}` |
141+
| `${white}` | `${fg:white}` |
142+
| `${gray}` | `${fg:gray}` |
143+
| `${brightred}` | `${fg:brightred}` |
144+
| `${brightgreen}` | `${fg:brightgreen}` |
145+
| `${brightyellow}` | `${fg:brightyellow}` |
146+
| `${brightblue}` | `${fg:brightblue}` |
147+
| `${brightpurple}` | `${fg:brightpurple}` |
148+
| `${brightcyan}` | `${fg:brightcyan}` |
149+
| `${brightwhite}` | `${fg:brightwhite}` |
150+
151+
### Background Colors
152+
153+
| Name | Alias of |
154+
|-----------------------|---------------------------|
155+
| `${bblack}` | `${bg:black}` |
156+
| `${bred}` | `${bg:red}` |
157+
| `${bgreen}` | `${bg:green}` |
158+
| `${byellow}` | `${bg:yellow}` |
159+
| `${bblue}` | `${bg:blue}` |
160+
| `${bpurple}` | `${bg:purple}` |
161+
| `${bcyan}` | `${bg:cyan}` |
162+
| `${bwhite}` | `${bg:white}` |
163+
| `${bgray}` | `${bg:gray}` |
164+
| `${bbrightred}` | `${bg:brightred}` |
165+
| `${bbrightgreen}` | `${bg:brightgreen}` |
166+
| `${bbrightyellow}` | `${bg:brightyellow}` |
167+
| `${bbrightblue}` | `${bg:brightblue}` |
168+
| `${bbrightpurple}` | `${bg:brightpurple}` |
169+
| `${bbrightcyan}` | `${bg:brightcyan}` |
170+
| `${bbrightwhite}` | `${bg:brightwhite}` |
171+
172+
### Special Effects
173+
174+
| Name | Alias of |
175+
|-----------------------|---------------------------|
176+
| `${bold}` | `${effect:bold}` |
177+
| `${dim}` | `${effect:dim}` |
178+
| `${underline}` | `${effect:underline}` |
179+
| `${blink}` | `${effect:blink}` |
180+
| `${inverse}` | `${effect:inverse}` |
181+
| `${strikethrough}` | `${effect:strikethrough}` |
182+
| `${reset}` | `${effect:reset}` |

assets/linux.png

206 KB
Loading

assets/macos.png

394 KB
Loading

assets/windows.png

143 KB
Loading

examples/basic/main.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package main
2+
3+
import (
4+
"github.com/kkrypt0nn/tangra"
5+
)
6+
7+
func main() {
8+
l := tangra.NewLogger()
9+
l.Debug("Debug message example")
10+
}

examples/file/main.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package main
2+
3+
import (
4+
"github.com/kkrypt0nn/tangra"
5+
"os"
6+
)
7+
8+
func main() {
9+
file, err := os.OpenFile("example.log", os.O_APPEND|os.O_WRONLY, os.ModeAppend)
10+
if err != nil {
11+
createdFile, err := os.Create("example.log")
12+
if err != nil {
13+
panic(err)
14+
}
15+
file = createdFile
16+
}
17+
l := tangra.NewLogger()
18+
l.SetLogFile(file)
19+
// The styling will get removed when writing into the file.
20+
l.Debug("${fg:red}${effect:blink}${effect:bold}${sys:username} says hello!")
21+
}

examples/placeholders/main.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package main
2+
3+
import "github.com/kkrypt0nn/tangra"
4+
5+
func main() {
6+
l := tangra.NewLogger()
7+
l.Println("${bold}${underline}Styling:")
8+
l.Println("${bold}Foreground colors:")
9+
l.Println("${fg:black}Black${reset}\t${fg:red}Red${reset}\t\t${fg:green}Green${reset}\t\t${fg:yellow}Yellow${reset}\t\t${fg:blue}Blue${reset}\t\t${fg:purple}Purple${reset}\t\t${fg:cyan}Cyan${reset}\t\t${fg:white}White")
10+
l.Println("${fg:gray}Gray${reset}\t${fg:brightred}Bright red${reset}\t${fg:brightgreen}Bright green${reset}\t${fg:brightyellow}Bright yellow\t${fg:brightblue}Bright blue${reset}\t${fg:brightpurple}Bright purple${reset}\t${fg:brightcyan}Bright cyan${reset}\t${fg:brightwhite}Bright white")
11+
l.Println("${bold}Background colors:")
12+
l.Println("${bg:black}Black${reset}\t${bg:red}Red${reset}\t\t${bg:green}Green${reset}\t\t${bg:yellow}Yellow${reset}\t\t${bg:blue}Blue${reset}\t\t${bg:purple}Purple${reset}\t\t${bg:cyan}Cyan${reset}\t\t${bg:white}White")
13+
l.Println("${bg:gray}Gray${reset}\t${bg:brightred}Bright red${reset}\t${bg:brightgreen}Bright green${reset}\t${bg:brightyellow}Bright yellow\t${bg:brightblue}Bright blue${reset}\t${bg:brightpurple}Bright purple${reset}\t${bg:brightcyan}Bright cyan${reset}\t${bg:brightwhite}Bright white")
14+
l.Println("${bold}Special Effects:")
15+
l.Println("${effect:bold}Bold${reset}\t${effect:dim}Dim${reset}\t\t${effect:underline}Underline${reset}\t${effect:blink}Blink${reset}\t\t${effect:inverse}Inverse${reset}\t\t${effect:strikethrough}Strikethrough${reset}")
16+
17+
l.Println("\n${bold}${underline}Variables:")
18+
l.Println("${bold}Caller:")
19+
l.Println("Function: ${caller:function}\tShort function: ${caller:shortfunction}\t\tFile: ${caller:file}\t\t\t\tLine: ${caller:line}")
20+
l.Println("${bold}Logging Level:")
21+
l.SetLoggingLevel(tangra.FATAL)
22+
l.Println("Level Color: ${level:color}Color${reset}\tLevel Name: ${level:name}\t\tLevel Short Name: ${level:shortname}")
23+
l.SetLoggingLevel(tangra.NONE)
24+
l.Println("${bold}Date & Time Now:")
25+
l.Println("Date: ${now:date}\tTime: ${now:time}\t\t\tDate & Time: ${now:datetime}")
26+
l.Println("${bold}System:")
27+
l.Println("Architecture: ${sys:architecture}\tHostname: ${sys:hostname}\tOperating System: ${sys:operating_system}\t\tUsername: ${username}")
28+
l.Println("Group ID: ${sys:groupid}\t\tUser ID: ${sys:userid}")
29+
}

examples/username_hello/main.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package main
2+
3+
import "github.com/kkrypt0nn/tangra"
4+
5+
func main() {
6+
l := tangra.NewLogger()
7+
l.Println("${fg:red}${effect:blink}${effect:bold}${sys:username} says hello!")
8+
}

0 commit comments

Comments
 (0)