how to debug or log info in bean | Community
Skip to main content
Xena_bcn
Level 5
October 16, 2015
Solved

how to debug or log info in bean

  • October 16, 2015
  • 34 replies
  • 7521 views

hello here.

So one of my component java bean functions is not returning result I am expecting.

I added log.info  to trace , doesn't print anything.

 

Then used debug from Eclipse , doesn't stop on breakpoints.

 

Where and what I should do?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by edubey

Try this snippet of code.

Resource r = resourceResolver.getResource(path); Asset a = r.adaptTo(Asset.class); Rendition rnd = a.getOriginal(); long size = rnd.getSize();

34 replies

edubey
Level 10
October 16, 2015

I am assuming this is component in OSGI.

I prefer using this library for logging, its very helpful, can you try to integrate this. Its simple

http://www.slf4j.org/manual.html

Xena_bcn
Xena_bcnAuthor
Level 5
October 16, 2015

hi...

 

yes i am using it. but it is not printing to adobe error.log

 

and this java class is in <package>.components

 

what do you mean by component in OSGI?

edubey
Level 10
October 16, 2015

In OSGI,

Can you open logger configuration and find out whether there is a separate log file configured for your class in  which this code is present.

Also please check what is the log level setup.

Are you able to see logs of other classes ?

Link: http://localhost:4502/system/console/configMgr

edubey
Level 10
October 16, 2015

Can you please share snippet of your code?

Can you ensure that JAR files required are present in you OSGI.

Xena_bcn
Xena_bcnAuthor
Level 5
October 16, 2015

as far as I can see the core bundle is present in

http://localhost:4502/system/console/bundles

http://localhost:4502/system/console/osgi-installer

I need to show a DAM asset file size in 1 of my components.

 

So I pass here URL as for example  /content/dam/project_name/<path>/filename.pdf

 

  private int getFileSize(URL url) {
        HttpURLConnection conn = null;
        try {
            log.info(" URL : " +  url.toString());
            conn = (HttpURLConnection) url.openConnection();
            log.info(" connected");
            conn.setRequestMethod("HEAD");
            conn.getInputStream();
            
            log.info(" input streem");
            
            return conn.getContentLength();
            
           
            
        } catch (IOException e) {
            e.printStackTrace();
            return -1;
        } finally {
            conn.disconnect();
        }
  }

smacdonald2008
Level 10
October 16, 2015

Did you properly declare the logger:

/** Default log. */

protected final Logger log = LoggerFactory.getLogger(this.getClass());

the information is written to the aem log file too. 

edubey
Level 10
October 16, 2015
Hi, Can you tell me how u r executing this piece of code, are you calling this via some method in your jsp?       
smacdonald2008
Level 10
October 16, 2015

What file are you looking in? 

Adobe Employee
October 16, 2015

So the bundle that contains your java code is empty?

Did you follow the guide[1] for adding Java classes to your OSGI bundle? It seems like your maven file has not been configured correctly to include the java class. After building you bundle, you should be able to unpack the jar file and see your class file.

Regards,

Opkar

[1] https://helpx.adobe.com/experience-manager/using/creating-osgi-bundles-digital-marketing.html

Xena_bcn
Xena_bcnAuthor
Level 5
October 16, 2015

oh not mine was:

private final Logger log = LoggerFactory.getLogger(getClass());

 

I added this, compiled and deployed. but it is still not writing log.

should i restart?