BrightSide Workbench Full Report + Source Code
SystemLogger.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2021 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 package org.turro.log;
20 
21 import java.util.Date;
22 import org.turro.action.Plugins;
23 import org.turro.annotation.ElephantLogger;
24 import org.turro.collections.CollectionUtil;
25 import org.turro.entities.Entities;
26 import org.turro.reflection.Instances;
27 
33 public class SystemLogger {
34 
35  private static ISystemLogger INSTANCE;
36 
37  public static ISystemLogger getInstance() {
38  if(INSTANCE == null) {
39  INSTANCE = CollectionUtil.from(Instances.cached().byAnnotation(ElephantLogger.class, ISystemLogger.class)).first();
40  }
41  return INSTANCE;
42  }
43 
44  public static ILogWrapper info() {
45  return getInstance().info();
46  }
47 
48  public static ILogWrapper warning() {
49  return getInstance().warning();
50  }
51 
52  public static ILogWrapper severe() {
53  return getInstance().severe();
54  }
55 
57  return getInstance().type(type);
58  }
59 
60  public static ILogButton getAnchor(Object generator, Object entity) {
61  return getAnchor(Entities.getController(generator).getPath(), Entities.getController(entity).getPath());
62  }
63 
64  public static ILogButton getAnchor(String generatorPath, String entityPath) {
65  ILogButton button = Plugins.loadImplementation(ILogButton.class, "log-anchor");
66  if(button != null) {
67  button.setGeneratorPath(generatorPath);
68  button.setEntityPath(entityPath);
69  }
70  return button;
71  }
72 
73  public static ILogButton getButton(Object generator, Object entity) {
74  return getButton(Entities.getController(generator).getPath(), Entities.getController(entity).getPath());
75  }
76 
77  public static ILogButton getButton(String generatorPath, String entityPath) {
78  ILogButton button = Plugins.loadImplementation(ILogButton.class, "log-button");
79  if(button != null) {
80  button.setGeneratorPath(generatorPath);
81  button.setEntityPath(entityPath);
82  }
83  return button;
84  }
85 
86  public static long getCountOf(String comment, String entityPath, Date since) {
87  return getInstance().getCountOf(comment, entityPath, since);
88  }
89 
90  public static void cleanup(String entityPath) {
91  getInstance().cleanup(entityPath);
92  }
93 
94  private SystemLogger() {
95  }
96 
97 }
static< T > T loadImplementation(Class< T > jclass)
Definition: Plugins.java:57
static IElephantEntity getController(String path)
Definition: Entities.java:78
static ILogButton getButton(String generatorPath, String entityPath)
static long getCountOf(String comment, String entityPath, Date since)
static void cleanup(String entityPath)
static ILogButton getAnchor(String generatorPath, String entityPath)
static ISystemLogger getInstance()
static ILogWrapper type(SystemLogType type)
static ILogWrapper severe()
static ILogButton getButton(Object generator, Object entity)
static ILogWrapper info()
static ILogButton getAnchor(Object generator, Object entity)
static ILogWrapper warning()
void setEntityPath(String entityPath)
void setGeneratorPath(String generatorPath)
long getCountOf(String comment, String logPath, Date since)
void cleanup(String logPath)
ILogWrapper type(SystemLogType type)