Logging in an AIR application

209 views
Skip to first unread message

Wim Deblauwe

unread,
Mar 9, 2012, 8:48:52 AM3/9/12
to as3-commons...@googlegroups.com
Hi,

we are creating an AIR application out of our current flex application. So far, we use the TraceTarget, but this no longer works for an AIR application. Ideally, I would like to have a file somewhere on the harddisk with all log statements.

I tried the AirFileTarget and that works, but 2 remarks:
1) The asdocs should mention where this file is going to be created. I had to look in the source code to see that File.applicationStorageDirectory was used and then on this page I found the specific location per operating system.
2) It seems it is not possible to adjust the format. The source code mentions something about the headers that would need to change, but I don't care about the headers, I want a log file in the format I want

Next option I want to try is the log4j support. I am a Java developer, so I am very familiar with log4j. What I don't get is how I can specify the location of the log file when using this? Also, is there an example of configuring this logger via spring-actionscript ? I want to extenalize the logging, so I can enable DEBUG info on an installed application without having to re-compile and re-install the application.

regards,

Wim

Martin Heidegger

unread,
Mar 9, 2012, 9:10:21 AM3/9/12
to as3-commons...@googlegroups.com
Hello Wim!

Thanks for having interest in it. To your two remarks:

 1) There is a little documentation available as to how its created but I will improve it for the next release, thanks! Basically it uses the path you defined when creating a AirFileTarget called "filePattern" the DEFAULT_PATTERN (that points to the applicationStorageDirectory) is used if you don't
     use your own pattern for the log path. It is a pattern because files get generated per day & bootup. The pattern can contain "{file}" and "{date}" which will be replaced by the current SWF_SHORT_URL(or "out" if its not set) and the current date as a string. But you can set it basically to any path you like.

 2) It takes some effort to implement the format "you want". I didn't implement it because I didn't have the time :) Contribution is welcome!

The log4j implementation does not take care of loading files. That is something you have to do yourself. (I will mention that clearer in the documentation) The reason for this is that any loading requires asynchronicity and it would be the first part of the logging that is asynchronous. Also people use various frameworks/systems to load external data that I couldn't support without bloating the library. Personally I didn't see a general ground how to solve this in a way even the majority would approve (too many opinions on this around) which is why I kept it separate. All you need to do is load your file and pass it as string to the setup generator. It looks like this:

   function onLoad(event: Event) {
       LOGGER_FACTORY.setup = log4jPropertiesToSetup(_urlLoader.data);
   }

yours
Martin.

Wim Deblauwe

unread,
Mar 9, 2012, 10:46:43 AM3/9/12
to as3-commons...@googlegroups.com
Thanks for your quick answer!

How do I specify where that the log4j logger should output the logging if I don't load a log4j.properties file, but just configure it in code?

Op vrijdag 9 maart 2012 15:10:21 UTC+1 schreef Martin Heidegger het volgende:

Op vrijdag 9 maart 2012 15:10:21 UTC+1 schreef Martin Heidegger het volgende:

Wim Deblauwe

unread,
Mar 9, 2012, 10:55:54 AM3/9/12
to as3-commons...@googlegroups.com
One last question: What kind of 'java' appenders will be understood by this properties file parser?

Suppose I have this log4j.properties file:

# Set root logger level to WARN
log4j.rootLogger=WARN, FILE
log4j.appender.FILE=org.apache.log4j.appender.TimeAndSizeRollingAppender
log4j.appender.FILE.File=air-app-logging.log
log4j.appender.FILE.MaxFileSize=10MB
log4j.appender.FILE.MaxRollFileCount=20
log4j.appender.FILE.DatePattern=.yyyy-MM-dd
log4j.appender.FILE.CompressionAlgorithm=GZ
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE.layout.ConversionPattern=%d{DATE} [%t] %-5p %c{4} %x - %m%n
log4j.appender.FILE.BufferedIO=false
log4j.logger.com.mycompany=DEBUG

Will this be parsed ok ? What if I use 'org.apache.log4j.FileAppender' instead ? If this works, on what location will the log file 'air-app-logging.log' be saved ?

regards,

Wim


Op vrijdag 9 maart 2012 16:46:43 UTC+1 schreef Wim Deblauwe het volgende:

Martin Heidegger

unread,
Mar 9, 2012, 11:45:46 AM3/9/12
to as3-commons...@googlegroups.com
Hello Wim,



On Saturday, 10 March 2012 00:46:43 UTC+9, Wim Deblauwe wrote:
How do I specify where that the log4j logger should output the logging if I don't load a log4j.properties file, but just configure it in code?

I think I do not properly understand this question. Basically speaking: Loading the properties file does not do anything different but calling properties in code.
This means a properties file like:
   log4j.rootLogger=WARN, FILE

could be written in AS3 like
   import org.as3commons.logging.setup.log4j.log4j;

   log4j.rootLogger = "WARN, FILE";

You can load the air target by its class name:

   log4j.appender.FILE = org.as3commons.logging.setup.target.AirFileTarget

unfortunately right now there is no public property to the "path" in the AirFileTarget so I (someone) would need to add it (not as easy as it sounds).



log4j.rootLogger=WARN, FILE
# Set root logger level to WARN
log4j.appender.FILE=org.apache.log4j.appender.TimeAndSizeRollingAppender
log4j.appender.FILE.File=air-app-logging.log
log4j.appender.FILE.MaxFileSize=10MB
log4j.appender.FILE.MaxRollFileCount=20
log4j.appender.FILE.DatePattern=.yyyy-MM-dd
log4j.appender.FILE.CompressionAlgorithm=GZ
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE.layout.ConversionPattern=%d{DATE} [%t] %-5p %c{4} %x - %m%n
log4j.appender.FILE.BufferedIO=false
log4j.logger.com.mycompany=DEBUG

Will this be parsed ok ? What if I use 'org.apache.log4j.FileAppender' instead ? If this works, on what location will the log file 'air-app-logging.log' be saved ?

It will be parsed just fine but it will not work. (as3commons is not in the business of throwing exceptions, errors will be logged). The log4j implementation is
referring to the syntax not the existing adapters (again: Time is my enemy). So: you can reference/generate the existing Appenders (targets) as explained in the asdocs.
Since there is no "TimeAndRolling" equivalent in as3commons-logging it will not work. Here is a simple example of a log4j properties file for as3commons:

log4j.rootLogger = WARN, TRACE;
log4j.appender.TRACE = org.as3commons.logging.setup.target::TraceTarget
log4j.appender.TRACE.format = {time} {logLevel} - {shortName}{atPerson} - {message}
log4j.logger.com.mycompany=DEBUG

I hope this clarifies the current situation.

yours
Martin.

Laurent de Goede

unread,
Feb 27, 2013, 8:53:50 AM2/27/13
to as3-commons...@googlegroups.com
I tried using a custom filepattern, and even tried passing the default file pattern to see if that still works when I pass it trough. But nothing works. the AirFileTarget just works if I don't give it anything in the constructor.

new AirFileTarget() works,
new AirFileTarget("system_{file}.{date}.log") does not,
new AirFileTarget("{file}.{date}.log") doesn't eather.

ArgumentError: Error #2004: One of the parameters is invalid.
at Error$/throwError()
at flash.filesystem::File/set nativePath()
at flash.filesystem::File()
at org.as3commons.logging.setup.target::AirFileTarget/log()[C:\projects\as3-commons\as3-commons-logging\src\main\actionscript\org\as3commons\logging\setup\target\AirFileTarget.as:129]
at org.as3commons.logging.api::Logger/info()[C:\projects\as3-commons\as3-commons-logging\src\main\actionscript\org\as3commons\logging\api\Logger.as:94]

I tried debugging this, but stopped when I realized I need all the 3rd party libraries to even compile the library. I hope you can help me out.

Thanks,

Laurent

martin heidegger

unread,
Feb 27, 2013, 9:39:08 AM2/27/13
to as3-commons...@googlegroups.com
Hello Laurent,

AirFileTarget will just replace the variables, that means that if you use the full path to your file instead of just a string (that points usually to the wrong path) it should work!

new AirFileTarget(File.applicationDirectory.resolvePath("system_{file}.{date}.log").nativePath)

yours
Martin.


--
You received this message because you are subscribed to the Google Groups "as3-commons-developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to as3-commons-devel...@googlegroups.com.
To post to this group, send email to as3-commons...@googlegroups.com.
Visit this group at http://groups.google.com/group/as3-commons-developers?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Laurent de Goede

unread,
Feb 27, 2013, 9:43:12 AM2/27/13
to as3-commons...@googlegroups.com
I figured so much after I gave the source another good look. Somehow the first time I looked at it I missed that. But thanks anyway for the quick respons!
To unsubscribe from this group and stop receiving emails from it, send an email to as3-commons-developers+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages