Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Readers > Amazon Kindle > Kindle Developer's Corner

Notices

Reply
 
Thread Tools Search this Thread
Old 12-13-2013, 09:11 AM   #1
dragon123
Junior Member
dragon123 began at the beginning.
 
Posts: 3
Karma: 10
Join Date: Dec 2013
Device: kindle 4
log4j on the kindle

Hi,

I hope someone can help me. I'm trying to log some output of my kindlet, but I didn't get any log file. I tried two versions of my propertie file, but it didn't work. So what could be wrong? Is the propertie file not correct? In which directory it should be on the kindle?

Could anyone help me please? Thanks in advance.

The code of the programm is:
Code:
package kindlebeispiel;

import com.amazon.kindle.kindlet.AbstractKindlet;
import com.amazon.kindle.kindlet.KindletContext;
import com.amazon.kindle.kindlet.ui.KTextArea;

import org.apache.log4j.Logger;

public class Main extends AbstractKindlet {
    
    private static final Logger log = Logger.getLogger(Main.class);
    
    public void create(KindletContext context) {
        log.debug("test1");
        this.ctx = context;
    }

    public void start() {
        try {
            log.debug("test2");
            ctx.getRootContainer().add(new KTextArea("Hello World"));
        } catch (Throwable t) {
            t.printStackTrace();
        }
    }

    public void stop() {
    }

    public void destroy() {
    }
}
The code of the properties files is:
Code:
log4j.rootLogger=DEBUG
log4j.appender.R=org.apache.log4j.FileAppender
log4j.appender.R.File=log4j.log
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n
Code:
log4j.rootLogger=debug, R

log4j.category.kindle.KindleTerminal=info
log4j.category.kindle.KindleTerminal$Redrawer=warn

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout

# Pattern to output the caller's file name and line number.
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n

log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.R.File=/mnt/us/developer/kindlebeispiel/work/kindlebeispiel.log

log4j.appender.R.MaxFileSize=100KB
# Keep one backup file
log4j.appender.R.MaxBackupIndex=1

log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%d{dd MMM HH:mm:ss} %5p [%t] (%F:%L) - %m%n
dragon123 is offline   Reply With Quote
Old 12-13-2013, 10:46 AM   #2
knc1
Going Viral
knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.
 
knc1's Avatar
 
Posts: 17,212
Karma: 18210809
Join Date: Feb 2012
Location: Central Texas
Device: No K1, PW2, KV, KOA
check if logging is disabled at a system's level.

seems to me that was the problem (and solution) last time someone asked about this.
knc1 is offline   Reply With Quote
Advert
Old 12-13-2013, 11:03 AM   #3
dragon123
Junior Member
dragon123 began at the beginning.
 
Posts: 3
Karma: 10
Join Date: Dec 2013
Device: kindle 4
Sorry for the stupid question, but I haven't the KDK.

Where can I check that logging is disabled? Can you tell me the path please.
dragon123 is offline   Reply With Quote
Old 12-13-2013, 11:44 AM   #4
aditya3098
Guru
aditya3098 ought to be getting tired of karma fortunes by now.aditya3098 ought to be getting tired of karma fortunes by now.aditya3098 ought to be getting tired of karma fortunes by now.aditya3098 ought to be getting tired of karma fortunes by now.aditya3098 ought to be getting tired of karma fortunes by now.aditya3098 ought to be getting tired of karma fortunes by now.aditya3098 ought to be getting tired of karma fortunes by now.aditya3098 ought to be getting tired of karma fortunes by now.aditya3098 ought to be getting tired of karma fortunes by now.aditya3098 ought to be getting tired of karma fortunes by now.aditya3098 ought to be getting tired of karma fortunes by now.
 
Posts: 608
Karma: 1588610
Join Date: Jan 2012
Device: Kindle Scribe
If the thing logs to a file, you will need a kindle jailbreak. See the kual sticky prereqs. Note that you cannot publish to amazon if you've used the kindlet jb
aditya3098 is offline   Reply With Quote
Old 12-13-2013, 11:44 AM   #5
knc1
Going Viral
knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.
 
knc1's Avatar
 
Posts: 17,212
Karma: 18210809
Join Date: Feb 2012
Location: Central Texas
Device: No K1, PW2, KV, KOA
Quote:
Originally Posted by dragon123 View Post
Sorry for the stupid question, but I haven't the KDK.

Where can I check that logging is disabled? Can you tell me the path please.
What are you running the Kindlet on?
Check that system's logging settings.

PS: Nobody has (or at least uses) the KDK here.
knc1 is offline   Reply With Quote
Advert
Old 12-13-2013, 12:18 PM   #6
ixtab
(offline)
ixtab ought to be getting tired of karma fortunes by now.ixtab ought to be getting tired of karma fortunes by now.ixtab ought to be getting tired of karma fortunes by now.ixtab ought to be getting tired of karma fortunes by now.ixtab ought to be getting tired of karma fortunes by now.ixtab ought to be getting tired of karma fortunes by now.ixtab ought to be getting tired of karma fortunes by now.ixtab ought to be getting tired of karma fortunes by now.ixtab ought to be getting tired of karma fortunes by now.ixtab ought to be getting tired of karma fortunes by now.ixtab ought to be getting tired of karma fortunes by now.
 
ixtab's Avatar
 
Posts: 2,907
Karma: 6736094
Join Date: Dec 2011
Device: K3, K4, K5, KPW, KPW2
@dragon123: You're not providing enough information. Are you getting an error? If so, which? Did you bundle log4j with your application, or make sure that log4j is actually supported?

The actual file that you want to be logging to seems ok, i.e., that directory should be accessible and writable from a Kindlet without the Kindlet jailbreak.

Still, I think that log4j is a massive overkill for what you're trying to do. If all you want to do is output some text to a file, I suggest to simply write an extremely simple Logging utility yourself.

I'm using this trivial peace of code in JBPatch. You could of course create something more prowerful, with logging levels etc. - but it will still be MUCH less complicated than using a full-blown logging framework like log4j.
ixtab is offline   Reply With Quote
Old 12-13-2013, 03:00 PM   #7
bhaak
Groupie
bhaak can program the VCR without an owner's manual.bhaak can program the VCR without an owner's manual.bhaak can program the VCR without an owner's manual.bhaak can program the VCR without an owner's manual.bhaak can program the VCR without an owner's manual.bhaak can program the VCR without an owner's manual.bhaak can program the VCR without an owner's manual.bhaak can program the VCR without an owner's manual.bhaak can program the VCR without an owner's manual.bhaak can program the VCR without an owner's manual.bhaak can program the VCR without an owner's manual.
 
bhaak's Avatar
 
Posts: 164
Karma: 164969
Join Date: Dec 2011
Device: Palm IIIx, (iPhone|Kindle) Touch
Quote:
Originally Posted by dragon123 View Post
I hope someone can help me. I'm trying to log some output of my kindlet, but I didn't get any log file. I tried two versions of my propertie file, but it didn't work. So what could be wrong? Is the propertie file not correct? In which directory it should be on the kindle?
My guess is that the properties file doesn't get read and your log4j logger isn't initialized at all. Have you any log4j experience? Sometimes it can be tricky to get it to output anything

In my HackedUpReaderKindlet I'm putting the log4j.properties into the same directory in the azw2 file as the other class files and I am loading it manually. You can have a look at it on github: https://github.com/bhaak/HackedUpRea...erKindlet.java
bhaak is offline   Reply With Quote
Old 12-13-2013, 03:14 PM   #8
bhaak
Groupie
bhaak can program the VCR without an owner's manual.bhaak can program the VCR without an owner's manual.bhaak can program the VCR without an owner's manual.bhaak can program the VCR without an owner's manual.bhaak can program the VCR without an owner's manual.bhaak can program the VCR without an owner's manual.bhaak can program the VCR without an owner's manual.bhaak can program the VCR without an owner's manual.bhaak can program the VCR without an owner's manual.bhaak can program the VCR without an owner's manual.bhaak can program the VCR without an owner's manual.
 
bhaak's Avatar
 
Posts: 164
Karma: 164969
Join Date: Dec 2011
Device: Palm IIIx, (iPhone|Kindle) Touch
Quote:
Originally Posted by ixtab View Post
@dragon123: You're not providing enough information. Are you getting an error? If so, which? Did you bundle log4j with your application, or make sure that log4j is actually supported?
log4j is already on the Kindle at /opt/amazon/ebook/sdk/lib/log4j-1.2.16.jar and it works well when configured properly when writing to the allowed locations (/mnt/us/developer/kindlet_name/work/*).

Quote:
Originally Posted by ixtab View Post
Still, I think that log4j is a massive overkill for what you're trying to do. If all you want to do is output some text to a file, I suggest to simply write an extremely simple Logging utility yourself.

I'm using this trivial peace of code in JBPatch. You could of course create something more prowerful, with logging levels etc. - but it will still be MUCH less complicated than using a full-blown logging framework like log4j.
Why not using a standard solution instead of writing an inferior version yourself? Logging seems trivial but you quickly get into difficult waters. Log levels seem easy enough but what about rotating log files or multiple log files (I usually configure log4j to output errors also into a separate file)?
bhaak is offline   Reply With Quote
Old 12-13-2013, 03:44 PM   #9
ixtab
(offline)
ixtab ought to be getting tired of karma fortunes by now.ixtab ought to be getting tired of karma fortunes by now.ixtab ought to be getting tired of karma fortunes by now.ixtab ought to be getting tired of karma fortunes by now.ixtab ought to be getting tired of karma fortunes by now.ixtab ought to be getting tired of karma fortunes by now.ixtab ought to be getting tired of karma fortunes by now.ixtab ought to be getting tired of karma fortunes by now.ixtab ought to be getting tired of karma fortunes by now.ixtab ought to be getting tired of karma fortunes by now.ixtab ought to be getting tired of karma fortunes by now.
 
ixtab's Avatar
 
Posts: 2,907
Karma: 6736094
Join Date: Dec 2011
Device: K3, K4, K5, KPW, KPW2
Quote:
Originally Posted by bhaak View Post
log4j is already on the Kindle at /opt/amazon/ebook/sdk/lib/log4j-1.2.16.jar and it works well when configured properly when writing to the allowed locations (/mnt/us/developer/kindlet_name/work/*).

Why not using a standard solution instead of writing an inferior version yourself? Logging seems trivial but you quickly get into difficult waters. Log levels seem easy enough but what about rotating log files or multiple log files (I usually configure log4j to output errors also into a separate file)?
You're correct of course. I didn't even realize that the Kindles came with log4j preinstalled - so yeah, in that case your answer is probably what the OP is looking for.

That said, I personally dislike log4j for reasons I can't really explain... maybe I'm spoilt by past experiences with it.

... And IMO, the usual Kindlet isn't exactly a complex application server that requires extensive logging with 7 different log levels, log file rotation etc. As the saying goes: "use the right tools for the right job". In my particular case, the trivial solution was enough. In other cases, a more complex and powerful solution may be better.
ixtab is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Kindle Nicknaming Scheme, Using Kindle with Calibre, and Hacking the Kindle Klif Amazon Kindle 11 09-12-2012 05:11 PM
$0.01 in Kindle Store: Interactive Sudoku for Kindle 2 and Kindle DX - Volume 1 Xia Deals and Resources (No Self-Promotion or Affiliate Links) 2 11-07-2009 10:06 AM


All times are GMT -4. The time now is 07:56 AM.


MobileRead.com is a privately owned, operated and funded community.