Revision 56802
Added by Claudio Atzori over 5 years ago
modules/dnet-modular-logging/tags/dnet-modular-logging-1.1.6/pom.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> |
|
3 |
<parent> |
|
4 |
<groupId>eu.dnetlib</groupId> |
|
5 |
<artifactId>dnet45-parent</artifactId> |
|
6 |
<version>1.0.0</version> |
|
7 |
<relativePath /> |
|
8 |
</parent> |
|
9 |
<modelVersion>4.0.0</modelVersion> |
|
10 |
<groupId>eu.dnetlib</groupId> |
|
11 |
<artifactId>dnet-modular-logging</artifactId> |
|
12 |
<packaging>jar</packaging> |
|
13 |
<version>1.1.6</version> |
|
14 |
<scm> |
|
15 |
<developerConnection>scm:svn:https://svn.driver.research-infrastructures.eu/driver/dnet45/modules/dnet-modular-logging/tags/dnet-modular-logging-1.1.6</developerConnection> |
|
16 |
</scm> |
|
17 |
<dependencies> |
|
18 |
<dependency> |
|
19 |
<groupId>eu.dnetlib</groupId> |
|
20 |
<artifactId>cnr-misc-utils</artifactId> |
|
21 |
<version>[1.0.0,2.0.0)</version> |
|
22 |
</dependency> |
|
23 |
<dependency> |
|
24 |
<groupId>eu.dnetlib</groupId> |
|
25 |
<artifactId>cnr-spring-utils</artifactId> |
|
26 |
<version>[1.0.0,2.0.0)</version> |
|
27 |
</dependency> |
|
28 |
<dependency> |
|
29 |
<groupId>com.typesafe</groupId> |
|
30 |
<artifactId>config</artifactId> |
|
31 |
<version>0.3.1</version> |
|
32 |
</dependency> |
|
33 |
<dependency> |
|
34 |
<groupId>junit</groupId> |
|
35 |
<artifactId>junit</artifactId> |
|
36 |
<version>${junit.version}</version> |
|
37 |
<scope>test</scope> |
|
38 |
</dependency> |
|
39 |
</dependencies> |
|
40 |
</project> |
modules/dnet-modular-logging/tags/dnet-modular-logging-1.1.6/src/main/java/eu/dnetlib/common/logging/DnetLogger.java | ||
---|---|---|
1 |
package eu.dnetlib.common.logging; |
|
2 |
|
|
3 |
import java.util.Date; |
|
4 |
import java.util.Iterator; |
|
5 |
import java.util.List; |
|
6 |
import java.util.Map; |
|
7 |
import java.util.concurrent.ExecutorService; |
|
8 |
import java.util.concurrent.Executors; |
|
9 |
|
|
10 |
import javax.annotation.PostConstruct; |
|
11 |
|
|
12 |
import org.springframework.beans.factory.annotation.Required; |
|
13 |
import org.springframework.core.io.Resource; |
|
14 |
|
|
15 |
import eu.dnetlib.common.logging.conf.DnetLogConfigurationLoader; |
|
16 |
import eu.dnetlib.common.logging.dao.DnetLoggerDao; |
|
17 |
|
|
18 |
public class DnetLogger implements Iterable<Map<String, String>> { |
|
19 |
|
|
20 |
private String name; |
|
21 |
|
|
22 |
private Resource indexConf; |
|
23 |
|
|
24 |
@javax.annotation.Resource |
|
25 |
private DnetLoggerDao dao; |
|
26 |
|
|
27 |
@PostConstruct |
|
28 |
public void init() { |
|
29 |
dao.init(name); |
|
30 |
Executors.newSingleThreadExecutor().submit(() -> dao.configureIndex(name, DnetLogConfigurationLoader.getIndexedPaths(indexConf))); |
|
31 |
} |
|
32 |
|
|
33 |
public LogMessage newLogMessage(final DnetLogLevel level) { |
|
34 |
return new LogMessage(dao, name, level); |
|
35 |
} |
|
36 |
|
|
37 |
public LogMessage newLogMessage() { |
|
38 |
return newLogMessage(DnetLogLevel.INFO); |
|
39 |
} |
|
40 |
|
|
41 |
public Iterator<Map<String, String>> find(final String key, final String value) { |
|
42 |
return dao.find(name, key, value); |
|
43 |
} |
|
44 |
|
|
45 |
public Iterator<Map<String, String>> find(final Map<String, Object> criteria) { |
|
46 |
return dao.find(name, criteria); |
|
47 |
} |
|
48 |
|
|
49 |
public Map<String, String> findOne(final String key, final String value) { |
|
50 |
return dao.findOne(name, key, value); |
|
51 |
} |
|
52 |
|
|
53 |
public Iterator<Map<String, String>> find(final String cql, final List<String> fields) { |
|
54 |
return dao.find(name, cql, fields); |
|
55 |
} |
|
56 |
|
|
57 |
@Override |
|
58 |
public Iterator<Map<String, String>> iterator() { |
|
59 |
return dao.obtainLogIterator(name); |
|
60 |
} |
|
61 |
|
|
62 |
public String getName() { |
|
63 |
return name; |
|
64 |
} |
|
65 |
|
|
66 |
@Required |
|
67 |
public void setName(final String name) { |
|
68 |
this.name = name; |
|
69 |
} |
|
70 |
|
|
71 |
public Resource getIndexConf() { |
|
72 |
return indexConf; |
|
73 |
} |
|
74 |
|
|
75 |
public void setIndexConf(final Resource indexConf) { |
|
76 |
this.indexConf = indexConf; |
|
77 |
} |
|
78 |
|
|
79 |
public Iterator<Map<String, String>> range(final Date startDate, final Date endDate) { |
|
80 |
return dao.findByDateRange(name, startDate, endDate); |
|
81 |
} |
|
82 |
|
|
83 |
public Iterator<Map<String, String>> range(final Date startDate, final Date endDate, final String key, final String value) { |
|
84 |
return dao.findByDateRange(name, startDate, endDate, key, value); |
|
85 |
} |
|
86 |
|
|
87 |
public Iterator<Map<String, String>> range(final Date startDate, final Date endDate, final Map<String, Object> criteria) { |
|
88 |
return dao.findByDateRange(name, startDate, endDate, criteria); |
|
89 |
} |
|
90 |
|
|
91 |
} |
modules/dnet-modular-logging/tags/dnet-modular-logging-1.1.6/src/main/java/eu/dnetlib/common/logging/dao/DnetLoggerDao.java | ||
---|---|---|
1 |
package eu.dnetlib.common.logging.dao; |
|
2 |
|
|
3 |
import java.util.*; |
|
4 |
|
|
5 |
public interface DnetLoggerDao { |
|
6 |
|
|
7 |
void init(final String collection); |
|
8 |
|
|
9 |
void writeLog(final String collection, final Map<String, Object> map); |
|
10 |
|
|
11 |
void configureIndex(final String collection, final Map<String, IndexConf> indexConf); |
|
12 |
|
|
13 |
Iterator<Map<String, String>> obtainLogIterator(final String collection); |
|
14 |
|
|
15 |
Map<String, String> findOne(final String collection, final String key, final String value); |
|
16 |
|
|
17 |
Iterator<Map<String, String>> find(final String collection, final String key, final String value); |
|
18 |
|
|
19 |
Iterator<Map<String, String>> find(final String collection, final Map<String, Object> criteria); |
|
20 |
|
|
21 |
Iterator<Map<String, String>> findByDateRange(final String collection, final Date startDate, final Date endDate, final String key, final String value); |
|
22 |
|
|
23 |
Iterator<Map<String, String>> findByDateRange(final String collection, final Date startDate, final Date endDate); |
|
24 |
|
|
25 |
Iterator<Map<String, String>> findByDateRange(final String name, final Date startDate, final Date endDate, final Map<String, Object> criteria); |
|
26 |
|
|
27 |
Iterator<Map<String, String>> find(final String collection, final String cql, final List<String> fields); |
|
28 |
} |
modules/dnet-modular-logging/tags/dnet-modular-logging-1.1.6/src/main/java/eu/dnetlib/common/logging/dao/IndexConf.java | ||
---|---|---|
1 |
package eu.dnetlib.common.logging.dao; |
|
2 |
|
|
3 |
import java.util.Map; |
|
4 |
|
|
5 |
public class IndexConf { |
|
6 |
|
|
7 |
private String field; |
|
8 |
private Map<String, String> params; |
|
9 |
|
|
10 |
public IndexConf() {} |
|
11 |
|
|
12 |
public IndexConf(final String field, final Map<String, String> params) { |
|
13 |
super(); |
|
14 |
this.field = field; |
|
15 |
this.params = params; |
|
16 |
} |
|
17 |
|
|
18 |
public String getField() { |
|
19 |
return field; |
|
20 |
} |
|
21 |
|
|
22 |
public void setField(final String field) { |
|
23 |
this.field = field; |
|
24 |
} |
|
25 |
|
|
26 |
public Map<String, String> getParams() { |
|
27 |
return params; |
|
28 |
} |
|
29 |
|
|
30 |
public void setParams(final Map<String, String> params) { |
|
31 |
this.params = params; |
|
32 |
} |
|
33 |
|
|
34 |
} |
modules/dnet-modular-logging/tags/dnet-modular-logging-1.1.6/src/main/java/eu/dnetlib/common/logging/LogMessage.java | ||
---|---|---|
1 |
package eu.dnetlib.common.logging; |
|
2 |
|
|
3 |
import java.util.Date; |
|
4 |
import java.util.Map; |
|
5 |
|
|
6 |
import com.google.common.collect.Maps; |
|
7 |
|
|
8 |
import eu.dnetlib.common.logging.dao.DnetLoggerDao; |
|
9 |
|
|
10 |
public class LogMessage { |
|
11 |
|
|
12 |
private DnetLoggerDao dao; |
|
13 |
private String logname; |
|
14 |
private Map<String, Object> details; |
|
15 |
|
|
16 |
public static final String LOG_LEVEL_FIELD = "log:level"; |
|
17 |
public static final String LOG_DATE_FIELD = "log:date"; |
|
18 |
|
|
19 |
public LogMessage(final DnetLoggerDao dao, final String logname, final DnetLogLevel level) { |
|
20 |
this.dao = dao; |
|
21 |
this.details = Maps.newHashMap(); |
|
22 |
this.details.put(LOG_LEVEL_FIELD, level.toString()); |
|
23 |
this.details.put(LOG_DATE_FIELD, (new Date()).getTime()); |
|
24 |
this.logname = logname; |
|
25 |
} |
|
26 |
|
|
27 |
public LogMessage addDetail(final String name, final String value) { |
|
28 |
this.details.put(name, value); |
|
29 |
return this; |
|
30 |
} |
|
31 |
|
|
32 |
public LogMessage addDetails(final Map<String, String> map) { |
|
33 |
this.details.putAll(map); |
|
34 |
return this; |
|
35 |
} |
|
36 |
|
|
37 |
public void flush() { |
|
38 |
dao.writeLog(logname, details); |
|
39 |
} |
|
40 |
|
|
41 |
} |
modules/dnet-modular-logging/tags/dnet-modular-logging-1.1.6/src/main/java/eu/dnetlib/common/logging/DnetLogLevel.java | ||
---|---|---|
1 |
package eu.dnetlib.common.logging; |
|
2 |
|
|
3 |
public enum DnetLogLevel { |
|
4 |
DEBUG, INFO, WARN, ERROR, FATAL |
|
5 |
} |
modules/dnet-modular-logging/tags/dnet-modular-logging-1.1.6/src/main/java/eu/dnetlib/common/logging/conf/DnetLogConfigurationLoader.java | ||
---|---|---|
1 |
package eu.dnetlib.common.logging.conf; |
|
2 |
|
|
3 |
import java.io.IOException; |
|
4 |
import java.util.Map; |
|
5 |
import java.util.Map.Entry; |
|
6 |
|
|
7 |
import org.apache.commons.io.IOUtils; |
|
8 |
import org.springframework.core.io.Resource; |
|
9 |
|
|
10 |
import com.google.common.collect.Maps; |
|
11 |
import com.typesafe.config.Config; |
|
12 |
import com.typesafe.config.ConfigFactory; |
|
13 |
import com.typesafe.config.ConfigValue; |
|
14 |
|
|
15 |
import eu.dnetlib.common.logging.LogMessage; |
|
16 |
import eu.dnetlib.common.logging.dao.IndexConf; |
|
17 |
|
|
18 |
public class DnetLogConfigurationLoader { |
|
19 |
|
|
20 |
public static Map<String, IndexConf> getIndexedPaths(final Resource indexConf) { |
|
21 |
Map<String, IndexConf> response = Maps.newHashMap(); |
|
22 |
response.put(LogMessage.LOG_LEVEL_FIELD, null); |
|
23 |
response.put(LogMessage.LOG_DATE_FIELD, null); |
|
24 |
if (indexConf != null) { |
|
25 |
Config config = loadConfiguration(indexConf); |
|
26 |
if (config != null) { |
|
27 |
for (Entry<String, ConfigValue> e : config.getObject("dnet.log.index.conf").entrySet()) { |
|
28 |
response.put(e.getKey(), null); |
|
29 |
} |
|
30 |
} |
|
31 |
} |
|
32 |
return response; |
|
33 |
} |
|
34 |
|
|
35 |
public static final Config loadConfiguration(final Resource resource) { |
|
36 |
if (resource != null) { |
|
37 |
try { |
|
38 |
return ConfigFactory.parseString(IOUtils.toString(resource.getInputStream())); |
|
39 |
} catch (IOException e) { |
|
40 |
return null; |
|
41 |
} |
|
42 |
} |
|
43 |
return null; |
|
44 |
} |
|
45 |
|
|
46 |
} |
modules/dnet-modular-logging/tags/dnet-modular-logging-1.1.6/src/main/resources/eu/dnetlib/common/logging/applicationContext-dnet-modular-logging.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
<beans xmlns="http://www.springframework.org/schema/beans" |
|
3 |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxws="http://cxf.apache.org/jaxws" |
|
4 |
xmlns:sec="http://cxf.apache.org/configuration/security" xmlns:wsa="http://cxf.apache.org/ws/addressing" |
|
5 |
xmlns:p="http://www.springframework.org/schema/p" xmlns:http="http://cxf.apache.org/transports/http/configuration" |
|
6 |
xmlns:t="http://dnetlib.eu/springbeans/t" xmlns:template="http://dnetlib.eu/springbeans/template" |
|
7 |
xmlns:util="http://www.springframework.org/schema/util" |
|
8 |
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd |
|
9 |
http://cxf.apache.org/ws/addressing http://cxf.apache.org/schemas/ws-addr-conf.xsd |
|
10 |
http://cxf.apache.org/configuration/security http://cxf.apache.org/schemas/configuration/security.xsd |
|
11 |
http://cxf.apache.org/transports/http/configuration http://cxf.apache.org/schemas/configuration/http-conf.xsd |
|
12 |
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd |
|
13 |
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd |
|
14 |
http://dnetlib.eu/springbeans/template http://dnetlib.eu/springbeans/template.xsd"> |
|
15 |
|
|
16 |
</beans> |
modules/dnet-modular-logging/tags/dnet-modular-logging-1.1.6/deploy.info | ||
---|---|---|
1 |
{"type_source": "SVN", "goal": "package -U -T 4C source:jar", "url": "http://svn-public.driver.research-infrastructures.eu/driver/dnet45/modules/dnet-modular-logging/trunk/", "deploy_repository": "dnet45-snapshots", "version": "4", "mail": "sandro.labruzzo@isti.cnr.it,michele.artini@isti.cnr.it, claudio.atzori@isti.cnr.it, alessia.bardi@isti.cnr.it", "deploy_repository_url": "http://maven.research-infrastructures.eu/nexus/content/repositories/dnet45-snapshots", "name": "dnet-modular-logging"} |
Also available in: Unified diff
[maven-release-plugin] copy for tag dnet-modular-logging-1.1.6