]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.diagram/src/org/simantics/diagram/LogManager.java
Get new subscription item unit value from previously stored defaults
[simantics/platform.git] / bundles / org.simantics.diagram / src / org / simantics / diagram / LogManager.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.diagram;
13
14 import java.util.Properties;
15
16 import org.apache.log4j.Hierarchy;
17 import org.apache.log4j.Level;
18 import org.apache.log4j.Logger;
19 import org.apache.log4j.PropertyConfigurator;
20 import org.apache.log4j.spi.LoggerFactory;
21 import org.apache.log4j.spi.RootLogger;
22
23 /**
24  * This class encapsulates a Log4J Hierarchy and centralizes all Logger access.
25  */
26 public class LogManager {
27
28     private Hierarchy hierarchy;
29
30     /**
31      * Creates a new LogManager. Saves the log and state location.
32      * Creates a new Hierarchy and add a new EventListener to it.
33      * Configure the hierarchy with the properties passed. Add this object to
34      * the list of active log managers.
35      * 
36      * @param properties log configuration properties
37      */
38     public LogManager(Properties properties) {
39         this.hierarchy = new Hierarchy(new RootLogger(Level.DEBUG));
40         new PropertyConfigurator().doConfigure(properties, this.hierarchy);
41     }
42
43     /**
44      * Checks if this PluginLogManager is disabled for this level.
45      * 
46      * @param level level value
47      * @return boolean true if it is disabled
48      */
49     public boolean isDisabled(int level) {
50         return this.hierarchy.isDisabled(level);
51     }
52
53     /**
54      * Enable logging for logging requests with level l or higher. By default
55      * all levels are enabled.
56      * 
57      * @param level level object
58      */
59     public void setThreshold(Level level) {
60         this.hierarchy.setThreshold(level);
61     }
62
63     /**
64      * The string version of setThreshold(Level level)
65      * 
66      * @param level level string
67      */
68     public void setThreshold(String level) {
69         this.hierarchy.setThreshold(level);
70     }
71
72     /**
73      * Get the repository-wide threshold.
74      * 
75      * @return Level
76      */
77     public Level getThreshold() {
78         return this.hierarchy.getThreshold();
79     }
80
81     /**
82      * Returns a new logger instance named as the first parameter using the
83      * default factory. If a logger of that name already exists, then it will be
84      * returned. Otherwise, a new logger will be instantiated and then linked
85      * with its existing ancestors as well as children.
86      * 
87      * @param clazz the class to get the logger for
88      * @return Logger
89      */
90     public Logger getLogger(Class<?> clazz) {
91         return this.hierarchy.getLogger(clazz.getName());
92     }
93
94     /**
95      * Returns a new logger instance named as the first parameter using the
96      * default factory. If a logger of that name already exists, then it will be
97      * returned. Otherwise, a new logger will be instantiated and then linked
98      * with its existing ancestors as well as children.
99      * 
100      * @param name logger name
101      * @return Logger
102      */
103     public Logger getLogger(String name) {
104         return this.hierarchy.getLogger(name);
105     }
106
107     /**
108      * The same as getLogger(String name) but using a factory instance instead
109      * of a default factory.
110      * 
111      * @param name logger name
112      * @param factory factory instance
113      * @return Logger
114      */
115     public Logger getLogger(String name, LoggerFactory factory) {
116         return this.hierarchy.getLogger(name, factory);
117     }
118
119     /**
120      * Returns the root of this hierarchy.
121      * 
122      * @return Logger
123      */
124     public Logger getRootLogger() {
125         return this.hierarchy.getRootLogger();
126     }
127
128     /**
129      * Checks if this logger exists.
130      * 
131      * @return Logger
132      */
133     public Logger exists(String name) {
134         return this.hierarchy.exists(name);
135     }
136
137     /**
138      * Disposes the logger hierarchy
139      */
140     public void shutdown() {
141         this.hierarchy.shutdown();
142     }
143
144     /**
145      * Resets configuration values to its defaults.
146      */
147     public void resetConfiguration() {
148         this.hierarchy.resetConfiguration();
149     }
150
151 }