1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.logging.script; |
21 |
|
|
22 |
|
import java.util.Collection; |
23 |
|
import java.util.HashMap; |
24 |
|
import java.util.Map; |
25 |
|
|
26 |
|
import javax.inject.Inject; |
27 |
|
import javax.inject.Named; |
28 |
|
import javax.inject.Singleton; |
29 |
|
|
30 |
|
import org.slf4j.Logger; |
31 |
|
import org.slf4j.LoggerFactory; |
32 |
|
import org.xwiki.component.annotation.Component; |
33 |
|
import org.xwiki.localization.ContextualLocalizationManager; |
34 |
|
import org.xwiki.localization.Translation; |
35 |
|
import org.xwiki.logging.LogLevel; |
36 |
|
import org.xwiki.logging.LogTree; |
37 |
|
import org.xwiki.logging.LogUtils; |
38 |
|
import org.xwiki.logging.LoggerManager; |
39 |
|
import org.xwiki.logging.event.LogEvent; |
40 |
|
import org.xwiki.script.service.ScriptService; |
41 |
|
import org.xwiki.security.authorization.ContextualAuthorizationManager; |
42 |
|
import org.xwiki.security.authorization.Right; |
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
@since |
48 |
|
@version |
49 |
|
|
50 |
|
@Component |
51 |
|
@Named("logging") |
52 |
|
@Singleton |
|
|
| 0% |
Uncovered Elements: 31 (31) |
Complexity: 9 |
Complexity Density: 0.47 |
|
53 |
|
public class LoggingScriptService implements ScriptService |
54 |
|
{ |
55 |
|
|
56 |
|
|
57 |
|
|
58 |
|
@Inject |
59 |
|
private LoggerManager loggerManager; |
60 |
|
|
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
@Inject |
65 |
|
private ContextualAuthorizationManager authorization; |
66 |
|
|
67 |
|
@Inject |
68 |
|
private ContextualLocalizationManager localization; |
69 |
|
|
70 |
|
|
71 |
|
|
72 |
|
|
73 |
|
@param |
74 |
|
@return |
75 |
|
@since |
76 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
77 |
0 |
public Logger getLogger(String name)... |
78 |
|
{ |
79 |
0 |
return LoggerFactory.getLogger(name); |
80 |
|
} |
81 |
|
|
82 |
|
|
83 |
|
|
84 |
|
|
85 |
|
@return |
86 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
87 |
0 |
public Map<String, LogLevel> getLevels()... |
88 |
|
{ |
89 |
0 |
Collection<Logger> registeredLoggers = this.loggerManager.getLoggers(); |
90 |
|
|
91 |
0 |
Map<String, LogLevel> levels = new HashMap<String, LogLevel>(registeredLoggers.size()); |
92 |
|
|
93 |
0 |
for (Logger registeredLogger : registeredLoggers) { |
94 |
0 |
levels.put(registeredLogger.getName(), getLevel(registeredLogger.getName())); |
95 |
|
} |
96 |
|
|
97 |
0 |
return levels; |
98 |
|
} |
99 |
|
|
100 |
|
|
101 |
|
@param |
102 |
|
@return |
103 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
104 |
0 |
public LogLevel getLevel(String loggerName)... |
105 |
|
{ |
106 |
0 |
return this.loggerManager.getLoggerLevel(loggerName); |
107 |
|
} |
108 |
|
|
109 |
|
|
110 |
|
@param |
111 |
|
@param |
112 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
113 |
0 |
public void setLevel(String logger, LogLevel level)... |
114 |
|
{ |
115 |
|
|
116 |
|
|
117 |
0 |
if (!this.authorization.hasAccess(Right.PROGRAM)) { |
118 |
0 |
return; |
119 |
|
} |
120 |
|
|
121 |
0 |
this.loggerManager.setLoggerLevel(logger, level); |
122 |
|
} |
123 |
|
|
124 |
|
|
125 |
|
|
126 |
|
|
127 |
|
@param |
128 |
|
@return@link |
129 |
|
@since |
130 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
131 |
0 |
public LogTree toLogTree(Iterable<LogEvent> logs)... |
132 |
|
{ |
133 |
0 |
LogTree logTree = new LogTree(); |
134 |
|
|
135 |
0 |
for (LogEvent logEvent : logs) { |
136 |
0 |
logTree.log(logEvent); |
137 |
|
} |
138 |
|
|
139 |
0 |
return logTree; |
140 |
|
} |
141 |
|
|
142 |
|
|
143 |
|
@link |
144 |
|
@link |
145 |
|
|
146 |
|
|
147 |
|
|
148 |
|
|
149 |
|
|
150 |
|
@param@link |
151 |
|
@return@link |
152 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 3 |
Complexity Density: 0.6 |
|
153 |
0 |
public LogEvent translate(LogEvent logEvent)... |
154 |
|
{ |
155 |
0 |
if (logEvent.getTranslationKey() != null) { |
156 |
0 |
Translation translation = this.localization.getTranslation(logEvent.getTranslationKey()); |
157 |
|
|
158 |
0 |
if (translation != null) { |
159 |
0 |
return LogUtils.translate(logEvent, (String) translation.getRawSource()); |
160 |
|
} |
161 |
|
} |
162 |
|
|
163 |
0 |
return logEvent; |
164 |
|
} |
165 |
|
} |