05-08-2016 10:41 PM
We have implemented custom element using Cisco CVP. We are able to achieve logging using audium addtolog function. But We need to know how we can use log4j for logging in our custom java classes. Do we need to modify logging.properties or log4j.xml by adding package name of our custom classes. We would like to know the location on call studio and vxml server if we can change logging.properties or log4j.xml.
Solved! Go to Solution.
05-09-2016 09:38 AM
In order to get Log4J working for your custom code, you do no want to or need to adjust CVP's log configurations. Rather, you will need to create your own Log4J .properties or .xml configuration file and put it in the classpath. You can then, in Java, read the file off the classpath without having to use a static file path. So, if the config file were in your classpath, something like this would load it and initialize your configuration without having to keep a static path:
try { |
URL url = ApplicationStart.class.getResource("/MyConfig_log4j.xml");
DOMConfigurator.configure(url);
} catch (Exception e) {
// do something
}
Now, there are several places you can put the file and have it work. The best choice really depends on your requirements. In Studio, you can put it in deploy/java/application/classes inside of your Studio project. That way, it will deploy with your Studio project and be available automatically. That's usually the simplest as it means you don't have to maintain a copy separately on the server. Otherwise, you can place it with your custom jar files on the CVP server itself, just be sure to use the classes subdirectory instead of the lib subdirectory of wherever you are placing it.
A couple more important notes:
1. don't override the root logger unless you want to start messing with CVP's logging as well
2. don't call your file log4j.properties or log4j.xml, give it some other unique name (so you again don't mess with CVP's logging)
3. if you have logging config files in multiple Studio projects, be sure they're not configuring the same logger. Otherwise, the last one to load will override all the ones that came before it
Good luck!
05-09-2016 09:25 AM
Hello!
This is a suggestion how a I have implemented log4j:
public class MyCustomCell extends ActionElementBase implements ElementInterface{
static{
PropertyConfigurator.configure("C:\\cfg\\CustomCVPElementLog.properties");
}
static Logger logger = Logger.getLogger(MyCustomCell.class);
...
}
05-09-2016 09:38 AM
In order to get Log4J working for your custom code, you do no want to or need to adjust CVP's log configurations. Rather, you will need to create your own Log4J .properties or .xml configuration file and put it in the classpath. You can then, in Java, read the file off the classpath without having to use a static file path. So, if the config file were in your classpath, something like this would load it and initialize your configuration without having to keep a static path:
try { |
URL url = ApplicationStart.class.getResource("/MyConfig_log4j.xml");
DOMConfigurator.configure(url);
} catch (Exception e) {
// do something
}
Now, there are several places you can put the file and have it work. The best choice really depends on your requirements. In Studio, you can put it in deploy/java/application/classes inside of your Studio project. That way, it will deploy with your Studio project and be available automatically. That's usually the simplest as it means you don't have to maintain a copy separately on the server. Otherwise, you can place it with your custom jar files on the CVP server itself, just be sure to use the classes subdirectory instead of the lib subdirectory of wherever you are placing it.
A couple more important notes:
1. don't override the root logger unless you want to start messing with CVP's logging as well
2. don't call your file log4j.properties or log4j.xml, give it some other unique name (so you again don't mess with CVP's logging)
3. if you have logging config files in multiple Studio projects, be sure they're not configuring the same logger. Otherwise, the last one to load will override all the ones that came before it
Good luck!
05-10-2016 08:37 PM
Thank you very much Angie.
02-24-2024 11:22 PM
Did any work to add the loggers for log4j2?
I have the same code for log4j 1.x but when I am using the below log4j2 code to configure loggers it is not able to store the logs.
URI uri = LogReader.class.getResource("/log4j2.xml").toURI();
File file = new File(uri);
ConfigurationSource source = new ConfigurationSource(new FileInputStream(file), file);
Configurator.initialize(null, source);
Thanks in advance.
02-26-2024 11:17 AM
Add the folowing libraries: log4j-api-x.y.x.jar and log4j-core-x.y.z.jar to callstudio_project/deploy/java/util/lib folder. Then try the following snipped:
public class MyElement extends ActionElementBase implements ElementInterface {
static {
System.setProperty("log4j.configurationFile","C:/path/config_log4j2.properties");
}
static Logger logger = LogManager.getLogger(MyElement.class);
public void doAction(String name, ActionElementData data)
throws ElementException {
// ...
logger.info("My log message");
// ...
}
// ...
}
Also, don't forget to put the proper configuration file for log4j2 on the specified path.
03-09-2024 04:06 AM
Hi @vLoz,
Thanks for your response
I have tried using the above code but in the Cisco CVP 12.6.2, we have below log4j jar files in the Tomcat lib location.
log4j-api.jar, log4j-core.jar, and log4j-slfj18-impl.jar I am using log4j-api-4.2.17.jar and log4j-core-4.2.17.jar but when I add 4. x jar files into the application lib location it is throwing error not able to deploy the application. I have tried without adding the jar files but it is not generating any logs.
Thanks & Regards
Pradeep S
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide