org.jpos.util.Logger类的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(6.7k)|赞(0)|评价(0)|浏览(247)

本文整理了Java中org.jpos.util.Logger类的一些代码示例,展示了Logger类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Logger类的具体详情如下:
包路径:org.jpos.util.Logger
类名称:Logger

Logger介绍

[英]Peer class Logger forwards LogEvents generated by LogSources to LogListeners.
This little tutorial give you additional information on how to extend the jPOS's Logger subsystem.
[中]对等类记录器将LogSources生成的LogEvents转发给LogListeners。
这个小小的tutorial为您提供了关于如何扩展jPOS的记录器子系统的额外信息。

代码示例

代码示例来源:origin: jpos/jPOS

/**
 * @param b - new Usable state (used by ISOMUX internals to
 * flag as unusable in order to force a reconnection)
 */
public void setUsable(boolean b) {
  Logger.log (new LogEvent (this, "usable", b));
  usable = b;
}
/**

代码示例来源:origin: jpos/jPOS

protected void initService () {
  logger = Logger.getLogger (getName());
}
protected void startService () throws ConfigurationException, IOException {

代码示例来源:origin: jpos/jPOS

/**
 * Execute SQL Query. 
 * @param sql  sql command
 * @param conn sql connection
 * @return ResultSet (please close() it after using - thanks)
 * @exception SQLException
 */
public ResultSet executeQuery (String sql, Connection conn) 
  throws SQLException
{
  Statement s = null;
  ResultSet rs;
  s = conn.createStatement();
  if (logger != null && logger.hasListeners()) 
    Logger.log (new LogEvent (this, "sql-query", sql));
  return s.executeQuery (sql);
}

代码示例来源:origin: jpos/jPOS

public Log getLog () {
  if (log == null) {
    Logger logger = Logger.getLogger (LOGGER_NAME);
    if (!hasSystemLogger && !logger.hasListeners() && cli == null)
      logger.addListener (new SimpleLogListener (System.out));
    log = new Log (logger, REALM);
  }
  return log;
}
public MBeanServer getMBeanServer () {

代码示例来源:origin: jpos/jPOS

public static void log (LogEvent evt) {
  Logger l = null;
  LogSource source = evt.getSource();
  if (source != null)
    l = source.getLogger();
  if (l == null && !evt.isHonorSourceLogger()) {
    l = getLogger(Q2.LOGGER_NAME);
  }
  if (l != null && l.hasListeners ()) {
    Iterator i = l.listeners.iterator();
    while (i.hasNext() && evt != null) {
      try {
        evt = ((LogListener) i.next()).log(evt);
      } catch (Throwable t) {
        evt.addMessage (t);
      }
    }
  }
}
/**

代码示例来源:origin: jpos/jPOS

@Test
public void testLog() throws Throwable {
  Logger.log(new LogEvent(new SimpleLogSource(Logger.getLogger("testLoggerName"), "testLoggerRealm"), "testLoggerTag",
      "testString"));
  assertTrue("Test completed without Exception", true);
}

代码示例来源:origin: jpos/jPOS

@Test
public void testConstructorThrowsNullPointerException2() throws Throwable {
  Configuration cfg = new SubConfiguration();
  try {
    new JCESecurityModule(cfg, new Logger(), "testJCESecurityModuleRealm");
    fail("Expected NullPointerException to be thrown");
  } catch (NullPointerException ex) {
    assertNull("ex.getMessage()", ex.getMessage());
  }
}

代码示例来源:origin: jpos/jPOS

private ChannelAdaptor configureAndStart(ChannelAdaptor channelAdaptor, LogListener... logListener) {
  Logger logger = new Logger();
  for (LogListener listener : logListener) {
    logger.addListener(listener);
  }
  logger.setName("testLinkLogger");
  channelAdaptor.setName(LINK_NAME);
  channelAdaptor.setLogger(logger.getName());
  channelAdaptor.setPersist(createConfiguration());
  channelAdaptor.init();
  channelAdaptor.start();
  return channelAdaptor;
}

代码示例来源:origin: jpos/jPOS

@Before
public void setUp() throws Exception {
  logger = new Logger();
  logger.addListener(new SimpleLogListener());
}

代码示例来源:origin: jpos/jPOS

@Test
public void testRemoveAllListeners1() throws Throwable {
  Logger logger = new Logger();
  logger.addListener(new FilterLogListener());
  logger.addListener(new RotateLogListener());
  logger.removeAllListeners();
  assertEquals("m_logger.listeners.size()", 0, logger.listeners.size());
}

代码示例来源:origin: jpos/jPOS

@Test
public void testHasListeners() throws Throwable {
  Logger logger = new Logger();
  logger.addListener(new SimpleLogListener());
  boolean result = logger.hasListeners();
  assertTrue("result", result);
}

代码示例来源:origin: jpos/jPOS

@Test
public void testRemoveAllListeners() throws Throwable {
  Logger logger = Logger.getLogger("testLoggerName");
  LogListener l = new SimpleLogListener();
  logger.addListener(l);
  logger.removeAllListeners();
  assertEquals("m_logger.listeners.size()", 0, logger.listeners.size());
  assertFalse("m_logger.listeners.contains(l)", logger.listeners.contains(l));
}

代码示例来源:origin: jpos/jPOS

@Test
public void testDestroy1() throws Throwable {
  Logger logger = new Logger();
  logger.addListener(new SimpleLogListener());
  logger.addListener(new ExceptionLogFilter());
  logger.destroy();
  assertEquals("m_logger.listeners.size()", 0, logger.listeners.size());
}

代码示例来源:origin: jpos/jPOS

@Test
public void testGetLogger() throws Throwable {
  Logger result = Logger.getLogger("testLoggerName");
  assertEquals("result.getName()", "testLoggerName", result.getName());
}

代码示例来源:origin: jpos/jPOS

@Test
public void testHasListeners1() throws Throwable {
  boolean result = new Logger().hasListeners();
  assertFalse("result", result);
}

代码示例来源:origin: jpos/jPOS

@Test
public void testGetName() throws Throwable {
  String result = new Logger().getName();
  assertEquals("result", "", result);
}

代码示例来源:origin: jpos/jPOS

@Test
public void testRemoveAllListeners3() throws Throwable {
  Logger logger = new Logger();
  logger.removeAllListeners();
  assertEquals("m_logger.listeners.size()", 0, logger.listeners.size());
}

代码示例来源:origin: jpos/jPOS

@Test
public void testRemoveListener() throws Throwable {
  Logger logger = new Logger();
  logger.removeListener(new SimpleLogListener());
  assertEquals("m_logger.listeners.size()", 0, logger.listeners.size());
}

代码示例来源:origin: jpos/jPOS

public void exec(CLIContext cli, String[] args) throws Exception {
  this.p = new PrintStream(cli.getReader().getTerminal().output());
  this.cli = cli;
  this.ansi = false; // cli.getReader().getTerminal().isAnsiSupported();
  if (args.length == 1) {
    usage(cli);
    return;
  }
  for (int i = 1; i < args.length; i++) {
    try {
      Logger logger = (Logger) NameRegistrar.get("logger." + args[i]);
      logger.addListener(this);
    } catch (NameRegistrar.NotFoundException e) {
      cli.println("Logger " + args[i] + " not found -- ignored.");
    }
  }
  // cli.getReader().readCharacter(new char[]{'q', 'Q'});
  cli.getReader().readLine();
  for (int i = 1; i < args.length; i++) {
    try {
      Logger logger = (Logger) NameRegistrar.get("logger." + args[i]);
      logger.removeListener(this);
    } catch (NameRegistrar.NotFoundException ignored) {
      // NOPMD OK to happen
    }
  }
}

代码示例来源:origin: jpos/jPOS

private void addListener (Element e)
    throws ConfigurationException
  {
    QFactory factory = getServer().getFactory();
    String clazz  = e.getAttributeValue ("class");
    LogListener listener = (LogListener) factory.newInstance (clazz);
    if (listener instanceof Configurable) {
      try {
        ((Configurable) listener).setConfiguration (
          factory.getConfiguration (e)
        );
      } catch (ConfigurationException ex) {
        throw new ConfigurationException (ex);
      }
    }
    if (listener instanceof XmlConfigurable) {
      try {
        ((XmlConfigurable) listener).setConfiguration (e);
      } catch (ConfigurationException ex) {
        throw new ConfigurationException (ex);
      }
    }
    logger.addListener (listener);
  }
}

相关文章