Search in sources :

Example 1 with CLogFile

use of org.compiere.util.CLogFile in project adempiere by adempiere.

the class SilentSetup method main.

/**
	 * 	Start
	 * 	@param args Log Level e.g. ALL, FINE
	 */
public static void main(String[] args) {
    CLogMgt.initialize(true);
    Handler fileHandler = new CLogFile(System.getProperty("user.dir"), false, false);
    CLogMgt.addHandler(fileHandler);
    //	Log Level
    if (args.length > 0)
        CLogMgt.setLevel(args[0]);
    else
        CLogMgt.setLevel(Level.INFO);
    //	File Logger at least FINE
    if (fileHandler.getLevel().intValue() > Level.FINE.intValue())
        fileHandler.setLevel(Level.FINE);
    new SilentSetup();
}
Also used : CLogFile(org.compiere.util.CLogFile) Handler(java.util.logging.Handler)

Example 2 with CLogFile

use of org.compiere.util.CLogFile in project adempiere by adempiere.

the class AdempiereMonitor method createLogMgtPage.

//	createSummaryPage
/**
	 * 	Add Log Management to page
	 *	@param bb body
	 */
private void createLogMgtPage(body bb) {
    bb.addElement(new hr());
    //	Ini Parameters
    table table = new table();
    table.setBorder(1);
    table.setCellSpacing(2);
    table.setCellPadding(2);
    //
    Properties ctx = new Properties();
    MSystem system = MSystem.get(ctx);
    tr line = new tr();
    line.addElement(new th().addElement(system.getDBAddress()));
    line.addElement(new td().addElement(Ini.getAdempiereHome()));
    table.addElement(line);
    //	OS + Name
    line = new tr();
    String info = System.getProperty("os.name") + " " + System.getProperty("os.version");
    String s = System.getProperty("sun.os.patch.level");
    if (s != null && s.length() > 0)
        info += " (" + s + ")";
    line.addElement(new th().addElement(info));
    info = system.getName();
    if (system.getCustomPrefix() != null)
        info += " (" + system.getCustomPrefix() + ")";
    line.addElement(new td().addElement(info));
    table.addElement(line);
    //	Java + email
    line = new tr();
    info = System.getProperty("java.vm.name") + " " + System.getProperty("java.vm.version");
    line.addElement(new th().addElement(info));
    line.addElement(new td().addElement(system.getUserName()));
    table.addElement(line);
    //	DB + Instance
    line = new tr();
    CConnection cc = CConnection.get();
    AdempiereDatabase db = cc.getDatabase();
    info = db.getDescription();
    line.addElement(new th().addElement(info));
    line.addElement(new td().addElement(cc.getConnectionURL()));
    //		line.addElement(new td().addElement(system.getDBInstance()));
    table.addElement(line);
    //	Processors/Support
    line = new tr();
    line.addElement(new th().addElement("Processor/Support"));
    line.addElement(new td().addElement(system.getNoProcessors() + "/" + system.getSupportUnits()));
    table.addElement(line);
    //	Memory
    line = new tr();
    MemoryMXBean memory = ManagementFactory.getMemoryMXBean();
    line.addElement(new th().addElement("VM Memory"));
    line.addElement(new td().addElement(new CMemoryUsage(memory.getNonHeapMemoryUsage()).toString()));
    table.addElement(line);
    line = new tr();
    line.addElement(new th().addElement("Heap Memory"));
    line.addElement(new td().addElement(new CMemoryUsage(memory.getHeapMemoryUsage()).toString()));
    table.addElement(line);
    //	Runtime
    line = new tr();
    RuntimeMXBean rt = ManagementFactory.getRuntimeMXBean();
    line.addElement(new th().addElement("Runtime " + rt.getName()));
    line.addElement(new td().addElement(TimeUtil.formatElapsed(rt.getUptime())));
    table.addElement(line);
    //	Threads
    line = new tr();
    ThreadMXBean th = ManagementFactory.getThreadMXBean();
    line.addElement(new th().addElement("Threads " + th.getThreadCount()));
    line.addElement(new td().addElement("Peak=" + th.getPeakThreadCount() + ", Demons=" + th.getDaemonThreadCount() + ", Total=" + th.getTotalStartedThreadCount()));
    table.addElement(line);
    //Transactions
    Trx[] trxs = Trx.getActiveTransactions();
    for (Trx trx : trxs) {
        if (trx != null && trx.isActive()) {
            line = new tr();
            line.addElement(new th().addElement("Active Transaction "));
            line.addElement(new td().addElement("Name=" + trx.getTrxName() + ", StartTime=" + trx.getStartTime()));
            table.addElement(line);
        }
    }
    //	Cache Reset
    line = new tr();
    line.addElement(new th().addElement(CacheMgt.get().toStringX()));
    line.addElement(new td().addElement(new a("adempiereMonitor?CacheReset=Yes", "Reset Cache")));
    table.addElement(line);
    //	Trace Level
    line = new tr();
    line.addElement(new th().addElement(new label("TraceLevel").addElement("Trace Log Level")));
    form myForm = new form("adempiereMonitor", form.METHOD_POST, form.ENC_DEFAULT);
    //	LogLevel Selection
    option[] options = new option[CLogMgt.LEVELS.length];
    for (int i = 0; i < options.length; i++) {
        options[i] = new option(CLogMgt.LEVELS[i].getName());
        options[i].addElement(CLogMgt.LEVELS[i].getName());
        if (CLogMgt.LEVELS[i] == CLogMgt.getLevel())
            options[i].setSelected(true);
    }
    select sel = new select("TraceLevel", options);
    myForm.addElement(sel);
    myForm.addElement(new input(input.TYPE_SUBMIT, "Set", "Set"));
    line.addElement(new td().addElement(myForm));
    table.addElement(line);
    //
    line = new tr();
    CLogFile fileHandler = CLogFile.get(true, null, false);
    line.addElement(new th().addElement("Trace File"));
    line.addElement(new td().addElement(new a("adempiereMonitor?Trace=" + fileHandler.getFileName(), "Current")));
    table.addElement(line);
    //
    line = new tr();
    line.addElement(new td().addElement(new a("adempiereMonitor?Trace=ROTATE", "Rotate Trace Log")));
    line.addElement(new td().addElement(new a("adempiereMonitor?Trace=DELETE", "Delete all Trace Logs")));
    table.addElement(line);
    //
    bb.addElement(table);
    //	List Log Files
    p p = new p();
    p.addElement(new b("All Log Files: "));
    //	All in dir
    File logDir = fileHandler.getLogDirectory();
    if (logDir != null && logDir.isDirectory()) {
        File[] logs = logDir.listFiles();
        for (int i = 0; i < logs.length; i++) {
            // Skip if is not a file - teo_sarca [ 1726066 ]
            if (!logs[i].isFile())
                continue;
            if (i != 0)
                p.addElement(" - ");
            String fileName = logs[i].getAbsolutePath();
            a link = new a("adempiereMonitor?Trace=" + fileName, fileName);
            p.addElement(link);
            int size = (int) (logs[i].length() / 1024);
            if (size < 1024)
                p.addElement(" (" + size + "k)");
            else
                p.addElement(" (" + size / 1024 + "M)");
        }
    }
    bb.addElement(p);
    //	Clients and Web Stores
    table = new table();
    table.setBorder(1);
    table.setCellSpacing(2);
    table.setCellPadding(2);
    //	
    line = new tr();
    MClient[] clients = MClient.getAll(ctx);
    line.addElement(new th().addElement("Client #" + clients.length + " - EMail Test:"));
    p = new p();
    for (int i = 0; i < clients.length; i++) {
        MClient client = clients[i];
        if (i > 0)
            p.addElement(" - ");
        p.addElement(new a("adempiereMonitor?EMail=" + client.getAD_Client_ID(), client.getName()));
    }
    if (clients.length == 0)
        p.addElement("&nbsp;");
    line.addElement(new td().addElement(p));
    table.addElement(line);
    //	
    line = new tr();
    MStore[] wstores = MStore.getActive();
    line.addElement(new th().addElement("Active Web Stores #" + wstores.length));
    p = new p();
    for (int i = 0; i < wstores.length; i++) {
        MStore store = wstores[i];
        if (i > 0)
            p.addElement(" - ");
        a a = new a(store.getWebContext(), store.getName());
        a.setTarget("t" + i);
        p.addElement(a);
    }
    if (wstores.length == 0)
        p.addElement("&nbsp;");
    line.addElement(new td().addElement(p));
    table.addElement(line);
    //
    bb.addElement(table);
}
Also used : org.apache.ecs.xhtml.select(org.apache.ecs.xhtml.select) org.apache.ecs.xhtml.hr(org.apache.ecs.xhtml.hr) Properties(java.util.Properties) MClient(org.compiere.model.MClient) MemoryMXBean(java.lang.management.MemoryMXBean) Trx(org.compiere.util.Trx) MSystem(org.compiere.model.MSystem) org.apache.ecs.xhtml.table(org.apache.ecs.xhtml.table) ThreadMXBean(java.lang.management.ThreadMXBean) org.apache.ecs.xhtml.a(org.apache.ecs.xhtml.a) CLogFile(org.compiere.util.CLogFile) org.apache.ecs.xhtml.b(org.apache.ecs.xhtml.b) RuntimeMXBean(java.lang.management.RuntimeMXBean) org.apache.ecs.xhtml.label(org.apache.ecs.xhtml.label) org.apache.ecs.xhtml.td(org.apache.ecs.xhtml.td) CConnection(org.compiere.db.CConnection) org.apache.ecs.xhtml.p(org.apache.ecs.xhtml.p) Timestamp(java.sql.Timestamp) org.apache.ecs.xhtml.input(org.apache.ecs.xhtml.input) AdempiereDatabase(org.compiere.db.AdempiereDatabase) org.apache.ecs.xhtml.th(org.apache.ecs.xhtml.th) org.apache.ecs.xhtml.form(org.apache.ecs.xhtml.form) CMemoryUsage(org.compiere.util.CMemoryUsage) MStore(org.compiere.model.MStore) CLogFile(org.compiere.util.CLogFile) File(java.io.File) org.apache.ecs.xhtml.tr(org.apache.ecs.xhtml.tr) org.apache.ecs.xhtml.option(org.apache.ecs.xhtml.option)

Example 3 with CLogFile

use of org.compiere.util.CLogFile in project adempiere by adempiere.

the class AdempiereMonitor method processTraceParameter.

//	processActionParameter
/**
	 * 	Process Trace Parameter
	 *	@param request request
	 *	@param response response
	 *	@return true if it was a trace request with output
	 *	@throws ServletException
	 *	@throws IOException
	 */
private boolean processTraceParameter(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    String traceCmd = WebUtil.getParameter(request, "Trace");
    String traceLevel = WebUtil.getParameter(request, "TraceLevel");
    if (traceLevel != null && traceLevel.length() > 0) {
        log.info("New Level: " + traceLevel);
        CLogMgt.setLevel(traceLevel);
        Ini.setProperty(Ini.P_TRACELEVEL, traceLevel);
        Ini.saveProperties(false);
        return false;
    }
    if (traceCmd == null || traceCmd.length() == 0)
        return false;
    log.info("Command: " + traceCmd);
    CLogFile fileHandler = CLogFile.get(false, null, false);
    //
    if (traceCmd.equals("ROTATE")) {
        if (fileHandler != null)
            fileHandler.rotateLog();
        //	re-display
        return false;
    } else if (traceCmd.equals("DELETE")) {
        File logDir = fileHandler.getLogDirectory();
        if (logDir != null && logDir.isDirectory()) {
            File[] logs = logDir.listFiles();
            for (int i = 0; i < logs.length; i++) {
                String fileName = logs[i].getAbsolutePath();
                if (fileName.equals(fileHandler.getFileName()))
                    continue;
                if (logs[i].delete())
                    log.warning("Deleted: " + fileName);
                else
                    log.warning("Not Deleted: " + fileName);
            }
        }
        //	re-display
        return false;
    }
    //	Display current log File
    if (fileHandler != null && fileHandler.getFileName().equals(traceCmd))
        fileHandler.flush();
    ////prevent local file inclusion
    if (!traceCmd.contains(Ini.getAdempiereHome())) {
        log.warning("Trying to access unauthorized system files");
        return false;
    }
    File file = new File(traceCmd);
    if (!file.exists()) {
        log.warning("Did not find File: " + traceCmd);
        return false;
    }
    if (file.length() == 0) {
        log.warning("File Length=0: " + traceCmd);
        return false;
    }
    //	Stream Log
    log.info("Streaming: " + traceCmd);
    try {
        //	timer start
        long time = System.currentTimeMillis();
        int fileLength = (int) file.length();
        //	2k Buffer
        int bufferSize = 2048;
        byte[] buffer = new byte[bufferSize];
        //
        response.setContentType("text/plain");
        response.setBufferSize(bufferSize);
        response.setContentLength(fileLength);
        //
        FileInputStream fis = new FileInputStream(file);
        ServletOutputStream out = response.getOutputStream();
        int read = 0;
        while ((read = fis.read(buffer)) > 0) out.write(buffer, 0, read);
        out.flush();
        out.close();
        fis.close();
        //
        time = System.currentTimeMillis() - time;
        double speed = (fileLength / 1024) / ((double) time / 1000);
        log.info("length=" + fileLength + " - " + time + " ms - " + speed + " kB/sec");
    } catch (IOException ex) {
        log.log(Level.SEVERE, "stream" + ex);
    }
    return true;
}
Also used : CLogFile(org.compiere.util.CLogFile) ServletOutputStream(javax.servlet.ServletOutputStream) IOException(java.io.IOException) CLogFile(org.compiere.util.CLogFile) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 4 with CLogFile

use of org.compiere.util.CLogFile in project adempiere by adempiere.

the class Setup method main.

//	actionPerformed
/**
	 * 	Start
	 * 	@param args Log Level e.g. ALL, FINE
	 */
public static void main(String[] args) {
    CLogMgt.initialize(true);
    Handler fileHandler = new CLogFile(System.getProperty("user.dir"), false, false);
    CLogMgt.addHandler(fileHandler);
    //	Log Level
    if (args.length > 0)
        CLogMgt.setLevel(args[0]);
    else
        CLogMgt.setLevel(Level.INFO);
    //	File Logger at least FINE
    if (fileHandler.getLevel().intValue() > Level.FINE.intValue())
        fileHandler.setLevel(Level.FINE);
    new Setup();
}
Also used : CLogFile(org.compiere.util.CLogFile) Handler(java.util.logging.Handler)

Aggregations

CLogFile (org.compiere.util.CLogFile)4 File (java.io.File)2 Handler (java.util.logging.Handler)2 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 MemoryMXBean (java.lang.management.MemoryMXBean)1 RuntimeMXBean (java.lang.management.RuntimeMXBean)1 ThreadMXBean (java.lang.management.ThreadMXBean)1 Timestamp (java.sql.Timestamp)1 Properties (java.util.Properties)1 ServletOutputStream (javax.servlet.ServletOutputStream)1 org.apache.ecs.xhtml.a (org.apache.ecs.xhtml.a)1 org.apache.ecs.xhtml.b (org.apache.ecs.xhtml.b)1 org.apache.ecs.xhtml.form (org.apache.ecs.xhtml.form)1 org.apache.ecs.xhtml.hr (org.apache.ecs.xhtml.hr)1 org.apache.ecs.xhtml.input (org.apache.ecs.xhtml.input)1 org.apache.ecs.xhtml.label (org.apache.ecs.xhtml.label)1 org.apache.ecs.xhtml.option (org.apache.ecs.xhtml.option)1 org.apache.ecs.xhtml.p (org.apache.ecs.xhtml.p)1 org.apache.ecs.xhtml.select (org.apache.ecs.xhtml.select)1