Changes for page Log Rotation

Last modified by David Avendasora on 2010/11/30 06:46

From version 2.1
edited by smmccraw
on 2007/07/08 09:45
Change comment: There is no comment for this version
To version 4.1
edited by yllan
on 2008/07/18 12:51
Change comment: There is no comment for this version

Summary

Details

Page properties
Title
... ... @@ -1,1 +1,1 @@
1 -Programming__WebObjects-Web Applications-Deployment-Logging
1 +Web Applications-Deployment-Logging
Author
... ... @@ -1,1 +1,1 @@
1 -XWiki.smmccraw
1 +XWiki.yllan
Content
... ... @@ -1,51 +1,100 @@
1 -== Log Rotation ==
1 +== Log Rotation ==
2 2  
3 -=== Mike Kienenberger ===
3 +=== Mike Kienenberger ===
4 4  
5 5  I can't remember who gave me the basic starting point for this, but I think it may have been one of the Jonathans. You'll need to change the filenames to make it work under non-unix deployment systems.
6 6  
7 7  You'll find it easier to copy out the source by going into Edit mode first.
8 8  
9 -{{panel}}
9 +{{code}}
10 10  
11 - public static void main(String argv[])
12 - {
13 - try
14 - {
15 - String baseOutputPath = null;
16 -
17 - //look for a -WOOutputPath argument
18 - for (int i=0; i<argv.length; i++) {
19 - if ( argv[i].equals("-WOOutputPath") &&
20 - !argv[i+1].equals("/dev/null") ) {
21 - String outputPath = argv[i+1];
22 - baseOutputPath = outputPath;
23 - java.io.File outputFile = new java.io.File(outputPath);
24 - if (outputFile.exists()) {
25 - // move old file out of way to new location,
26 - //name based on existing name with an appended timestamp
27 -
28 - // Format the current time.
29 - java.text.SimpleDateFormat formatter = new java.text.SimpleDateFormat("yyyy-MM-dd_HH:mm:ss");
30 - java.util.GregorianCalendar now = new java.util.GregorianCalendar();
31 - String dateSuffix = ".bck-" + formatter.format(now.getTime());
32 - System.err.println("new name: " + outputPath + dateSuffix);
33 - java.io.File renamedFile = new java.io.File(outputPath + dateSuffix);
34 - outputFile.renameTo(renamedFile);
35 - }
36 - break;
37 - }
38 - }
39 - }
40 - catch (Throwable e) {
41 - //just so any Throwables generated in trying to do this don't
42 - //keep our app from launching.
43 - System.err.println("Ignoring: " + e);
44 - }
45 -
46 - WOApplication.main(argv, Application.class);
47 - }
11 + public static void main(String argv[])
12 + {
13 + try
14 + {
15 + String baseOutputPath = null;
48 48  
49 -{{/panel}}
17 + //look for a -WOOutputPath argument
18 + for (int i=0; i<argv.length; i++) {
19 + if ( argv[i].equals("-WOOutputPath") &&
20 + !argv[i+1].equals("/dev/null") ) {
21 + String outputPath = argv[i+1];
22 + baseOutputPath = outputPath;
23 + java.io.File outputFile = new java.io.File(outputPath);
24 + if (outputFile.exists()) {
25 + // move old file out of way to new location,
26 + //name based on existing name with an appended timestamp
50 50  
51 -Category:WebObjects
28 + // Format the current time.
29 + java.text.SimpleDateFormat formatter = new java.text.SimpleDateFormat("yyyy-MM-dd_HH:mm:ss");
30 + java.util.GregorianCalendar now = new java.util.GregorianCalendar();
31 + String dateSuffix = ".bck-" + formatter.format(now.getTime());
32 + System.err.println("new name: " + outputPath + dateSuffix);
33 + java.io.File renamedFile = new java.io.File(outputPath + dateSuffix);
34 + outputFile.renameTo(renamedFile);
35 + }
36 + break;
37 + }
38 + }
39 + }
40 + catch (Throwable e) {
41 + //just so any Throwables generated in trying to do this don't
42 + //keep our app from launching.
43 + System.err.println("Ignoring: " + e);
44 + }
45 +
46 + WOApplication.main(argv, Application.class);
47 + }
48 +
49 +{{/code}}
50 +
51 +=== Log4j ===
52 +
53 +Kieran Kelleher provides his configuration as an example that will log for each instance and rotate the file every day. Moreover, any errors get instantly emailed with subject line indicating which woa, host and port.
54 +
55 +{{code}}
56 +
57 +#########################################################################
58 +# ERXLogger
59 +#########################################################################
60 +# Pattern codes:
61 +# %-5p : Priority DEBUG, INFO, WARN, etc.
62 +# %d(ISO08601 : Date and time
63 +# %t : Thread
64 +# %c : Logger name (usually a class name)
65 +# %m%n : Log message arguments
66 +
67 +# Available levels are DEBUG, INFO, WARN, ERROR, FATAL
68 +
69 +# log4j appender and formatting
70 +log4j.rootLogger=WARN, A2, myMail
71 +log4j.loggerFactory=er.extensions.ERXLogger$Factory
72 +
73 +# A1 is a ConsoleAppender
74 +log4j.appender.A1=org.apache.log4j.ConsoleAppender
75 +log4j.appender.A1.layout=er.extensions.ERXPatternLayout
76 +#log4j.appender.A1.layout.ConversionPattern=%-5p %d{HH:mm:ss} (%-20c:%L) %x -%m%n
77 +log4j.appender.A1.layout.ConversionPattern=%r %-5p [%t] (%C{3}, %M, %L) - %n%m%n%n
78 +
79 +# A2 is a DailyRollingFileAppender
80 +log4j.appender.A2=org.apache.log4j.DailyRollingFileAppender
81 +log4j.appender.A2.file=/var/log/webobjects_apps/@@build.app.bundle.name@@-@@WOPort@@.log
82 +log4j.appender.A2.datePattern='.'yyyy-MM-dd
83 +log4j.appender.A2.append=true
84 +log4j.appender.A2.layout=er.extensions.ERXPatternLayout
85 +log4j.appender.A2.layout.ConversionPattern=%-5p %d{ISO8601} [%t] (%c: %L) - %m%n
86 +
87 +# myMail is the SMTPAppender
88 +log4j.appender.myMail=org.apache.log4j.net.SMTPAppender
89 +log4j.appender.myMail.Threshold=ERROR
90 +log4j.appender.myMail.BufferSize=10
91 +# log4j.appender.myMail.To=<email1>,<email2>
92 +log4j.appender.myMail.From=<removed>
93 +log4j.appender.myMail.SMTPHost=@@cheetah.smtpserver@@
94 +log4j.appender.myMail.Subject=Log4J Error (@@build.app.bundle.name@@ host @@host@@ port @@WOPort@@)
95 +log4j.appender.myMail.layout=er.extensions.ERXPatternLayout
96 +# log4j.appender.myMail.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n
97 +log4j.appender.myMail.layout.ConversionPattern=%r %-5p %d{ISO8601}%n%n%V{t total/u used/f free}%n%n[%t] %n%n (%C, %M, %F:%L) - %n%n%m%n
98 +
99 +
100 +{{/code}}