Skip to content

Commit 7430bdc

Browse files
committed
Added a new easy way to log info, errors and warnings
1 parent ca675ad commit 7430bdc

5 files changed

Lines changed: 241 additions & 20 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ Simple logger for java with mixpanel support
66
<dependency>
77
<groupId>io.github.Fi0x</groupId>
88
<artifactId>JavaLogger</artifactId>
9-
<version>1.3.0</version>
9+
<version>1.3.1</version>
1010
</dependency>
1111
```

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>io.github.Fi0x</groupId>
88
<artifactId>JavaLogger</artifactId>
9-
<version>1.3.0</version>
9+
<version>1.3.1</version>
1010
<name>Java Logger</name>
1111
<description>This is a Library for a custom Java Logger</description>
1212
<url>http://github.com/Fi0x/JavaLogger</url>
Lines changed: 221 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,221 @@
1+
package io.fi0x.javalogger.logging;
2+
3+
/**
4+
* This class is designed to enable an easy way to log important messages with pre-defined settings.
5+
* These settings can be changed by overriding the default LogLevel types.
6+
*/
7+
public class LOG
8+
{
9+
/**
10+
* This method will create a log message with the INFO template.
11+
* @param message The message that will be displayed in the log.
12+
* @param projectName The name of the project this log was created in.
13+
*/
14+
public static void INFO(String message, String projectName)
15+
{
16+
LogEntry l = new LogEntry(message, LogLevel.INFO)
17+
.PROJECTNAME(projectName);
18+
Logger.log(l);
19+
}
20+
/**
21+
* This method will create a log message with the INFO template.
22+
* @param message The message that will be displayed in the log.
23+
*/
24+
public static void INFO(String message)
25+
{
26+
LogEntry l = new LogEntry(message, LogLevel.INFO);
27+
Logger.log(l);
28+
}
29+
/**
30+
* This method will create a log message with the WARNING template.
31+
* @param message The message that will be displayed in the log.
32+
* @param projectName The name of the project this log was created in.
33+
* @param errorCode The error code that will be displayed.
34+
* @param exception The exception that will be printed.
35+
*/
36+
public static void WARN(String message, String projectName, int errorCode, Exception exception)
37+
{
38+
LogEntry l = new LogEntry(message, LogLevel.WARNING)
39+
.PROJECTNAME(projectName)
40+
.CODE(errorCode)
41+
.EXCEPTION(exception);
42+
Logger.log(l);
43+
}
44+
/**
45+
* This method will create a log message with the WARNING template.
46+
* @param message The message that will be displayed in the log.
47+
* @param errorCode The error code that will be displayed.
48+
* @param exception The exception that will be printed.
49+
*/
50+
public static void WARN(String message, int errorCode, Exception exception)
51+
{
52+
LogEntry l = new LogEntry(message, LogLevel.WARNING)
53+
.CODE(errorCode)
54+
.EXCEPTION(exception);
55+
Logger.log(l);
56+
}
57+
/**
58+
* This method will create a log message with the WARNING template.
59+
* @param message The message that will be displayed in the log.
60+
* @param projectName The name of the project this log was created in.
61+
* @param errorCode The error code that will be displayed.
62+
*/
63+
public static void WARN(String message, String projectName, int errorCode)
64+
{
65+
LogEntry l = new LogEntry(message, LogLevel.WARNING)
66+
.PROJECTNAME(projectName)
67+
.CODE(errorCode);
68+
Logger.log(l);
69+
}
70+
/**
71+
* This method will create a log message with the WARNING template.
72+
* @param message The message that will be displayed in the log.
73+
* @param projectName The name of the project this log was created in.
74+
* @param exception The exception that will be printed.
75+
*/
76+
public static void WARN(String message, String projectName, Exception exception)
77+
{
78+
LogEntry l = new LogEntry(message, LogLevel.WARNING)
79+
.PROJECTNAME(projectName)
80+
.EXCEPTION(exception);
81+
Logger.log(l);
82+
}
83+
/**
84+
* This method will create a log message with the WARNING template.
85+
* @param message The message that will be displayed in the log.
86+
* @param errorCode The error code that will be displayed.
87+
*/
88+
public static void WARN(String message, int errorCode)
89+
{
90+
LogEntry l = new LogEntry(message, LogLevel.WARNING)
91+
.CODE(errorCode);
92+
Logger.log(l);
93+
}
94+
/**
95+
* This method will create a log message with the WARNING template.
96+
* @param message The message that will be displayed in the log.
97+
* @param projectName The name of the project this log was created in.
98+
*/
99+
public static void WARN(String message, String projectName)
100+
{
101+
LogEntry l = new LogEntry(message, LogLevel.WARNING)
102+
.PROJECTNAME(projectName);
103+
Logger.log(l);
104+
}
105+
/**
106+
* This method will create a log message with the WARNING template.
107+
* @param message The message that will be displayed in the log.
108+
* @param exception The exception that will be printed.
109+
*/
110+
public static void WARN(String message, Exception exception)
111+
{
112+
LogEntry l = new LogEntry(message, LogLevel.WARNING)
113+
.EXCEPTION(exception);
114+
Logger.log(l);
115+
}
116+
/**
117+
* This method will create a log message with the WARNING template.
118+
* @param message The message that will be displayed in the log.
119+
*/
120+
public static void WARN(String message)
121+
{
122+
LogEntry l = new LogEntry(message, LogLevel.WARNING);
123+
Logger.log(l);
124+
}
125+
/**
126+
* This method will create a log message with the ERROR template.
127+
* @param message The message that will be displayed in the log.
128+
* @param projectName The name of the project this log was created in.
129+
* @param errorCode The error code that will be displayed.
130+
* @param exception The exception that will be printed.
131+
*/
132+
public static void ERROR(String message, String projectName, int errorCode, Exception exception)
133+
{
134+
LogEntry l = new LogEntry(message, LogLevel.ERROR)
135+
.PROJECTNAME(projectName)
136+
.CODE(errorCode)
137+
.EXCEPTION(exception);
138+
Logger.log(l);
139+
}
140+
/**
141+
* This method will create a log message with the ERROR template.
142+
* @param message The message that will be displayed in the log.
143+
* @param errorCode The error code that will be displayed.
144+
* @param exception The exception that will be printed.
145+
*/
146+
public static void ERROR(String message, int errorCode, Exception exception)
147+
{
148+
LogEntry l = new LogEntry(message, LogLevel.ERROR)
149+
.CODE(errorCode)
150+
.EXCEPTION(exception);
151+
Logger.log(l);
152+
}
153+
/**
154+
* This method will create a log message with the ERROR template.
155+
* @param message The message that will be displayed in the log.
156+
* @param projectName The name of the project this log was created in.
157+
* @param errorCode The error code that will be displayed.
158+
*/
159+
public static void ERROR(String message, String projectName, int errorCode)
160+
{
161+
LogEntry l = new LogEntry(message, LogLevel.ERROR)
162+
.PROJECTNAME(projectName)
163+
.CODE(errorCode);
164+
Logger.log(l);
165+
}
166+
/**
167+
* This method will create a log message with the ERROR template.
168+
* @param message The message that will be displayed in the log.
169+
* @param projectName The name of the project this log was created in.
170+
* @param exception The exception that will be printed.
171+
*/
172+
public static void ERROR(String message, String projectName, Exception exception)
173+
{
174+
LogEntry l = new LogEntry(message, LogLevel.ERROR)
175+
.PROJECTNAME(projectName)
176+
.EXCEPTION(exception);
177+
Logger.log(l);
178+
}
179+
/**
180+
* This method will create a log message with the ERROR template.
181+
* @param message The message that will be displayed in the log.
182+
* @param errorCode The error code that will be displayed.
183+
*/
184+
public static void ERROR(String message, int errorCode)
185+
{
186+
LogEntry l = new LogEntry(message, LogLevel.ERROR)
187+
.CODE(errorCode);
188+
Logger.log(l);
189+
}
190+
/**
191+
* This method will create a log message with the ERROR template.
192+
* @param message The message that will be displayed in the log.
193+
* @param projectName The name of the project this log was created in.
194+
*/
195+
public static void ERROR(String message, String projectName)
196+
{
197+
LogEntry l = new LogEntry(message, LogLevel.ERROR)
198+
.PROJECTNAME(projectName);
199+
Logger.log(l);
200+
}
201+
/**
202+
* This method will create a log message with the ERROR template.
203+
* @param message The message that will be displayed in the log.
204+
* @param exception The exception that will be printed.
205+
*/
206+
public static void ERROR(String message, Exception exception)
207+
{
208+
LogEntry l = new LogEntry(message, LogLevel.ERROR)
209+
.EXCEPTION(exception);
210+
Logger.log(l);
211+
}
212+
/**
213+
* This method will create a log message with the ERROR template.
214+
* @param message The message that will be displayed in the log.
215+
*/
216+
public static void ERROR(String message)
217+
{
218+
LogEntry l = new LogEntry(message, LogLevel.ERROR);
219+
Logger.log(l);
220+
}
221+
}

src/main/java/io/fi0x/javalogger/logging/LogEntry.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public class LogEntry
2626
boolean consoleException = false;
2727
boolean mixpanel = false;
2828
String mixpanelEventName = "LOG";
29-
String projectName = "JavaLogger";
29+
String projectName = "";
3030

3131
/**
3232
* Create a new {@link LogEntry} with the given text.
@@ -221,7 +221,7 @@ public LogEntry MIXPANELNAME(String mixpanelEvent)
221221
/**
222222
* Change the name of the project that produces this {@link LogEntry}.
223223
* @param nameOfProject The project name under which this {@link LogEntry} should be displayed
224-
* (Default is 'JavaLogger').
224+
* (Default is empty).
225225
* @return The current {@link LogEntry} to be used further.
226226
*/
227227
public LogEntry PROJECTNAME(String nameOfProject)

src/main/java/io/fi0x/javalogger/logging/Logger.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,19 @@ public class Logger
2929

3030
static Map<String, LogTemplate> templates = new HashMap<>()
3131
{{
32-
put(LogLevel.VERBOSE.name(), new LogTemplate(LogColor.WHITE, "", "VER", false, true, 0, false, false, false, false, "LOG", "JavaLogger"));
33-
put(LogLevel.VVERBOSE.name(), new LogTemplate(LogColor.WHITE, "", "VER", false, true, 1, false, false, false, false, "LOG", "JavaLogger"));
34-
put(LogLevel.VVVERBOSE.name(), new LogTemplate(LogColor.WHITE, "", "VER", false, true, 2, false, false, false, false, "LOG", "JavaLogger"));
35-
put(LogLevel.INFO.name(), new LogTemplate(LogColor.WHITE_BRIGHT, "", "INF", true, false, 0, true, false, false, false, "LOG", "JavaLogger"));
36-
put(LogLevel.WARNING.name(), new LogTemplate(LogColor.YELLOW_BRIGHT, "", "WRN", true, false, 0, false, false, false, true, "LOG", "JavaLogger"));
37-
put(LogLevel.ERROR.name(), new LogTemplate(LogColor.RED_BRIGHT, "", "ERR", true, false, 0, false, false, true, true, "LOG", "JavaLogger"));
38-
put(LogLevel.SPECIAL.name(), new LogTemplate(LogColor.GREEN, "", "SPE", false, false, 0, false, false, false, false, "LOG", "JavaLogger"));
39-
put(LogLevel.RESPONSE.name(), new LogTemplate(LogColor.BLUE, "", "RES", false, false, 0, false, false, false, false, "LOG", "JavaLogger"));
40-
put(LogLevel.QUESTION.name(), new LogTemplate(LogColor.CYAN_BRIGHT, "", "QUE", false, false, 0, false, false, false, false, "LOG", "JavaLogger"));
41-
put(LogLevel.CLEAN_INFO.name(), new LogTemplate(LogColor.WHITE_BRIGHT, "", "INF", true, false, 0, true, true, false, false, "LOG", "JavaLogger"));
42-
put(LogLevel.CLEAN_SPECIAL.name(), new LogTemplate(LogColor.GREEN, "", "SPE", false, false, 0, false, true, false, false, "LOG", "JavaLogger"));
43-
put(LogLevel.CLEAN_RESPONSE.name(), new LogTemplate(LogColor.BLUE, "", "RES", false, false, 0, false, true, false, false, "LOG", "JavaLogger"));
44-
put(LogLevel.CLEAN_QUESTION.name(), new LogTemplate(LogColor.CYAN_BRIGHT, "", "QUE", false, false, 0, false, true, false, false, "LOG", "JavaLogger"));
32+
put(LogLevel.VERBOSE.name(), new LogTemplate(LogColor.WHITE, "", "VER", false, true, 0, false, false, false, false, "LOG", ""));
33+
put(LogLevel.VVERBOSE.name(), new LogTemplate(LogColor.WHITE, "", "VER", false, true, 1, false, false, false, false, "LOG", ""));
34+
put(LogLevel.VVVERBOSE.name(), new LogTemplate(LogColor.WHITE, "", "VER", false, true, 2, false, false, false, false, "LOG", ""));
35+
put(LogLevel.INFO.name(), new LogTemplate(LogColor.WHITE_BRIGHT, "", "INF", true, false, 0, true, false, false, false, "LOG", ""));
36+
put(LogLevel.WARNING.name(), new LogTemplate(LogColor.YELLOW_BRIGHT, "", "WRN", true, false, 0, false, false, false, true, "LOG", ""));
37+
put(LogLevel.ERROR.name(), new LogTemplate(LogColor.RED_BRIGHT, "", "ERR", true, false, 0, false, false, true, true, "LOG", ""));
38+
put(LogLevel.SPECIAL.name(), new LogTemplate(LogColor.GREEN, "", "SPE", false, false, 0, false, false, false, false, "LOG", ""));
39+
put(LogLevel.RESPONSE.name(), new LogTemplate(LogColor.BLUE, "", "RES", false, false, 0, false, false, false, false, "LOG", ""));
40+
put(LogLevel.QUESTION.name(), new LogTemplate(LogColor.CYAN_BRIGHT, "", "QUE", false, false, 0, false, false, false, false, "LOG", ""));
41+
put(LogLevel.CLEAN_INFO.name(), new LogTemplate(LogColor.WHITE_BRIGHT, "", "INF", true, false, 0, true, true, false, false, "LOG", ""));
42+
put(LogLevel.CLEAN_SPECIAL.name(), new LogTemplate(LogColor.GREEN, "", "SPE", false, false, 0, false, true, false, false, "LOG", ""));
43+
put(LogLevel.CLEAN_RESPONSE.name(), new LogTemplate(LogColor.BLUE, "", "RES", false, false, 0, false, true, false, false, "LOG", ""));
44+
put(LogLevel.CLEAN_QUESTION.name(), new LogTemplate(LogColor.CYAN_BRIGHT, "", "QUE", false, false, 0, false, true, false, false, "LOG", ""));
4545
}};
4646

4747
private Logger()
@@ -258,21 +258,21 @@ public static boolean createNewTemplate(String templateName, String colorCode, S
258258
*/
259259
public static boolean createNewTemplate(Enum<?> templateName, String colorCode, String backgroundColorCode, String logLevel, boolean writeToFile, boolean onlyVerbose, int verboseLevel, boolean onlyDebug, boolean hidePrefix, boolean exceptionsInConsole, boolean mixpanelMessage, String mixpanelName, String projectName)
260260
{
261-
return createNewTemplate(templateName.name(), colorCode, backgroundColorCode, logLevel, writeToFile, onlyVerbose, verboseLevel, onlyDebug, hidePrefix, exceptionsInConsole, mixpanelMessage, mixpanelName, "JavaLogger");
261+
return createNewTemplate(templateName.name(), colorCode, backgroundColorCode, logLevel, writeToFile, onlyVerbose, verboseLevel, onlyDebug, hidePrefix, exceptionsInConsole, mixpanelMessage, mixpanelName, "");
262262
}
263263
/**
264264
* @see #createNewTemplate(String, String, String, String, boolean, boolean, int, boolean, boolean, boolean, boolean, String, String)
265265
*/
266266
public static boolean createNewTemplate(String templateName, String colorCode, String backgroundColorCode, String logLevel, boolean writeToFile, boolean onlyVerbose, int verboseLevel, boolean onlyDebug, boolean hidePrefix, boolean exceptionsInConsole, boolean mixpanelMessage, String mixpanelName)
267267
{
268-
return createNewTemplate(templateName, colorCode, backgroundColorCode, logLevel, writeToFile, onlyVerbose, 0, onlyDebug, hidePrefix, exceptionsInConsole, mixpanelMessage, mixpanelName, "JavaLogger");
268+
return createNewTemplate(templateName, colorCode, backgroundColorCode, logLevel, writeToFile, onlyVerbose, 0, onlyDebug, hidePrefix, exceptionsInConsole, mixpanelMessage, mixpanelName, "");
269269
}
270270
/**
271271
* @see #createNewTemplate(String, String, String, String, boolean, boolean, int, boolean, boolean, boolean, boolean, String, String)
272272
*/
273273
public static boolean createNewTemplate(Enum<?> templateName, String colorCode, String backgroundColorCode, String logLevel, boolean writeToFile, boolean onlyVerbose, int verboseLevel, boolean onlyDebug, boolean hidePrefix, boolean exceptionsInConsole, boolean mixpanelMessage, String mixpanelName)
274274
{
275-
return createNewTemplate(templateName, colorCode, backgroundColorCode, logLevel, writeToFile, onlyVerbose, verboseLevel, onlyDebug, hidePrefix, exceptionsInConsole, mixpanelMessage, mixpanelName, "JavaLogger");
275+
return createNewTemplate(templateName, colorCode, backgroundColorCode, logLevel, writeToFile, onlyVerbose, verboseLevel, onlyDebug, hidePrefix, exceptionsInConsole, mixpanelMessage, mixpanelName, "");
276276
}
277277
/**
278278
* @see #createNewTemplate(String, String, String, String, boolean, boolean, int, boolean, boolean, boolean, boolean, String, String)

0 commit comments

Comments
 (0)