Source Code Cross Referenced for Log.java in  » Web-Framework » JAT » com » jat » core » log » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Web Framework » JAT » com.jat.core.log 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.jat.core.log;
002:
003:        import java.io.File;
004:        import java.io.FileOutputStream;
005:        import java.io.IOException;
006:        import java.io.RandomAccessFile;
007:        import java.text.SimpleDateFormat;
008:        import java.util.Calendar;
009:        import java.util.Date;
010:        import java.util.GregorianCalendar;
011:        import java.util.TimeZone;
012:        import java.util.Vector;
013:
014:        import com.jat.core.config.Config;
015:
016:        /**
017:         * <p>Title: JAT</p>
018:         * <p>Description: </p>
019:         * <p>Copyright: Copyright (c) 2004 -2005 Stefano Fratini (stefano.fratini@gmail.com)</p>
020:         * <p>Distributed under the terms of the GNU Lesser General Public License, v2.1 or later</p> * @author stf
021:         * @version 1.1
022:         */
023:
024:        public class Log {
025:            /**
026:             * @param timeZone
027:             * Init the timezone used in FILE_DATE_FORMAT_
028:             */
029:            public static void init(TimeZone timeZone) throws Exception {
030:                FILE_DATE_FORMAT_.setTimeZone(timeZone);
031:            }
032:
033:            public synchronized String[] getLast(int _numRow) throws Exception {
034:                RandomAccessFile file = new RandomAccessFile(filename_, "r");
035:                Vector vect = new Vector();
036:                file.seek(0);
037:                try {
038:                    String line = file.readLine();
039:                    int numLine = 0;
040:                    while (line != null) {
041:                        numLine++;
042:                        line = file.readLine();
043:                    }
044:                    file.seek(0);
045:                    int start = numLine > _numRow ? numLine - _numRow : 0;
046:                    line = file.readLine();
047:                    numLine = 0;
048:                    while (line != null) {
049:                        numLine++;
050:                        if (numLine > start)
051:                            vect.addElement(line);
052:                        line = file.readLine();
053:                    }
054:                } finally {
055:                    file.close();
056:                }
057:                String[] ret = new String[vect.size()];
058:                for (int i = 0; i < vect.size(); i++) {
059:                    ret[i] = (String) vect.elementAt(i);
060:                }
061:                return ret;
062:            }
063:
064:            /**
065:             * @return returns true output on file or on HTML
066:             */
067:            public boolean isActivated() {
068:                return active_;
069:            }
070:
071:            public void setActive(boolean valore) {
072:                this .active_ = valore;
073:            }
074:
075:            protected Log(String _path, String _name) throws Exception {
076:                path_ = _path;
077:                name_ = _name;
078:                setFile();
079:
080:                GregorianCalendar calendar = new GregorianCalendar();
081:                dayOfYear_ = calendar.get(Calendar.DAY_OF_YEAR);
082:                String act = Config.getCurrent().getValue("log", _name);
083:                if (act != null)
084:                    active_ = act.equalsIgnoreCase("active");
085:                //if (Project.DEBUG) System.out.println("log file '"+_name+"' inited: "+(active_?"active":"not active"));
086:            }
087:
088:            /**
089:             * @param _messageString formated text of the message
090:             */
091:            protected synchronized void send(StringBuffer _messageString)
092:                    throws IOException {
093:                /*
094:                 * send
095:                 */
096:                updateFile();
097:                _messageString.append("\n");
098:                file_.write(_messageString.toString().getBytes());
099:            }
100:
101:            /**
102:             * @exception IOException
103:             * Update the file : close and reopen if
104:             * the current day is different from dayOfYear_
105:             */
106:            protected void updateFile() throws java.io.IOException {
107:                GregorianCalendar calendar = new GregorianCalendar();
108:                int dayOfYear = calendar.get(Calendar.DAY_OF_YEAR);
109:                if (dayOfYear != dayOfYear_) {
110:                    try {
111:                        file_.close();
112:                    } catch (java.io.IOException ignored) {
113:                    }
114:                    setFile();
115:                    dayOfYear_ = dayOfYear;
116:                }
117:            }
118:
119:            private void setFile() throws java.io.IOException {
120:                try {
121:                    File dir = new File(path_);
122:                    if (!dir.exists())
123:                        dir.mkdirs();
124:                    filename_ = path_ + FILE_DATE_FORMAT_.format(new Date())
125:                            + "_" + name_ + ".log";
126:                    file_ = new FileOutputStream(filename_, true);
127:                } catch (java.io.IOException ex) {
128:                    throw new java.io.IOException(
129:                            "Log::setFile:: exception for log '" + this .name_
130:                                    + "': " + ex);
131:                }
132:            }
133:
134:            /**
135:             * Name of message file format
136:             */
137:            private static final SimpleDateFormat FILE_DATE_FORMAT_ = new SimpleDateFormat(
138:                    "yyyy_MM_dd");
139:
140:            /**
141:             * output directory
142:             */
143:            private String path_;
144:
145:            /**
146:             * log name
147:             */
148:            private String name_;
149:
150:            /**
151:             * output file
152:             */
153:            private FileOutputStream file_;
154:
155:            /**
156:             * log file name
157:             */
158:            private String filename_;
159:
160:            /**
161:             * current day of CGMessageOutput object
162:             */
163:            private int dayOfYear_;
164:
165:            private boolean active_ = false;
166:
167:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.