Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
ipgallery.common.java
/
microservice
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Registry
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
1c5c41df
authored
Sep 11, 2019
by
Amir Aharon
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
2.1.3 add date time to ILoggerConsoleImpl
parent
4eb0f339
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
64 additions
and
8 deletions
.gitignore
README.md
build.gradle
src/main/java/microservice/io/impl/ILoggerConsoleImpl.java
src/test/java/microservice/TestLogger.java
.gitignore
View file @
1c5c41df
...
@@ -7,3 +7,4 @@
...
@@ -7,3 +7,4 @@
.project
.project
.classpath
.classpath
gradle/
gradle/
out/
\ No newline at end of file
README.md
View file @
1c5c41df
### Microservice Framework in JAVA
### Microservice Framework in JAVA
## 2.1.3
-
add date time to ILoggerConsoleImpl
## 2.1.2
-
add config to okhttp client read/connect timeouts
"microservice.http.client.read.timeout.seconds" (30)
"microservice.http.client.connect.timeout.seconds" (10)
## 2.1.1
## 2.1.1
-
downgrade metrics influxdb to fit the reporter on iot jar
-
downgrade metrics influxdb to fit the reporter on iot jar
...
...
build.gradle
View file @
1c5c41df
group
'com.ipgallery.common'
group
'com.ipgallery.common'
version
'2.1.
2
'
version
'2.1.
3
'
apply
plugin:
'java'
apply
plugin:
'java'
apply
plugin:
'maven-publish'
apply
plugin:
'maven-publish'
...
...
src/main/java/microservice/io/impl/ILoggerConsoleImpl.java
View file @
1c5c41df
...
@@ -2,6 +2,8 @@ package microservice.io.impl;
...
@@ -2,6 +2,8 @@ package microservice.io.impl;
import
microservice.io.iface.ILogger
;
import
microservice.io.iface.ILogger
;
import
java.time.LocalDateTime
;
/**
/**
* Created by amir on 03/05/17.
* Created by amir on 03/05/17.
*/
*/
...
@@ -16,6 +18,7 @@ public class ILoggerConsoleImpl implements ILogger {
...
@@ -16,6 +18,7 @@ public class ILoggerConsoleImpl implements ILogger {
public
static
final
String
ANSI_PURPLE
=
"\u001B[35m"
;
public
static
final
String
ANSI_PURPLE
=
"\u001B[35m"
;
public
static
final
String
ANSI_CYAN
=
"\u001B[36m"
;
public
static
final
String
ANSI_CYAN
=
"\u001B[36m"
;
public
static
final
String
ANSI_WHITE
=
"\u001B[37m"
;
public
static
final
String
ANSI_WHITE
=
"\u001B[37m"
;
public
static
final
int
INITIAL_LOG_LENGTH
=
128
;
String
name
;
String
name
;
String
prefix
;
String
prefix
;
...
@@ -23,37 +26,47 @@ public class ILoggerConsoleImpl implements ILogger {
...
@@ -23,37 +26,47 @@ public class ILoggerConsoleImpl implements ILogger {
public
ILoggerConsoleImpl
(
String
name
)
{
public
ILoggerConsoleImpl
(
String
name
)
{
this
.
name
=
name
;
this
.
name
=
name
;
this
.
prefix
=
"["
+
name
+
"]: "
;
this
.
prefix
=
" ["
+
name
+
"]: "
;
}
String
getDateTimeString
(){
return
LocalDateTime
.
now
().
toString
();
}
}
@Override
@Override
public
void
fatal
(
String
msg
)
{
public
void
fatal
(
String
msg
)
{
System
.
out
.
println
(
ANSI_RED
+
prefix
+
msg
+
ANSI_RESET
);
System
.
out
.
println
(
formatLogMsg
(
ANSI_RED
,
msg
));
}
private
String
formatLogMsg
(
String
color
,
String
msg
)
{
StringBuilder
sb
=
new
StringBuilder
(
INITIAL_LOG_LENGTH
);
sb
.
append
(
color
).
append
(
getDateTimeString
()).
append
(
prefix
).
append
(
msg
).
append
(
ANSI_RESET
);
return
sb
.
toString
();
}
}
@Override
@Override
public
void
error
(
String
msg
)
{
public
void
error
(
String
msg
)
{
if
(
level
.
ordinal
()
>=
EnumLevel
.
E_ERROR
.
ordinal
())
System
.
out
.
println
(
ANSI_RED
+
prefix
+
msg
+
ANSI_RESET
);
if
(
level
.
ordinal
()
>=
EnumLevel
.
E_ERROR
.
ordinal
())
System
.
out
.
println
(
formatLogMsg
(
ANSI_RED
,
msg
)
);
}
}
@Override
@Override
public
void
warning
(
String
msg
)
{
public
void
warning
(
String
msg
)
{
if
(
level
.
ordinal
()
>=
EnumLevel
.
E_WARNING
.
ordinal
())
System
.
out
.
println
(
ANSI_YELLOW
+
prefix
+
msg
+
ANSI_RESET
);
if
(
level
.
ordinal
()
>=
EnumLevel
.
E_WARNING
.
ordinal
())
System
.
out
.
println
(
formatLogMsg
(
ANSI_YELLOW
,
msg
)
);
}
}
@Override
@Override
public
void
info
(
String
msg
)
{
public
void
info
(
String
msg
)
{
if
(
level
.
ordinal
()
>=
EnumLevel
.
E_INFO
.
ordinal
())
System
.
out
.
println
(
ANSI_BLUE
+
prefix
+
msg
+
ANSI_RESET
);
if
(
level
.
ordinal
()
>=
EnumLevel
.
E_INFO
.
ordinal
())
System
.
out
.
println
(
formatLogMsg
(
ANSI_BLUE
,
msg
)
);
}
}
@Override
@Override
public
void
debug
(
String
msg
)
{
public
void
debug
(
String
msg
)
{
if
(
level
.
ordinal
()
>=
EnumLevel
.
E_DEBUG
.
ordinal
())
System
.
out
.
println
(
ANSI_WHITE
+
prefix
+
msg
+
ANSI_RESET
);
if
(
level
.
ordinal
()
>=
EnumLevel
.
E_DEBUG
.
ordinal
())
System
.
out
.
println
(
formatLogMsg
(
ANSI_WHITE
,
msg
)
);
}
}
@Override
@Override
public
void
trace
(
String
msg
)
{
public
void
trace
(
String
msg
)
{
if
(
level
.
ordinal
()
>=
EnumLevel
.
E_TRACE
.
ordinal
())
System
.
out
.
println
(
ANSI_GREEN
+
prefix
+
msg
+
ANSI_RESET
);
if
(
level
.
ordinal
()
>=
EnumLevel
.
E_TRACE
.
ordinal
())
System
.
out
.
println
(
formatLogMsg
(
ANSI_GREEN
,
msg
)
);
}
}
@Override
@Override
...
...
src/test/java/microservice/TestLogger.java
0 → 100644
View file @
1c5c41df
package
microservice
;
import
microservice.io.iface.ILogger
;
import
microservice.io.impl.ILoggerConsoleImpl
;
import
org.junit.Test
;
import
java.time.LocalDateTime
;
public
class
TestLogger
{
public
static
final
int
ITERATIONS
=
1000000
;
@Test
public
void
testLocalDateTime
(){
final
long
startTime
=
System
.
currentTimeMillis
();
for
(
int
i
=
0
;
i
<
ITERATIONS
;
i
++){
final
String
localDateTime
=
LocalDateTime
.
now
().
toString
();
}
System
.
out
.
println
(
String
.
format
(
"Test of %d Took: %d ms"
,
ITERATIONS
,
System
.
currentTimeMillis
()
-
startTime
));
}
@Test
public
void
testLogger
(){
ILoggerConsoleImpl
logger
=
new
ILoggerConsoleImpl
(
"test"
);
logger
.
setLogLevel
(
ILogger
.
EnumLevel
.
E_TRACE
);
logger
.
fatal
(
"test fatal msg"
);
logger
.
error
(
"test error msg"
);
logger
.
warning
(
"test warning msg"
);
logger
.
info
(
"test info msg"
);
logger
.
debug
(
"test debug msg"
);
logger
.
trace
(
"test trace msg"
);
logger
.
fatal
(
"test fatal msg"
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment