Commit cbfc8f06 by amir

1.3.8 add colorful logging

parent d5c24201
### Microservice Framework in JAVA
### 1.4.2:
- update common.utils to 1.2.5
......@@ -8,6 +7,7 @@
### 1.4.0:
- update common.utils to 1.2.0
## 1.3.8: Add colorful logging
## 1.3.7: Add Pagination - PageBuilder
## 1.3.6: upgrade common-utils 1.2.0
## 1.3.2:
......
......@@ -13,10 +13,7 @@ import microservice.handlers.MBIHandler;
import microservice.handlers.MonitorHandler;
import microservice.handlers.RestHandler;
import microservice.io.iface.*;
import microservice.io.impl.IConfigurationConfigPropImpl;
import microservice.io.impl.ILogger4jImpl;
import microservice.io.impl.IMetricsFactoryImpl;
import microservice.io.impl.IPubSubMQTTImpl;
import microservice.io.impl.*;
import microservice.params.RMQClientParams;
import microservice.params.RestServerParams;
......@@ -212,7 +209,7 @@ public class MicroserviceApp
public MicroserviceApp build()
{
if (logger == null)
logger = new ILogger4jImpl(appName); // default logger
logger = new ILoggerConsoleImpl(appName); //new ILogger4jImpl(appName); // default logger
// some java 8 now...
optMonitorHandler.ifPresent(mon -> msMap.forEach((prfx,handler) -> { mon.addHandler(handler);}));
......@@ -372,7 +369,8 @@ public class MicroserviceApp
try
{
restServer.start();
System.out.println("rest server started successfully on host: " + rsiParams.getHost() + ", and port: " + String.valueOf(rsiParams.getPort()));
logger.info("rest server started successfully on host: " + rsiParams.getHost() + ", and port: " + String.valueOf(rsiParams.getPort()));
//System.out.println("rest server started successfully on host: " + rsiParams.getHost() + ", and port: " + String.valueOf(rsiParams.getPort()));
} catch (Exception e)
{
System.out.println(e.toString() + " ...exit restServer");
......
package microservice.io.impl;
import microservice.io.iface.ILogger;
/**
* Created by amir on 03/05/17.
*/
public class ILoggerConsoleImpl implements ILogger {
public static final String ANSI_RESET = "\u001B[0m";
public static final String ANSI_BLACK = "\u001B[30m";
public static final String ANSI_RED = "\u001B[31m";
public static final String ANSI_GREEN = "\u001B[32m";
public static final String ANSI_YELLOW = "\u001B[33m";
public static final String ANSI_BLUE = "\u001B[34m";
public static final String ANSI_PURPLE = "\u001B[35m";
public static final String ANSI_CYAN = "\u001B[36m";
public static final String ANSI_WHITE = "\u001B[37m";
String name;
String prefix;
public ILoggerConsoleImpl(String name) {
this.name = name;
this.prefix = "[" + name + "]: ";
}
@Override
public void fatal(String msg) {
System.out.println(ANSI_RED + prefix + msg + ANSI_RESET);
}
@Override
public void error(String msg) {
System.out.println(ANSI_RED + prefix + msg + ANSI_RESET);
}
@Override
public void warning(String msg) {
System.out.println(ANSI_YELLOW + prefix + msg + ANSI_RESET);
}
@Override
public void info(String msg) {
System.out.println(ANSI_BLUE + prefix + msg + ANSI_RESET);
}
@Override
public void debug(String msg) {
System.out.println(ANSI_WHITE + prefix + msg + ANSI_RESET);
}
@Override
public void trace(String msg) {
System.out.println(ANSI_GREEN + prefix + msg + ANSI_RESET);
}
}
......@@ -13,6 +13,7 @@ import java.util.Map.Entry;
import java.util.Set;
import common.Network;
import microservice.MicroserviceApp;
import microservice.handlers.BaseHandler;
import microservice.handlers.RestHandler;
import microservice.io.iface.IPubSub;
......@@ -94,7 +95,7 @@ public class IRestServerUndertowImpl implements IRestServer {
try
{
restServer.start();
System.out.println("rest server started successfully on host: " + rsiParams.getHost() + ", and port: " + String.valueOf(rsiParams.getPort()));
MicroserviceApp.getsInstance().getLogger().info("rest server started successfully on host: " + rsiParams.getHost() + ", and port: " + String.valueOf(rsiParams.getPort()));
} catch (Exception e)
{
System.out.println(e.toString() + " ...exit restServer");
......
......@@ -32,7 +32,7 @@ public class TestMicroserviceApp {
.withPubSub(new microservice.io.impl.IPubSubMQTTImpl("tcp://localhost",0,null,0))
//.withServiceDiscovery(serDisco)
.withMonitoring()
.addHandler("/test",new TestMicroserviceHandler())
//.addHandler("/test",new TestMicroserviceHandler())
.addMicroserviceClient(new MicroserviceClient(cmdClient,clientParams))
//.addMicroserviceClient("rabbit-service",new MicroserviceClient(EnumRestClientType.E_RABBITMQ,clientParams))
.addRestServer(new IRestServerUndertowImpl(new RestServerParams(32000, "localhost", 2)))
......@@ -57,7 +57,7 @@ public class TestMicroserviceApp {
.withPubSub(new microservice.io.impl.IPubSubMQTTImpl("tcp://localhost",0,null,0))
//.withServiceDiscovery(serDisco)
.withMonitoring()
.addHandler("/test",new TestMicroserviceHandler())
// .addHandler("/test",new TestMicroserviceHandler())
.addMicroserviceClient(new MicroserviceClient(cmdClient,clientParams))
//.addMicroserviceClient("rabbit-service",new MicroserviceClient(EnumRestClientType.E_RABBITMQ,clientParams))
.addRestServer(new IRestServerUndertowImpl(new RestServerParams(32000, "localhost", 2)))
......@@ -67,6 +67,21 @@ public class TestMicroserviceApp {
}
public static final String ANSI_RESET = "\u001B[0m";
public static final String ANSI_BLACK = "\u001B[30m";
public static final String ANSI_RED = "\u001B[31m";
public static final String ANSI_GREEN = "\u001B[32m";
public static final String ANSI_YELLOW = "\u001B[33m";
public static final String ANSI_BLUE = "\u001B[34m";
public static final String ANSI_PURPLE = "\u001B[35m";
public static final String ANSI_CYAN = "\u001B[36m";
public static final String ANSI_WHITE = "\u001B[37m";
@Test
public void testLogger()
{
System.out.println(ANSI_RED + "hello" + ANSI_RESET);
System.out.println(ANSI_BLUE + "hello" + ANSI_RESET);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment