1 package org.codehaus.plexus.container.initialization;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 import org.codehaus.plexus.PlexusConstants;
20 import org.codehaus.plexus.PlexusContainer;
21 import org.codehaus.plexus.component.composition.CycleDetectedInComponentGraphException;
22 import org.codehaus.plexus.component.repository.ComponentDescriptor;
23 import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
24 import org.codehaus.plexus.logging.Logger;
25 import org.codehaus.plexus.logging.LoggerManager;
26 import org.codehaus.plexus.logging.console.ConsoleLoggerManager;
27
28
29 public class InitializeLoggerManagerPhase extends AbstractCoreComponentInitializationPhase {
30 public void initializeCoreComponent(ContainerInitializationContext context)
31 throws ContainerInitializationException {
32 LoggerManager loggerManager = context.getContainer().getLoggerManager();
33
34
35
36
37
38
39
40
41 if (loggerManager == null) {
42 try {
43 loggerManager = context.getContainer().lookup(LoggerManager.class);
44 } catch (ComponentLookupException e) {
45 ComponentDescriptor cd = new ComponentDescriptor();
46
47 cd.setRole(LoggerManager.ROLE);
48
49 cd.setRoleHint(PlexusConstants.PLEXUS_DEFAULT_HINT);
50
51 cd.setImplementation(ConsoleLoggerManager.class.getName());
52
53 try {
54 context.getContainer().addComponentDescriptor(cd);
55 } catch (CycleDetectedInComponentGraphException cre) {
56 throw new ContainerInitializationException("Error setting up logging manager.", cre);
57 }
58
59 loggerManager = new ConsoleLoggerManager("info");
60 }
61
62 context.getContainer().setLoggerManager(loggerManager);
63 }
64
65 Logger logger = loggerManager.getLoggerForComponent(PlexusContainer.class.getName());
66
67 context.getContainer().enableLogging(logger);
68 }
69 }