summaryrefslogtreecommitdiff
path: root/webapps/qooxdoo-0.6.3-sdk/frontend/framework/source/class/qx/dev/log/LogEventProcessor.js
blob: c6c4a8ed3380234a87fcd401514b078152851591 (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
/* ************************************************************************

   qooxdoo - the new era of web development

   http://qooxdoo.org

   Copyright:
     2006 by STZ-IDA, Germany, http://www.stz-ida.de

   License:
     LGPL 2.1: http://www.gnu.org/licenses/lgpl.html

   Authors:
     * Til Schneider (til132)

************************************************************************ */

/* ************************************************************************

#module(core)

************************************************************************ */

/**
 * Processes log events. May be configured with filters in order to specify
 * which log events should be processed.
 */
qx.OO.defineClass("qx.dev.log.LogEventProcessor", qx.core.Object,
function() {
  qx.core.Object.call(this);
});


/**
 * Appends a filter to the filter chain.
 *
 * @param filter {Filter} The filter to append.
 */
qx.Proto.addFilter = function(filter) {
  if (this._filterArr == null) {
    this._filterArr = []
  }
  this._filterArr.push(filter);
}


/**
 * Clears the filter chain.
 */
qx.Proto.clearFilters = function() {
  this._filterArr = null;
}


/**
 * Returns the head filter from the chain. Returns null if there are no filters.
 *
 * @return {Filter} the head filter from the chain.
 */
qx.Proto.getHeadFilter = function() {
  return (this._filterArr == null || this._filterArr.length == 0) ? null : this._filterArr[0];
}


/**
 * Returns the default filter from the chain. If the head filter is no default
 * filter, the chain will be cleared and a default filter will be created.
 *
 * @return {Filter} the default filter.
 */
qx.Proto._getDefaultFilter = function() {
  var headFilter = this.getHeadFilter();
  if (! (headFilter instanceof qx.dev.log.DefaultFilter)) {
    // The head filter of the appender is no DefaultFilter
    // (or the appender has no filters at all)
    // -> Create a default handler and append it
    this.clearFilters();
    headFilter = new qx.dev.log.DefaultFilter();
    this.addFilter(headFilter);
  }

  return headFilter;
}


/**
 * Sets whether event processing should be enabled.
 * <p>
 * Note: This will clear all custom filters.
 *
 * @param enabled {boolean} whether event processing should be enabled.
 */
qx.Proto.setEnabled = function(enabled) {
  this._getDefaultFilter().setEnabled(enabled);
}


/**
 * Sets the min level an event must have in order to be processed.
 * <p>
 * Note: This will clear all custom filters.
 *
 * @param minLevel {int} the new min level.
 */
qx.Proto.setMinLevel = function(minLevel) {
  this._getDefaultFilter().setMinLevel(minLevel);
}


/**
 * Decides whether a log event is processed.
 *
 * @param evt {Map} the event to check.
 * @return {int} {@link Filter#ACCEPT}, {@link Filter#DENY} or
 *     {@link Filter#NEUTRAL}.
 */
qx.Proto.decideLogEvent = function(evt) {
  var NEUTRAL = qx.dev.log.Filter.NEUTRAL;

  if (this._filterArr != null) {
    for (var i = 0; i < this._filterArr.length; i++) {
      var decision = this._filterArr[i].decide(evt);
      if (decision != NEUTRAL) {
        return decision;
      }
    }
  }

  // All filters are neutral, so are we
  return NEUTRAL;
}


/**
 * Processes a log event.
 *
 * @param evt {Map} The log event to process.
 */
qx.Proto.handleLogEvent = function(evt) {
  throw new Error("handleLogEvent is abstract");
}