use of lucee.commons.io.log.log4j.LogAdapter in project Lucee by lucee.
the class Log method doStartTag.
@Override
public int doStartTag() throws PageException {
if (text == null && exception == null)
throw new ApplicationException("Wrong Context, you must define one of the following attributes [text, exception]");
PageContextImpl pci = (PageContextImpl) pageContext;
ConfigImpl config = (ConfigImpl) pageContext.getConfig();
lucee.commons.io.log.Log logger;
if (file == null) {
logger = pci.getLog(log.toLowerCase(), false);
if (logger == null) {
// for backward compatiblity
if ("console".equalsIgnoreCase(log))
logger = new LogAdapter(Log4jUtil.getConsoleLog(config, false, "cflog", Level.INFO));
else {
java.util.Collection<String> set = pci.getLogNames();
Iterator<String> it = set.iterator();
lucee.runtime.type.Collection.Key[] keys = new lucee.runtime.type.Collection.Key[set.size()];
int index = 0;
while (it.hasNext()) {
keys[index++] = KeyImpl.init(it.next());
}
throw new ApplicationException(ExceptionUtil.similarKeyMessage(keys, log, "attribute log", "log names", null, true));
}
}
} else {
logger = getFileLog(pageContext, file, charset, async);
}
String contextName = pageContext.getApplicationContext().getName();
if (contextName == null || !application)
contextName = "";
if (exception != null) {
if (StringUtil.isEmpty(text))
LogUtil.log(logger, type, contextName, exception);
else
LogUtil.log(logger, type, contextName, text, exception);
} else if (!StringUtil.isEmpty(text))
logger.log(type, contextName, text);
else
throw new ApplicationException("you must define attribute text or attribute exception with the tag cflog");
// logger.write(toStringType(type),contextName,text);
return SKIP_BODY;
}
use of lucee.commons.io.log.log4j.LogAdapter in project Lucee by lucee.
the class LogUtil method log.
public static void log(Log log, int level, String logName, String msg, Throwable t) {
if (log instanceof LogAdapter) {
log.log(level, logName, msg, t);
} else {
String em = ExceptionUtil.getMessage(t);
String est = ExceptionUtil.getStacktrace(t, false);
if (msg.equals(em))
msg = em + ";" + est;
else
msg += ";" + em + ";" + est;
if (log != null) {
log.log(level, logName, msg);
} else {
PrintStream ps = (level >= Log.LEVEL_WARN) ? System.err : System.out;
ps.println(logName + ";" + msg);
}
}
}
use of lucee.commons.io.log.log4j.LogAdapter in project Lucee by lucee.
the class Log method getFileLog.
private static lucee.commons.io.log.Log getFileLog(PageContext pc, String file, CharSet charset, boolean async) throws PageException {
ConfigImpl config = (ConfigImpl) pc.getConfig();
Resource logDir = config.getLogDirectory();
Resource res = logDir.getRealResource(file);
LogAdapter log = FileLogPool.instance.get(res, CharsetUtil.toCharset(charset));
if (log != null)
return log;
if (charset == null)
charset = CharsetUtil.toCharSet(((PageContextImpl) pc).getResourceCharset());
try {
log = new LogAdapter(Log4jUtil.getResourceLog(config, res, CharsetUtil.toCharset(charset), "cflog." + FileLogPool.toKey(file, CharsetUtil.toCharset(charset)), Level.TRACE, 5, new Listener(FileLogPool.instance, res, charset), async));
FileLogPool.instance.put(res, CharsetUtil.toCharset(charset), log);
} catch (IOException e) {
throw Caster.toPageException(e);
}
return log;
}
use of lucee.commons.io.log.log4j.LogAdapter in project Lucee by lucee.
the class LoggerAndSourceData method getLog.
public Log getLog() {
if (_log == null) {
config = ThreadLocalPageContext.getConfig(config);
layout = Log4jUtil.getLayout(cdLayout, layoutArgs);
_appender = Log4jUtil.getAppender(config, layout, name, cdAppender, appenderArgs);
_log = new LogAdapter(Log4jUtil.getLogger(config, _appender, name, level));
}
return _log;
}
Aggregations