Last active
January 3, 2022 00:37
-
-
Save DanielAdeniji/82a66c9b25157316162e0a0f7eb16cd7 to your computer and use it in GitHub Desktop.
helloLog4J
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
setlocal | |
set "jar_log4j_version=2.17.1" | |
set "jar_log4j_explicit=lib/log4j/*" | |
set "jar_log4j_implicit=lib/log4j/log4j-api-%jar_log4j_version%.jar;lib/log4j/log4j-core-%jar_log4j_version%.jar;lib/log4j/log4j-1.2-api-%jar_log4j_version%.jar" | |
set "jar_log4j=%jar_log4j_implicit%" | |
javac -cp .;%jar_log4j% helloLog4j.java | |
endlocal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Import Apache log4j Packages | |
*/ | |
import org.apache.logging.log4j.LogManager; | |
import org.apache.logging.log4j.Logger; | |
public class helloLog4j | |
{ | |
/* | |
Declare Variables | |
*/ | |
static Logger log = null; | |
public static void main(String[] args) | |
{ | |
/* | |
Declare Variables | |
*/ | |
Exception objExceptionNull = null; | |
// configures the root logger | |
Logger log = LogManager.getRootLogger(); | |
objExceptionNull = new NullPointerException("NullError"); | |
metadata(); | |
log.debug("Hello this is a debug message"); | |
log.info("Hello this is an info message"); | |
log.error | |
( | |
"Error Message Logged !!!" | |
, objExceptionNull | |
); | |
} // function main | |
static void metadata() | |
{ | |
/* | |
Declare Variables | |
*/ | |
String strLog4JVersion = null; | |
String FORMAT_LOG4J_VERSION = "Log4j Version Number is %s %n"; | |
/* | |
How can I check the version number of Log4j in a .jar file? | |
Bhushan | |
https://stackoverflow.com/questions/70333560/how-can-i-check-the-version-number-of-log4j-in-a-jar-file | |
*/ | |
/* | |
Get log4J Version Number | |
*/ | |
strLog4JVersion | |
= org.apache.log4j.Layout.class.getPackage().getImplementationVersion(); | |
/* | |
If we have log4J Version Number, Log the retrieved version number | |
*/ | |
if (strLog4JVersion != null) | |
{ | |
System.out.printf | |
( | |
FORMAT_LOG4J_VERSION | |
, strLog4JVersion | |
); | |
} | |
} //metadata | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
setlocal | |
set "jar_log4j_version=2.17.1" | |
set "jar_log4j_explicit=lib/log4j/*" | |
set "jar_log4j_implicit=lib/log4j/log4j-api-%jar_log4j_version%.jar;lib/log4j/log4j-core-%jar_log4j_version%.jar;lib/log4j/log4j-1.2-api-%jar_log4j_version%.jar" | |
set "jar_log4j=%jar_log4j_implicit%" | |
java -cp .;%jar_log4j% helloLog4j | |
endlocal |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment