ffalcitelli
(Francesco Falcitelli)
August 23, 2024, 10:34am
1
I need to understand how log into a plugin
Which IIQ version are you inquiring about?
8.4
Problem Description
We have an easy plugin that expose some API.
Example:
@GET
@Path("search/kpiDashConfigTest")
@AllowAll
public Response getKpiDashConfigTest() throws GeneralException {
logger.info("##### START method 'getKpiDashConfigTest' #####");
}
This method is in my class with package com.acme.training.rest.SearchResource
The API works fine when installed on IdentityIQ but I don’t know where to find the log.
I tried to modify the file \iiq\WEB-INF\classes\log4j2.properties
with all in trace level and adding in below this:
logger.plugindashboard.name=com.acme.training.rest.SearchResource
logger.plugindashboard.level=trace
but I cannot see any log !
Could you help me ?
Thanks
Arun-Kumar
(Arun Kumar)
August 23, 2024, 11:06am
2
Hi @ffalcitelli ,
Define the logger in plugin class
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
private static Log log = LogFactory.getLog(MyClass.class);
log.info("printing message");
Regards,
Arun
vedeepak
(Deepak Vema)
August 23, 2024, 11:06am
3
you can use like below
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
Log logger = LogFactory.getLog("com.acme.training.rest.SearchResource");
logger.info("##### START method 'getKpiDashConfigTest' #####");
If you want to set log level for your code only then use below
import org.apache.logging.log4j.core.config.Configurator;
import org.apache.logging.log4j.Level;
Configurator.setLevel("com.acme.training.rest.SearchResource", Level.INFO);
1 Like
ffalcitelli
(Francesco Falcitelli)
August 28, 2024, 1:42pm
4
Hi all,
I’m not seeing anything about the logs, I used everything you suggested:
import java.util.logging.Logger;
//private static Logger logger = Logger.getLogger("SearchResource");
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
//private static Log logger = LogFactory.getLog(SearchResource.class);
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
private static Logger logger = LogManager.getLogger("SearchResource");
I’ll try to give more details:
I’m working on a java project for the implementation of a Sailpoint Plugin, there is a problem the plugin is not printing any logs located in the local folder “C:/Windows/Temp/sailpoint.log”, this file sailpoint.log, despite making API calls with speaking Responses and with logs reported in code does not print anything. The situation is the following:
the Sailpoint Plugin is on an Apache Tomcat Server in which it has a set of libraries that allow writing the backend code of the Plugin
logging is configured on the configuration file “log4j2.properties” located in “C:\Program Files\Apache Software Foundation\Tomcat 9.0\webapps\iiq\WEB-INF\classes\log4j2.properties”
the following file “log4j2.properties” has several lines inside it that indicate the level/status of the logs and the path of the logs, such as:
######################################
## Global log4j2 properties
######################################
name=identityiq_default
status=trace
monitorInterval=20
packages=sailpoint.api.logging
######################################
## sailpoint properties
######################################
property.logLocation=${sys:java.io.tmpdir}${sys:file.separator}
property.discardsFilename=sailpointDiscardedMessages
appender.rolling.type=RollingFile
appender.rolling.name=roll
appender.rolling.fileName=C:/Windows/Temp/sailpoint.log
appender.rolling.filePattern=C:/Windows/Temp/%d{MM-dd-yy-HH-mm-ss}-%i.sailpoint.gz
appender.rolling.layout.type=PatternLayout
appender.rolling.layout.pattern=%d{ISO8601} %5p %t %c{4}:%L - %m%n
appender.rolling.policies.type = Policies
appender.rolling.policies.size.type = SizeBasedTriggeringPolicy
appender.rolling.policies.size.size=5MB
appender.rolling.strategy.type = DefaultRolloverStrategy
appender.rolling.strategy.max = 5
in the Plugin project classpath I added the following two jars to include (in the various log problem resolution tests) the libraries:
commons-logging-1.2.jar
log4j-1.2-api-2.17.1.jar
which are the libraries also included in Tomcat;
on the Sailpoint Plugin Java project we have an iml file (Plugin-master.iml), the content of this file is the following:
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="identityiq" level="project" />
<orderEntry type="library" name="commons-logging-1.2" level="project" />
</component>
</module>
These logger.info, and in general any attempt to write logs, are not written to the sailpoint.log file, what’s the problem?
ffalcitelli
(Francesco Falcitelli)
August 28, 2024, 1:49pm
5
One more piece of information, see then despite between yesterday and today I restarted the server several times and made several API calls both from the web (Sailpoint) and from Postman, the sailpoint.log file does not update:
Hi @ffalcitelli ,
try this configuration:
In log4j create a new file and a new appender, like this(change the paths):
Appender
appender.pg.type=File
appender.pg.name=pg
appender.pg.fileName=/opt/tomcat/logs/pg.log
appender.pg.filePattern=/opt/tomcat/logs/pg.%i.log
appender.pg.layout.type=PatternLayout
appender.pg.layout.pattern=%d{ISO8601} %5p %t %c{4}:%L - %m%n
appender.pg.policies.type=Policies
appender.pg.policies.size.type=SizeBasedTriggeringPolicy
appender.pg.policies.size.size=100MB
appender.pg.strategy.type=DefaultRolloverStrategy
appender.pg.strategy.max=5
Logger
logger.pg.name=com.plugin
logger.pg.level=debug
logger.pg.appenderRef.pg.ref=pg
and use it in your code:
Log log = LogFactory.getLog("com.plugin");
Restart the tomcat and try to execute your code. This conf will create a new file calle pg.log.
ffalcitelli
(Francesco Falcitelli)
August 28, 2024, 2:36pm
7
Hi @enistri_devo ,
thanks, but I added the following lines to the log4j2.properties file:
#test read and write log
appender.pg.type=PgFile
appender.pg.name=pg
appender.pg.fileName=C:/Program Files/Apache Software Foundation/Tomcat 9.0/logs/pg.log
appender.pg.filePattern=C:/Program Files/Apache Software Foundation/Tomcat 9.0/logs/pg.%i.log
appender.pg.layout.type=PatternLayout
appender.pg.layout.pattern=%d{ISO8601} %5p %t %c{4}:%L - %m%n
appender.pg.policies.type=Policies
appender.pg.policies.size.type=SizeBasedTriggeringPolicy
appender.pg.policies.size.size=100MB
appender.pg.strategy.type=DefaultRolloverStrategy
appender.pg.strategy.max=5
...
logger.pluginsailpoint.name=com.acme.training.rest.SearchResource
logger.pluginsailpoint.level=trace
logger.trainingplugin.name=trainingPluginLogger
logger.trainingplugin.level=info
logger.pg.name=com.plugin
logger.pg.level=info
logger.pg.appenderRef.pg.ref=pg
but when restarting Tomcat and re-building the plugin on Sailpoint with the Java code:
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
private static Log logger = LogFactory.getLog("com.plugin");
@GET
@Path("search/kpiDashConfigTest")
@AllowAll
public Response getKpiDashConfigTest() throws GeneralException {
logger.info("##### START method 'getKpiDashConfigTest' #####");
}
did not produce pg.log file on the given path:
Hi @ffalcitelli ,
can you try to change the path with this:
appender.pg.fileName=C:\\Program Files\\Apache Software Foundation\\Tomcat 9.0\\logs\\pg.log
or
appender.pg.fileName="C:/Program Files/Apache Software Foundation/Tomcat 9.0/logs/pg.log"
and later reload the confguration:
I use the following for logging from a Plugin:
log4j.properties:
appender.pg.type=RollingFile
appender.pg.name=PG
appender.pg.fileName=C:\\Program Files\\Apache Software Foundation\\Tomcat 9.0\\logs\\pg.log
appender.pg.filePattern=C:\\Program Files\\Apache Software Foundation\\Tomcat 9.0\\logs\\pg.log.%d{dd-MMM}.log.gz
appender.pg.layout.type=PatternLayout
appender.pg.layout.pattern = %d{ISO8601} %5p %t %c{4}:%L - %m%n
appender.pg.policies.type=Policies
appender.pg.policies.size.type=SizeBasedTriggeringPolicy
appender.pg.policies.size.size=300MB
appender.pg.strategy.type=DefaultRolloverStrategy
appender.pg.strategy.max=15
logger.pg.name=com.altron.plugin.AWSCustomConnector
logger.pg.level=trace
logger.pg.additivity=false
logger.pg.appenderRef.connector.ref=PG
Please note the appenderRef.
Reload the log4j config from Debug UI or start IIQ Console.
ffalcitelli
(Francesco Falcitelli)
August 29, 2024, 8:58am
10
Thank you so much everyone,
@Paul_Meyer ’s final solution worked for me.
So, Was the path the problem?
ffalcitelli
(Francesco Falcitelli)
August 29, 2024, 10:19am
12
Hi @enistri_devo ,
yes, the problem was the path and also adding “logger.pg.additivity =false ” and changing the log control level to “trace ” solved the problem. Simply with @Paul_Meyer ’s solution adding “logger.pg.additivity =false ” allowed the log messages generated by that specific logger to be sent only to the appenders configured directly for that logger and not to those configured for the higher loggers.
1 Like
system
(system)
Closed
October 28, 2024, 10:20am
13
This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.