com.alibaba.csp.sentinel.log.LogBase Java Examples
The following examples show how to use
com.alibaba.csp.sentinel.log.LogBase.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EagleEyeLogUtilTest.java From Sentinel-Dashboard-Nacos with Apache License 2.0 | 6 votes |
@Test public void testChangeLogBase() throws Exception { String userHome = System.getProperty("user.home"); String newLogBase = userHome + File.separator + "tmpLogDir" + System.currentTimeMillis(); System.setProperty(LogBase.LOG_DIR, newLogBase); EagleEyeLogUtil.log("resourceName", "BlockException", "app1", "origin", 1); final File file = new File(RecordLog.getLogBaseDir() + EagleEyeLogUtil.FILE_NAME); await().timeout(2, TimeUnit.SECONDS) .until(new Callable<File>() { @Override public File call() throws Exception { return file; } }, FileMatchers.anExistingFile()); }
Example #2
Source File: ConfigPropertyHelper.java From Sentinel with Apache License 2.0 | 6 votes |
public static void runWithConfig(Properties prop, String appName, Task task) throws Exception { if (prop == null || appName == null || "".equals(appName)) { throw new IllegalArgumentException("Prop and appName cannot be empty"); } // Set application name property. setAppNameProperty(appName); // Save the config. String path = LogBase.getLogBaseDir() + appName + ".properties"; File file = new File(path); if (!file.exists()) { file.createNewFile(); } OutputStream outputStream = new FileOutputStream(file); prop.store(outputStream,""); outputStream.close(); // Run the procedure. task.run(); // Clean-up. file.delete(); // Clear application name property. clearAppNameProperty(); }
Example #3
Source File: EagleEyeLogUtilTest.java From Sentinel with Apache License 2.0 | 6 votes |
public void testChangeLogBase() throws Exception { String userHome = System.getProperty("user.home"); String newLogBase = userHome + File.separator + "tmpLogDir" + System.currentTimeMillis(); System.setProperty(LogBase.LOG_DIR, newLogBase); EagleEyeLogUtil.log("resourceName", "BlockException", "app1", "origin", 1); final File file = new File(LogBase.getLogBaseDir() + EagleEyeLogUtil.FILE_NAME); await().timeout(2, TimeUnit.SECONDS) .until(new Callable<File>() { @Override public File call() throws Exception { return file; } }, FileMatchers.anExistingFile()); Assert.assertTrue(file.getAbsolutePath().startsWith(newLogBase)); deleteLogDir(new File(LogBase.getLogBaseDir())); }
Example #4
Source File: MetricWriter.java From Sentinel with Apache License 2.0 | 6 votes |
/** * Form metric file name use the specific appName and pid. Note that only * form the file name, not include path. * * Note: {@link MetricFileNameComparator}'s implementation relays on the metric file name, * we should be careful when changing the metric file name. * * @param appName * @param pid * @return metric file name. */ public static String formMetricFileName(String appName, int pid) { if (appName == null) { appName = ""; } // dot is special char that should be replaced. final String dot = "."; final String separator = "-"; if (appName.contains(dot)) { appName = appName.replace(dot, separator); } String name = appName + separator + METRIC_FILE; if (LogBase.isLogNameUsePid()) { name += ".pid" + pid; } return name; }
Example #5
Source File: ConfigPropertyHelper.java From Sentinel-Dashboard-Nacos with Apache License 2.0 | 6 votes |
public static void runWithConfig(Properties prop, String appName, Task task) throws Exception { if (prop == null || appName == null || "".equals(appName)) { throw new IllegalArgumentException("Prop and appName cannot be empty"); } // Set application name property. setAppNameProperty(appName); // Save the config. String path = LogBase.getLogBaseDir() + appName + ".properties"; File file = new File(path); if (!file.exists()) { file.createNewFile(); } OutputStream outputStream = new FileOutputStream(file); prop.store(outputStream,""); outputStream.close(); // Run the procedure. task.run(); // Clean-up. file.delete(); // Clear application name property. clearAppNameProperty(); }
Example #6
Source File: MetricWriter.java From Sentinel-Dashboard-Nacos with Apache License 2.0 | 6 votes |
/** * Form metric file name use the specific appName and pid. Note that only * form the file name, not include path. * * Note: {@link MetricFileNameComparator}'s implementation relays on the metric file name, * we should be careful when changing the metric file name. * * @param appName * @param pid * @return metric file name. */ public static String formMetricFileName(String appName, int pid) { if (appName == null) { appName = ""; } // dot is special char that should be replaced. final String dot = "."; final String separator = "-"; if (appName.contains(dot)) { appName = appName.replace(dot, separator); } String name = appName + separator + METRIC_FILE; if (LogBase.isLogNameUsePid()) { name += ".pid" + pid; } return name; }
Example #7
Source File: RecordLogTest.java From Sentinel-Dashboard-Nacos with Apache License 2.0 | 5 votes |
public void testLogNameNotUsePid() { String userHome = System.getProperty("user.home"); String newLogBase = userHome + File.separator + "tmpLogDir" + System.currentTimeMillis(); System.setProperty(LogBase.LOG_DIR, newLogBase); RecordLog.info("testLogNameNotUsePid"); File[] files = new File(newLogBase).listFiles(); assertTrue(files != null && files.length > 0); for (File f : files) { assertTrue(!f.getName().contains("pid" + PidUtil.getPid())); } }
Example #8
Source File: RecordLogTest.java From Sentinel-Dashboard-Nacos with Apache License 2.0 | 5 votes |
public void testLogNameUsePid() { String userHome = System.getProperty("user.home"); String newLogBase = userHome + File.separator + "tmpLogDir" + System.currentTimeMillis(); System.setProperty(LogBase.LOG_DIR, newLogBase); System.setProperty(LogBase.LOG_NAME_USE_PID, "true"); RecordLog.info("testLogNameUsePid"); File[] files = new File(newLogBase).listFiles(); assertTrue(files != null && files.length > 0); for (File f : files) { assertTrue(f.getName().contains("pid" + PidUtil.getPid())); } }
Example #9
Source File: RecordLogTest.java From Sentinel-Dashboard-Nacos with Apache License 2.0 | 5 votes |
@Test public void testChangeLogBase() { String userHome = System.getProperty("user.home"); String newLogBase = userHome + File.separator + "tmpLogDir" + System.currentTimeMillis(); System.setProperty(LogBase.LOG_DIR, newLogBase); RecordLog.info("testChangeLogBase"); String logFileName = RecordLog.getLogBaseDir(); File[] files = new File(logFileName).listFiles(); assertTrue(files != null && files.length > 0); }
Example #10
Source File: EagleEyeLogUtilTest.java From Sentinel with Apache License 2.0 | 5 votes |
@Test public void testWriteLog() throws Exception { EagleEyeLogUtil.log("resourceName", "BlockException", "app1", "origin", 1); final File file = new File(LogBase.getLogBaseDir() + EagleEyeLogUtil.FILE_NAME); await().timeout(2, TimeUnit.SECONDS) .until(new Callable<File>() { @Override public File call() throws Exception { return file; } }, FileMatchers.anExistingFile()); }
Example #11
Source File: RecordLogTest.java From Sentinel with Apache License 2.0 | 5 votes |
public void testChangeLogBase() { String userHome = System.getProperty("user.home"); String newLogBase = userHome + File.separator + "tmpLogDir" + System.currentTimeMillis(); System.setProperty(LogBase.LOG_DIR, newLogBase); RecordLog.info("testChangeLogBase"); String logFileName = LogBase.getLogBaseDir(); Assert.assertTrue(newLogBase.equals(logFileName)); File[] files = new File(logFileName).listFiles(); assertTrue(files != null && files.length > 0); deleteLogDir(new File(newLogBase)); }
Example #12
Source File: RecordLogTest.java From Sentinel with Apache License 2.0 | 5 votes |
public void testLogNameNotUsePid() { String userHome = System.getProperty("user.home"); String newLogBase = userHome + File.separator + "tmpLogDir" + System.currentTimeMillis(); System.setProperty(LogBase.LOG_DIR, newLogBase); RecordLog.info("testLogNameNotUsePid"); File[] files = new File(newLogBase).listFiles(); assertTrue(files != null && files.length > 0); for (File f : files) { assertTrue(!f.getName().contains("pid" + PidUtil.getPid())); } }
Example #13
Source File: RecordLogTest.java From Sentinel with Apache License 2.0 | 5 votes |
public void testLogNameUsePid() { String userHome = System.getProperty("user.home"); String newLogBase = userHome + File.separator + "tmpLogDir" + System.currentTimeMillis(); System.setProperty(LogBase.LOG_DIR, newLogBase); System.setProperty(LogBase.LOG_NAME_USE_PID, "true"); RecordLog.info("testLogNameUsePid"); File[] files = new File(newLogBase).listFiles(); assertTrue(files != null && files.length > 0); for (File f : files) { assertTrue(f.getName().contains("pid" + PidUtil.getPid())); } }
Example #14
Source File: SentinelEndpoint.java From spring-cloud-alibaba with Apache License 2.0 | 5 votes |
@ReadOperation public Map<String, Object> invoke() { final Map<String, Object> result = new HashMap<>(); if (sentinelProperties.isEnabled()) { result.put("appName", AppNameUtil.getAppName()); result.put("logDir", LogBase.getLogBaseDir()); result.put("logUsePid", LogBase.isLogNameUsePid()); result.put("blockPage", SentinelConfig.getConfig(BLOCK_PAGE_URL_CONF_KEY)); result.put("metricsFileSize", SentinelConfig.singleMetricFileSize()); result.put("metricsFileCharset", SentinelConfig.charset()); result.put("totalMetricsFileCount", SentinelConfig.totalMetricFileCount()); result.put("consoleServer", TransportConfig.getConsoleServerList()); result.put("clientIp", TransportConfig.getHeartbeatClientIp()); result.put("heartbeatIntervalMs", TransportConfig.getHeartbeatIntervalMs()); result.put("clientPort", TransportConfig.getPort()); result.put("coldFactor", sentinelProperties.getFlow().getColdFactor()); result.put("filter", sentinelProperties.getFilter()); result.put("datasource", sentinelProperties.getDatasource()); final Map<String, Object> rules = new HashMap<>(); result.put("rules", rules); rules.put("flowRules", FlowRuleManager.getRules()); rules.put("degradeRules", DegradeRuleManager.getRules()); rules.put("systemRules", SystemRuleManager.getRules()); rules.put("authorityRule", AuthorityRuleManager.getRules()); rules.put("paramFlowRule", ParamFlowRuleManager.getRules()); } return result; }
Example #15
Source File: SentinelAutoConfigurationTests.java From spring-cloud-alibaba with Apache License 2.0 | 5 votes |
@Test public void testSentinelSystemProperties() { assertThat(LogBase.isLogNameUsePid()).isEqualTo(true); assertThat(TransportConfig.getConsoleServerList().toString()).isEqualTo( Arrays.asList(Tuple2.of("localhost", 8080), Tuple2.of("localhost", 8081)) .toString()); assertThat(TransportConfig.getPort()).isEqualTo("9999"); assertThat(TransportConfig.getHeartbeatIntervalMs().longValue()) .isEqualTo(20000L); assertThat(TransportConfig.getHeartbeatClientIp()).isEqualTo("1.1.1.1"); assertThat(SentinelConfig.singleMetricFileSize()).isEqualTo(9999); assertThat(SentinelConfig.totalMetricFileCount()).isEqualTo(100); assertThat(SentinelConfig.charset()).isEqualTo("UTF-8"); assertThat(SentinelConfig.getConfig(BLOCK_PAGE_URL_CONF_KEY)).isEqualTo("/error"); }
Example #16
Source File: RecordLogTest.java From Sentinel with Apache License 2.0 | 4 votes |
@Test public void testLogBaseDir() { assertTrue(LogBase.getLogBaseDir().startsWith(System.getProperty("user.home"))); }
Example #17
Source File: SentinelAutoConfiguration.java From spring-cloud-alibaba with Apache License 2.0 | 4 votes |
@PostConstruct private void init() { if (StringUtils.isEmpty(System.getProperty(LogBase.LOG_DIR)) && StringUtils.hasText(properties.getLog().getDir())) { System.setProperty(LogBase.LOG_DIR, properties.getLog().getDir()); } if (StringUtils.isEmpty(System.getProperty(LogBase.LOG_NAME_USE_PID)) && properties.getLog().isSwitchPid()) { System.setProperty(LogBase.LOG_NAME_USE_PID, String.valueOf(properties.getLog().isSwitchPid())); } if (StringUtils.isEmpty(System.getProperty(AppNameUtil.APP_NAME)) && StringUtils.hasText(projectName)) { System.setProperty(AppNameUtil.APP_NAME, projectName); } if (StringUtils.isEmpty(System.getProperty(TransportConfig.SERVER_PORT)) && StringUtils.hasText(properties.getTransport().getPort())) { System.setProperty(TransportConfig.SERVER_PORT, properties.getTransport().getPort()); } if (StringUtils.isEmpty(System.getProperty(TransportConfig.CONSOLE_SERVER)) && StringUtils.hasText(properties.getTransport().getDashboard())) { System.setProperty(TransportConfig.CONSOLE_SERVER, properties.getTransport().getDashboard()); } if (StringUtils.isEmpty(System.getProperty(TransportConfig.HEARTBEAT_INTERVAL_MS)) && StringUtils .hasText(properties.getTransport().getHeartbeatIntervalMs())) { System.setProperty(TransportConfig.HEARTBEAT_INTERVAL_MS, properties.getTransport().getHeartbeatIntervalMs()); } if (StringUtils.isEmpty(System.getProperty(TransportConfig.HEARTBEAT_CLIENT_IP)) && StringUtils.hasText(properties.getTransport().getClientIp())) { System.setProperty(TransportConfig.HEARTBEAT_CLIENT_IP, properties.getTransport().getClientIp()); } if (StringUtils.isEmpty(System.getProperty(SentinelConfig.CHARSET)) && StringUtils.hasText(properties.getMetric().getCharset())) { System.setProperty(SentinelConfig.CHARSET, properties.getMetric().getCharset()); } if (StringUtils .isEmpty(System.getProperty(SentinelConfig.SINGLE_METRIC_FILE_SIZE)) && StringUtils.hasText(properties.getMetric().getFileSingleSize())) { System.setProperty(SentinelConfig.SINGLE_METRIC_FILE_SIZE, properties.getMetric().getFileSingleSize()); } if (StringUtils .isEmpty(System.getProperty(SentinelConfig.TOTAL_METRIC_FILE_COUNT)) && StringUtils.hasText(properties.getMetric().getFileTotalCount())) { System.setProperty(SentinelConfig.TOTAL_METRIC_FILE_COUNT, properties.getMetric().getFileTotalCount()); } if (StringUtils.isEmpty(System.getProperty(SentinelConfig.COLD_FACTOR)) && StringUtils.hasText(properties.getFlow().getColdFactor())) { System.setProperty(SentinelConfig.COLD_FACTOR, properties.getFlow().getColdFactor()); } if (StringUtils.hasText(properties.getBlockPage())) { setConfig(BLOCK_PAGE_URL_CONF_KEY, properties.getBlockPage()); } // earlier initialize if (properties.isEager()) { InitExecutor.doInit(); } }