Yusi Posted June 9, 2023 Share Posted June 9, 2023 Hello is colorful log possible in osbot? If it is can you tell me how? Quote Link to comment Share on other sites More sharing options...
ExtraBotz Posted June 9, 2023 Share Posted June 9, 2023 (edited) 16 hours ago, Yusi said: Hello is colorful log possible in osbot? If it is can you tell me how? Unfortunately this isn't available with OSBot. You would have to create a custom logger. Here is a good link on how you can modify the logger for color: https://www.baeldung.com/java-log-console-in-color Edited June 9, 2023 by ExtraBotz 1 Quote Link to comment Share on other sites More sharing options...
Malcolm Posted June 10, 2023 Share Posted June 10, 2023 here is a custom one I made ages ago. Feel free to edit it. import java.awt.Color; import java.awt.Component; import java.awt.Dimension; import java.awt.GridLayout; import java.sql.Timestamp; import java.text.SimpleDateFormat; import javax.swing.DefaultListCellRenderer; import javax.swing.DefaultListModel; import javax.swing.JFrame; import javax.swing.JList; import javax.swing.JPanel; import javax.swing.JScrollBar; import javax.swing.JScrollPane; import javax.swing.JTabbedPane; public class UltimateLogger { public UltimateLogger() { createLogger(); } public void close() { loggerFrame.setVisible(false); loggerFrame.dispose(); } public void open() { loggerFrame.setVisible(true); } private void createLogger() { JTabbedPane loggerTab = getTabbedPane(); loggerFrame = getFrame(); loggerFrame.add(loggerTab); open(); } private JFrame getFrame() { JFrame frame = new JFrame("Ultimate Logger"); final Dimension frameDimention = new Dimension(650, 350); frame.setSize(frameDimention); frame.setMinimumSize(frameDimention); return frame; } private JTabbedPane getTabbedPane() { JPanel scrollPanel = new JPanel(); scrollPane = new JScrollPane(scrollPanel); list = new JList<String>(listModel); scrollPanel.add(list); scrollPanel.setLayout(new GridLayout(1, 0)); JTabbedPane tab = new JTabbedPane(); tab.addTab("Ultimate Bot Debug", scrollPane); return tab; } public void log(String loggedString) { listModel.addElement(getOkHeader() + loggedString); list.setCellRenderer(new CellRender()); setMaximumScroll(); } public void logError(String loggedString) { listModel.addElement(getErrorHeader() + loggedString + "\n"); list.setCellRenderer(new CellRender()); setMaximumScroll(); } public void logWarning(String loggedString) { listModel.addElement(getWarningHeader() + loggedString + "\n"); list.setCellRenderer(new CellRender()); setMaximumScroll(); } private void setMaximumScroll() { JScrollBar vertical = scrollPane.getVerticalScrollBar(); vertical.setValue(vertical.getMaximum()); } private String getOkHeader() { return "[OKAY][UltimateLogger][" + getTimeStamp() + "]: "; } private String getErrorHeader() { return "[ERROR][UltimateLogger][" + getTimeStamp() + "]: "; } private String getWarningHeader() { return "[WARN][UltimateLogger][" + getTimeStamp() + "]: "; } public boolean isVisible() { return loggerFrame.isVisible(); } public static String getTimeStamp() { Timestamp timestamp = new Timestamp(System.currentTimeMillis()); return SDF.format(timestamp); } private final static SimpleDateFormat SDF = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss"); private JFrame loggerFrame; private JScrollPane scrollPane; private final DefaultListModel<String> listModel = new DefaultListModel<String>(); private JList<String> list; private static class CellRender extends DefaultListCellRenderer { @Override public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) { super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); if (value.toString().contains("ERROR")) { setForeground(Color.RED); } else if (value.toString().contains("WARN")) { setForeground(Color.ORANGE); } else { setForeground(Color.GREEN); } return this; } } } public enum LoggerSeverity { OKAY, WARN, ERROR; } 2 Quote Link to comment Share on other sites More sharing options...
Yusi Posted June 14, 2023 Author Share Posted June 14, 2023 On 6/10/2023 at 9:08 AM, Malcolm said: here is a custom one I made ages ago. Feel free to edit it. import java.awt.Color; import java.awt.Component; import java.awt.Dimension; import java.awt.GridLayout; import java.sql.Timestamp; import java.text.SimpleDateFormat; import javax.swing.DefaultListCellRenderer; import javax.swing.DefaultListModel; import javax.swing.JFrame; import javax.swing.JList; import javax.swing.JPanel; import javax.swing.JScrollBar; import javax.swing.JScrollPane; import javax.swing.JTabbedPane; public class UltimateLogger { public UltimateLogger() { createLogger(); } public void close() { loggerFrame.setVisible(false); loggerFrame.dispose(); } public void open() { loggerFrame.setVisible(true); } private void createLogger() { JTabbedPane loggerTab = getTabbedPane(); loggerFrame = getFrame(); loggerFrame.add(loggerTab); open(); } private JFrame getFrame() { JFrame frame = new JFrame("Ultimate Logger"); final Dimension frameDimention = new Dimension(650, 350); frame.setSize(frameDimention); frame.setMinimumSize(frameDimention); return frame; } private JTabbedPane getTabbedPane() { JPanel scrollPanel = new JPanel(); scrollPane = new JScrollPane(scrollPanel); list = new JList<String>(listModel); scrollPanel.add(list); scrollPanel.setLayout(new GridLayout(1, 0)); JTabbedPane tab = new JTabbedPane(); tab.addTab("Ultimate Bot Debug", scrollPane); return tab; } public void log(String loggedString) { listModel.addElement(getOkHeader() + loggedString); list.setCellRenderer(new CellRender()); setMaximumScroll(); } public void logError(String loggedString) { listModel.addElement(getErrorHeader() + loggedString + "\n"); list.setCellRenderer(new CellRender()); setMaximumScroll(); } public void logWarning(String loggedString) { listModel.addElement(getWarningHeader() + loggedString + "\n"); list.setCellRenderer(new CellRender()); setMaximumScroll(); } private void setMaximumScroll() { JScrollBar vertical = scrollPane.getVerticalScrollBar(); vertical.setValue(vertical.getMaximum()); } private String getOkHeader() { return "[OKAY][UltimateLogger][" + getTimeStamp() + "]: "; } private String getErrorHeader() { return "[ERROR][UltimateLogger][" + getTimeStamp() + "]: "; } private String getWarningHeader() { return "[WARN][UltimateLogger][" + getTimeStamp() + "]: "; } public boolean isVisible() { return loggerFrame.isVisible(); } public static String getTimeStamp() { Timestamp timestamp = new Timestamp(System.currentTimeMillis()); return SDF.format(timestamp); } private final static SimpleDateFormat SDF = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss"); private JFrame loggerFrame; private JScrollPane scrollPane; private final DefaultListModel<String> listModel = new DefaultListModel<String>(); private JList<String> list; private static class CellRender extends DefaultListCellRenderer { @Override public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) { super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); if (value.toString().contains("ERROR")) { setForeground(Color.RED); } else if (value.toString().contains("WARN")) { setForeground(Color.ORANGE); } else { setForeground(Color.GREEN); } return this; } } } public enum LoggerSeverity { OKAY, WARN, ERROR; } Damn thank you thats a lot Quote Link to comment Share on other sites More sharing options...