Skip to content

Instantly share code, notes, and snippets.

@DanielAdeniji
Last active January 3, 2022 00:37
Embed
What would you like to do?
helloLog4J
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
/*
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
}
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