Javolution 6.0.0 java
javolution.context.internal.LogContextImpl Class Reference
Inheritance diagram for javolution.context.internal.LogContextImpl:
[legend]
Collaboration diagram for javolution.context.internal.LogContextImpl:
[legend]

Public Member Functions

void prefix (Object... pfx)
 
void setLevel (Level level)
 
void suffix (Object... sfx)
 
abstract void setLevel (Level level)
 
void exit ()
 

Static Public Member Functions

static void debug (Object... message)
 
static LogContext enter ()
 
static< T extends AbstractContext > T enter (Class< T > custom)
 
static void error (Object... message)
 
static void info (Object... message)
 
static void warning (Object... message)
 
static AbstractContext current ()
 
static void inherit (AbstractContext ctx)
 

Static Public Attributes

static final Configurable< Level > LEVEL
 

Protected Member Functions

LogContext inner ()
 
void log (Level level, Object... message)
 
abstract void log (Level level, Object... message)
 
AbstractContext enterInner ()
 
AbstractContext getOuter ()
 

Static Protected Member Functions

static< T extends AbstractContext > T current (Class< T > type)
 

Private Member Functions

Level currentLevel ()
 

Static Private Member Functions

static LogContext currentLogContext ()
 

Private Attributes

Level level
 
Object[] prefix = NONE
 
Object[] suffix = NONE
 
AbstractContext outer
 

Static Private Attributes

static final Object[] NONE = new Object[0]
 
static final int[] TO_OSGI_LEVEL
 
static final ThreadLocal< AbstractContextCURRENT = new ThreadLocal<AbstractContext>()
 

Detailed Description

The default implementation of LogContext.

Definition at line 20 of file LogContextImpl.java.

Member Function Documentation

◆ current() [1/2]

static AbstractContext javolution.context.AbstractContext.current ( )
staticinherited

Returns the current context for the current thread or

null

if this thread has no context (default).

Definition at line 61 of file AbstractContext.java.

61  {
62  return AbstractContext.CURRENT.get();
63  }

References javolution.context.AbstractContext.CURRENT.

Referenced by javolution.context.LogContext.currentLogContext(), javolution.context.SecurityContext.currentSecurityContext(), javolution.text.TextContext.currentTextContext(), javolution.xml.XMLContext.currentXMLContext(), javolution.context.LocalContext.enter(), javolution.context.ConcurrentContext.enter(), and javolution.context.LocalContext.Parameter< T >.get().

Here is the caller graph for this function:

◆ current() [2/2]

static <T extends AbstractContext> T javolution.context.AbstractContext.current ( Class< T >  type)
staticprotectedinherited

Returns the current context of specified type or

null

if none.

Definition at line 69 of file AbstractContext.java.

69  {
70  AbstractContext ctx = AbstractContext.CURRENT.get();
71  while (ctx != null) {
72  if (type.isInstance(ctx))
73  return (T) ctx;
74  ctx = ctx.outer;
75  }
76  return null;
77  }

References javolution.context.AbstractContext.CURRENT, and javolution.context.AbstractContext.outer.

◆ currentLevel()

Level javolution.context.internal.LogContextImpl.currentLevel ( )
private

Definition at line 86 of file LogContextImpl.java.

86  {
87  if (LEVEL == null) return Level.DEBUG; // Only during class initialization.
88  if (level == null) return LEVEL.get();
89  return level;
90  }

References javolution.context.LogContext.Level.DEBUG, javolution.context.internal.LogContextImpl.level, and javolution.context.LogContext.LEVEL.

Referenced by javolution.context.internal.LogContextImpl.log().

Here is the caller graph for this function:

◆ currentLogContext()

static LogContext javolution.context.LogContext.currentLogContext ( )
staticprivateinherited

Definition at line 120 of file LogContext.java.

120  {
121  LogContext ctx = current(LogContext.class);
122  if (ctx != null)
123  return ctx;
124  return OSGiServices.getLogContext();
125  }

References javolution.context.AbstractContext.current(), and javolution.osgi.internal.OSGiServices.getLogContext().

Referenced by javolution.context.LogContext.debug(), javolution.context.LogContext.enter(), javolution.context.LogContext.error(), javolution.context.LogContext.info(), and javolution.context.LogContext.warning().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ debug()

static void javolution.context.LogContext.debug ( Object...  message)
staticinherited

Logs the specified debug message.

Definition at line 87 of file LogContext.java.

87  {
88  currentLogContext().log(Level.DEBUG, message);
89  }

References javolution.context.LogContext.currentLogContext(), javolution.context.LogContext.Level.DEBUG, and javolution.context.LogContext.log().

Referenced by javolution.lang.Configurable< javolution.context.LogContext.Level >.Configurable(), javolution.osgi.internal.ConfigurableListenerImpl.configurableInitialized(), javolution.osgi.internal.ConfigurableListenerImpl.configurableReconfigured(), javolution.lang.Initializer.initializeLoadedClasses(), javolution.lang.Initializer.loadClass(), and javolution.test.Perfometer< T >.printDetails().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ enter() [1/2]

static LogContext javolution.context.LogContext.enter ( )
staticinherited

Enters and returns a new log context instance.

Definition at line 94 of file LogContext.java.

94  {
96  }

References javolution.context.LogContext.currentLogContext(), and javolution.context.AbstractContext.enterInner().

Here is the call graph for this function:

◆ enter() [2/2]

static <T extends AbstractContext> T javolution.context.AbstractContext.enter ( Class< T >  custom)
staticinherited

Enters the scope of a custom context. This method raises a SecurityException if the permission to enter contexts of the specified class is not granted. For example, the following disallow entering any custom context. [code] SecurityContext ctx = SecurityContext.enter(); try { ctx.revoke(new SecurityContext.Permission(AbstractContext.class, "enter")); ... // Cannot enter any custom context. } finally { ctx.exit(); // Back to previous security settings. }[/code]


Parameters
customthe custom context to enter.
Exceptions
IllegalArgumentExceptionif the specified class default constructor cannot be instantiated.
SecurityExceptionif
SecurityContext.Permission(custom, "enter")

is not granted.
See also
SecurityContext.Permission

Definition at line 101 of file AbstractContext.java.

101  {
102  SecurityContext.check(new Permission<T>(custom, "enter"));
103  try {
104  return (T) custom.newInstance().enterInner();
105  } catch (InstantiationException e) {
106  throw new IllegalArgumentException(
107  "Cannot instantiate instance of " + custom, e);
108  } catch (IllegalAccessException e) {
109  throw new IllegalArgumentException("Cannot access " + custom, e);
110  }
111  }

References javolution.context.SecurityContext.check().

Here is the call graph for this function:

◆ enterInner()

AbstractContext javolution.context.AbstractContext.enterInner ( )
protectedinherited

Enters the scope of an inner context which becomes the current context; the previous current context becomes the outer of this context.

Returns
the inner context entered.

Definition at line 141 of file AbstractContext.java.

141  {
143  inner.outer = AbstractContext.CURRENT.get();
144  AbstractContext.CURRENT.set(inner);
145  return inner;
146  }

References javolution.context.AbstractContext.CURRENT, and javolution.context.AbstractContext.outer.

Referenced by javolution.xml.XMLContext.enter(), javolution.text.TextContext.enter(), javolution.context.LogContext.enter(), javolution.context.LocalContext.enter(), javolution.context.SecurityContext.enter(), and javolution.context.ConcurrentContext.enter().

Here is the caller graph for this function:

◆ error()

static void javolution.context.LogContext.error ( Object...  message)
staticinherited

Logs the specified error message (which may include any Throwable instance).

Definition at line 102 of file LogContext.java.

102  {
103  currentLogContext().log(Level.ERROR, message);
104  }

References javolution.context.LogContext.currentLogContext(), javolution.context.LogContext.Level.ERROR, and javolution.context.LogContext.log().

Referenced by javolution.lang.Initializer.initializeLoadedClasses().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ exit()

void javolution.context.AbstractContext.exit ( )
inherited

Exits the scope of this context; the outer of this context becomes
the current context.

Exceptions
IllegalStateExceptionif this context is not the current context.

Reimplemented in javolution.context.ConcurrentContext, and javolution.context.internal.ConcurrentContextImpl.

Definition at line 155 of file AbstractContext.java.

155  {
156  if (this != AbstractContext.CURRENT.get())
157  throw new IllegalStateException(
158  "This context is not the current context");
159  AbstractContext.CURRENT.set(outer);
160  outer = null;
161  }

References javolution.context.AbstractContext.CURRENT.

◆ getOuter()

AbstractContext javolution.context.AbstractContext.getOuter ( )
protectedinherited

Returns the outer context of this context or

null

if this context has no outer context.

Definition at line 167 of file AbstractContext.java.

167  {
168  return outer;
169  }

◆ info()

static void javolution.context.LogContext.info ( Object...  message)
staticinherited

Logs the specified info message.

Definition at line 109 of file LogContext.java.

109  {
110  currentLogContext().log(Level.INFO, message);
111  }

References javolution.context.LogContext.currentLogContext(), javolution.context.LogContext.Level.INFO, and javolution.context.LogContext.log().

Referenced by javolution.xml.internal.stream.XMLStreamReaderImpl.increaseDataBuffer(), javolution.xml.internal.stream.XMLStreamReaderImpl.increaseStack(), and javolution.test.Perfometer< T >.print().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ inherit()

static void javolution.context.AbstractContext.inherit ( AbstractContext  ctx)
staticinherited

Inherits the specified context which becomes the context of the current thread. This method is particularly useful when creating new threads to make them inherits from the context stack of the parent thread. [code] //Spawns a new thread inheriting the context of the current thread. MyThread myThread = new MyThread(); myThread.inherited = AbstractContext.current(); myThread.start(); ... class MyThread extends Thread { AbstractContext inherited; public void run() { AbstractContext.inherit(inherited); // Sets current context. ... } }[/code]

Definition at line 131 of file AbstractContext.java.

131  {
132  CURRENT.set(ctx);
133  }

Referenced by javolution.context.internal.ConcurrentThreadImpl.run().

Here is the caller graph for this function:

◆ inner()

LogContext javolution.context.internal.LogContextImpl.inner ( )
protected

Returns a new inner instance of this context inheriting the properties of this context. The new instance can be configured independently from its parent.

Reimplemented from javolution.context.AbstractContext.

Definition at line 52 of file LogContextImpl.java.

52  {
53  LogContextImpl ctx = new LogContextImpl();
54  ctx.prefix = prefix;
55  ctx.suffix = suffix;
56  ctx.level = level;
57  return ctx;
58  }

References javolution.context.internal.LogContextImpl.level, javolution.context.internal.LogContextImpl.prefix, and javolution.context.internal.LogContextImpl.suffix.

◆ log() [1/2]

void javolution.context.internal.LogContextImpl.log ( Level  level,
Object...  message 
)
protected

Definition at line 61 of file LogContextImpl.java.

61  {
62  if (level.compareTo(currentLevel()) < 0)
63  return;
64  TextBuilder tmp = new TextBuilder();
65  Throwable exception = null;
66  for (Object pfx : prefix) {
67  tmp.append(pfx); // Uses TextContext for formatting.
68  }
69  for (Object obj : message) {
70  if ((exception == null) && (obj instanceof Throwable)) {
71  exception = (Throwable) obj;
72  } else {
73  tmp.append(obj); // Uses TextContext for formatting.
74  }
75  }
76  for (Object sfx : suffix) {
77  tmp.append(sfx); // Uses TextContext for formatting.
78  }
79  int osgiLevel = TO_OSGI_LEVEL[level.ordinal()];
80  String msg = tmp.toString();
81  Object[] logServices = OSGiServices.getLogServices();
82  for (Object logService : logServices) {
83  ((LogService)logService).log(osgiLevel, msg, exception);
84  }
85  }

References javolution.text.TextBuilder.append(), javolution.context.internal.LogContextImpl.currentLevel(), javolution.osgi.internal.OSGiServices.getLogServices(), javolution.context.internal.LogContextImpl.level, javolution.context.internal.LogContextImpl.prefix, javolution.context.internal.LogContextImpl.suffix, javolution.context.internal.LogContextImpl.TO_OSGI_LEVEL, and javolution.text.TextBuilder.toString().

Here is the call graph for this function:

◆ log() [2/2]

abstract void javolution.context.LogContext.log ( Level  level,
Object...  message 
)
abstractprotectedinherited

Logs the specified message at the specified level.

Referenced by javolution.context.LogContext.debug(), javolution.context.LogContext.error(), javolution.context.LogContext.info(), and javolution.context.LogContext.warning().

Here is the caller graph for this function:

◆ prefix()

void javolution.context.internal.LogContextImpl.prefix ( Object...  prefixes)

Prefixes all messages being logged by the specified prefixes (prefixing existing prefixes if any).

Reimplemented from javolution.context.LogContext.

Definition at line 31 of file LogContextImpl.java.

31  {
32  Object[] tmp = new Object[prefix.length + pfx.length];
33  System.arraycopy(pfx, 0, tmp, 0, pfx.length);
34  System.arraycopy(prefix, 0, tmp, pfx.length, prefix.length);
35  prefix = tmp;
36  }

References javolution.context.internal.LogContextImpl.prefix.

◆ setLevel() [1/2]

void javolution.context.internal.LogContextImpl.setLevel ( Level  level)

Definition at line 39 of file LogContextImpl.java.

39  {
40  this.level = level;
41  }

References javolution.context.internal.LogContextImpl.level.

◆ setLevel() [2/2]

abstract void javolution.context.LogContext.setLevel ( Level  level)
abstractinherited

Set the logging level, messages below that level are not logged.

◆ suffix()

void javolution.context.internal.LogContextImpl.suffix ( Object...  suffixes)

Suffixes all messages being logged by the specified suffixes (suffixing existing suffixes if any).

Reimplemented from javolution.context.LogContext.

Definition at line 44 of file LogContextImpl.java.

44  {
45  Object[] tmp = new Object[suffix.length + sfx.length];
46  System.arraycopy(suffix, 0, tmp, 0, suffix.length);
47  System.arraycopy(sfx, 0, tmp, suffix.length, sfx.length);
48  suffix = tmp;
49  }

References javolution.context.internal.LogContextImpl.suffix.

◆ warning()

static void javolution.context.LogContext.warning ( Object...  message)
staticinherited

Logs the specified warning message.

Definition at line 116 of file LogContext.java.

116  {
117  currentLogContext().log(Level.WARNING, message);
118  }

References javolution.context.LogContext.currentLogContext(), javolution.context.LogContext.log(), and javolution.context.LogContext.Level.WARNING.

Referenced by javolution.text.internal.TextContextImpl.searchFormat().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ CURRENT

final ThreadLocal<AbstractContext> javolution.context.AbstractContext.CURRENT = new ThreadLocal<AbstractContext>()
staticprivateinherited

◆ level

◆ LEVEL

final Configurable<Level> javolution.context.LogContext.LEVEL
staticinherited
Initial value:
= new Configurable<Level>() {
@Override
protected Level getDefault() {
return Level.DEBUG;
}
@Override
public Level parse(String str) {
return Level.valueOf(str);
}
}

Holds the default logging level (DEBUG). This level is configurable. For example, running with the option -Djavolution.context.LogContextLEVEL=WARNING
causes the debug/info not to be logged.

Definition at line 73 of file LogContext.java.

Referenced by javolution.context.internal.LogContextImpl.currentLevel().

◆ NONE

final Object [] javolution.context.internal.LogContextImpl.NONE = new Object[0]
staticprivate

Definition at line 22 of file LogContextImpl.java.

◆ outer

AbstractContext javolution.context.AbstractContext.outer
privateinherited

Holds the outer context or

null

if none (top context).

Definition at line 50 of file AbstractContext.java.

Referenced by javolution.context.AbstractContext.current(), and javolution.context.AbstractContext.enterInner().

◆ prefix

Object [] javolution.context.internal.LogContextImpl.prefix = NONE
private

◆ suffix

Object [] javolution.context.internal.LogContextImpl.suffix = NONE
private

◆ TO_OSGI_LEVEL

final int [] javolution.context.internal.LogContextImpl.TO_OSGI_LEVEL
staticprivate
Initial value:
= { LogService.LOG_DEBUG,
LogService.LOG_INFO, LogService.LOG_WARNING, LogService.LOG_ERROR }

Definition at line 23 of file LogContextImpl.java.

Referenced by javolution.context.internal.LogContextImpl.log().


The documentation for this class was generated from the following file:
javolution.context.LogContext.currentLogContext
static LogContext currentLogContext()
Definition: LogContext.java:120
javolution.context.internal.LogContextImpl.prefix
Object[] prefix
Definition: LogContextImpl.java:27
javolution.context.LogContext.log
abstract void log(Level level, Object... message)
javolution.context.internal.LogContextImpl.level
Level level
Definition: LogContextImpl.java:26
javolution.context.internal.LogContextImpl.currentLevel
Level currentLevel()
Definition: LogContextImpl.java:86
javolution.context.AbstractContext.CURRENT
static final ThreadLocal< AbstractContext > CURRENT
Definition: AbstractContext.java:45
javolution.context.AbstractContext.inner
abstract AbstractContext inner()
javolution.context.LogContext.LEVEL
static final Configurable< Level > LEVEL
Definition: LogContext.java:73
javolution.context.LogContext.LogContext
LogContext()
Definition: LogContext.java:130
javolution.context.internal.LogContextImpl.TO_OSGI_LEVEL
static final int[] TO_OSGI_LEVEL
Definition: LogContextImpl.java:23
javolution.context.AbstractContext.outer
AbstractContext outer
Definition: AbstractContext.java:50
javolution.context.AbstractContext.current
static AbstractContext current()
Definition: AbstractContext.java:61
javolution.context.internal.LogContextImpl.suffix
Object[] suffix
Definition: LogContextImpl.java:28
javolution.context.AbstractContext.enterInner
AbstractContext enterInner()
Definition: AbstractContext.java:141
javolution.context.AbstractContext.AbstractContext
AbstractContext()
Definition: AbstractContext.java:55