summaryrefslogtreecommitdiff
path: root/orktrack/src/net/sf/oreka/orktrack/LogManager.java
blob: bf395683de9da50cae7b92aedeec56b06ef3e456 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/*
 * Oreka -- A media capture and retrieval platform
 * 
 * Copyright (C) 2005, orecx LLC
 *
 * http://www.orecx.com
 *
 * This program is free software, distributed under the terms of
 * the GNU General Public License.
 * Please refer to http://www.gnu.org/copyleft/gpl.html
 *
 */

package net.sf.oreka.orktrack;

import java.io.File;

import net.sf.oreka.OrkException;

import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;

/**
 * This singleton class manages all application log4j loggers
 */
public class LogManager {

	static LogManager logManager = null;
	
	String ConfigFilename = null;
	
	Logger rootLogger = null;
	Logger configLogger = null;
	Logger contextLogger = null;
	Logger portLogger = null;
	Logger userLogger = null;
	Logger recurrentLogger = null;	// special logger for recurrent messages (annoying to have normally)
	
	private LogManager() 
	{
		rootLogger = Logger.getRootLogger();
		rootLogger.setLevel(Level.INFO);
		configLogger = Logger.getLogger("config");
		contextLogger = Logger.getLogger("context");
		portLogger = Logger.getLogger("port");
		userLogger = Logger.getLogger("user");
		recurrentLogger = Logger.getLogger("net.sf.oreka.recurrent");
		
	    BasicConfigurator.configure();	// in case there is no properties file
	}
	
	public static LogManager getInstance()
	{
		if (logManager == null)
		{
			logManager = new LogManager();
		}
		return logManager;
	}

	public void configure(String filename) throws OrkException {
		
		ConfigFilename = filename;
		configure();
	}
	
	public void configure() throws OrkException {
		
		// Check wether filename is valid
		File file = new File(ConfigFilename);
		if (file.exists()) {

			// Attempt to configure log4j
			PropertyConfigurator.configure(ConfigFilename);
		}
		else {
			throw new OrkException("Log4j properties file does not exist:" + ConfigFilename + " check your web.xml");
		}	
	}
	
	/**
	 * @return Returns the rootLogger.
	 */
	public Logger getRootLogger() {
		return rootLogger;
	}
	

	/**
	 * @param rootLogger The rootLogger to set.
	 */
	public void setRootLogger(Logger rootLogger) {
		this.rootLogger = rootLogger;
	}

	/**
	 * @return Returns the configLogger.
	 */
	public Logger getConfigLogger() {
		return configLogger;
	}
	

	/**
	 * @param configLogger The configLogger to set.
	 */
	public void setConfigLogger(Logger configLogger) {
		this.configLogger = configLogger;
	}

	public Logger getContextLogger() {
		return contextLogger;
	}

	public void setContextLogger(Logger contextLogger) {
		this.contextLogger = contextLogger;
	}

	public Logger getPortLogger() {
		return portLogger;
	}

	public void setPortLogger(Logger portLogger) {
		this.portLogger = portLogger;
	}

	public Logger getUserLogger() {
		return userLogger;
	}

	public void setUserLogger(Logger userLogger) {
		this.userLogger = userLogger;
	}

	public Logger getRecurrentLogger() {
		return recurrentLogger;
	}
	

	public void setRecurrentLogger(Logger recurrentLogger) {
		this.recurrentLogger = recurrentLogger;
	}
	
	
	

}