1 23 24 package org.objectweb.fractal.julia.logger; 25 26 import org.objectweb.fractal.api.control.IllegalLifeCycleException; 27 import org.objectweb.fractal.api.control.BindingController; 28 import org.objectweb.fractal.api.Component; 29 30 import org.objectweb.fractal.julia.control.lifecycle.LifeCycleCoordinator; 31 import org.objectweb.fractal.julia.control.binding.ContentBindingController; 32 import org.objectweb.fractal.julia.Util; 33 import org.objectweb.fractal.julia.loader.Initializable; 34 import org.objectweb.fractal.julia.loader.Tree; 35 36 import org.objectweb.util.monolog.api.Logger; 37 import org.objectweb.util.monolog.api.MonologFactory; 38 import org.objectweb.util.monolog.api.Loggable; 39 import org.objectweb.util.monolog.Monolog; 40 41 84 85 public abstract class LoggerLifeCycleMixin 86 implements LifeCycleCoordinator, Initializable 87 { 88 89 93 private LoggerLifeCycleMixin () { 94 } 95 96 100 public void initialize (final Tree args) throws Exception { 101 _super_initialize(args); 102 for (int i = 0; i < args.getSize(); ++i) { 103 Tree arg = args.getSubTree(i); 104 if (arg.getSize() == 2 && arg.getSubTree(0).equals("monolog-conf-file")) { 105 String monologConfFile = arg.getSubTree(1).toString(); 106 if (Monolog.monologFactory == Monolog.getDefaultMonologFactory()) { 107 Monolog.getMonologFactory(monologConfFile); 108 } 109 } 110 } 111 } 112 113 121 122 public boolean setFcStarted () throws IllegalLifeCycleException { 123 boolean result = _super_setFcStarted(); 124 try { 125 if (Monolog.monologFactory == Monolog.getDefaultMonologFactory()) { 126 Monolog.initialize(); 127 } 128 StringBuffer path = new StringBuffer (); 129 Util.toString(_this_weaveableC, path); 130 String s = path.toString().substring(1).replace('/', '.'); 131 MonologFactory mf = Monolog.monologFactory; 132 Logger logger = Monolog.monologFactory.getLogger(s); 133 Object content = _this_weaveableC.getFcInterface("/content"); 134 if (content instanceof Loggable) { 135 ((Loggable)content).setLogger(logger); 136 ((Loggable)content).setLoggerFactory(mf); 137 } 138 if (content instanceof ContentBindingController) { 139 ContentBindingController bc = (ContentBindingController)content; 140 bc.bindFcContent("logger", logger); 142 bc.bindFcContent("monolog-factory", mf); 143 } else if (content instanceof BindingController) { 144 BindingController bc = (BindingController)content; 145 bc.bindFc("logger", logger); 147 bc.bindFc("monolog-factory", mf); 148 } 149 } catch (Exception ignored) { 150 } 151 return result; 152 } 153 154 158 163 164 public Component _this_weaveableC; 165 166 174 175 public abstract void _super_initialize (final Tree args) throws Exception ; 176 177 185 186 public abstract boolean _super_setFcStarted() throws IllegalLifeCycleException; 187 } 188 | Popular Tags |