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
4ca34a66
authored
Jun 18, 2017
by
amir
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
version 2.0.6 add get/set logging level from web
parent
ed59b412
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
96 additions
and
6 deletions
build.gradle
src/main/java/microservice/handlers/MonitorHandler.java
src/main/java/microservice/io/iface/ILogger.java
src/main/java/microservice/io/impl/ILogger4jImpl.java
src/main/java/microservice/io/impl/ILoggerConsoleImpl.java
build.gradle
View file @
4ca34a66
group
'com.ipgallery.common'
group
'com.ipgallery.common'
version
'2.0.
5
-services'
version
'2.0.
6
-services'
apply
plugin:
'java'
apply
plugin:
'java'
apply
plugin:
'maven-publish'
apply
plugin:
'maven-publish'
...
...
src/main/java/microservice/handlers/MonitorHandler.java
View file @
4ca34a66
...
@@ -16,6 +16,7 @@ import com.fasterxml.jackson.databind.node.JsonNodeFactory;
...
@@ -16,6 +16,7 @@ import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import
com.fasterxml.jackson.databind.node.ObjectNode
;
import
com.fasterxml.jackson.databind.node.ObjectNode
;
import
microservice.MicroserviceApp
;
import
microservice.MicroserviceApp
;
import
microservice.defs.Enums
;
import
microservice.defs.Enums
;
import
microservice.io.iface.ILogger
;
import
microservice.services.CommonServices
;
import
microservice.services.CommonServices
;
import
microservice.io.iface.IConfiguration
;
import
microservice.io.iface.IConfiguration
;
import
microservice.io.impl.IMetricsFactoryImpl
;
import
microservice.io.impl.IMetricsFactoryImpl
;
...
@@ -32,7 +33,9 @@ public class MonitorHandler implements CommonServices.IMethodClass
...
@@ -32,7 +33,9 @@ public class MonitorHandler implements CommonServices.IMethodClass
public
static
final
String
MON_PREFIX
=
"_mon"
;
public
static
final
String
MON_PREFIX
=
"_mon"
;
private
static
final
String
RELOAD
=
"_reload"
;
private
static
final
String
RELOAD
=
"_reload"
;
public
static
final
String
STAT
=
"_stat"
;
public
static
final
String
STAT
=
"_stat"
;
public
static
final
String
LOG_LEVEL
=
"_logLevel"
;
public
static
final
String
FIELD_NAME
=
"name"
;
public
static
final
String
FIELD_NAME
=
"name"
;
public
static
final
String
LEVEL
=
"Level"
;
List
<
BaseHandler
>
containers
=
null
;
List
<
BaseHandler
>
containers
=
null
;
protected
ObjectMapper
objMapper
=
new
ObjectMapper
();
protected
ObjectMapper
objMapper
=
new
ObjectMapper
();
...
@@ -184,5 +187,37 @@ public class MonitorHandler implements CommonServices.IMethodClass
...
@@ -184,5 +187,37 @@ public class MonitorHandler implements CommonServices.IMethodClass
(
msgCtx
,
orgService
)
->
{
(
msgCtx
,
orgService
)
->
{
printStats
((
RestContext
)
msgCtx
);
printStats
((
RestContext
)
msgCtx
);
}));
}));
methodParamsList
.
add
(
new
CommonServices
.
MethodParams
(
Enums
.
EnumServiceType
.
E_REST
,
CommonServices
.
EnumRestCommands
.
E_READ
,
"/"
+
MON_PREFIX
+
"/"
+
LOG_LEVEL
,
(
msgCtx
,
orgService
)
->
{
printLogLevel
((
RestContext
)
msgCtx
);
}));
methodParamsList
.
add
(
new
CommonServices
.
MethodParams
(
Enums
.
EnumServiceType
.
E_REST
,
CommonServices
.
EnumRestCommands
.
E_CREATE
,
"/"
+
MON_PREFIX
+
"/"
+
LOG_LEVEL
,
(
msgCtx
,
orgService
)
->
{
setLogLevel
((
RestContext
)
msgCtx
);
}));
}
}
private
void
setLogLevel
(
RestContext
reqCtx
)
{
final
JsonNode
jsonNode
=
(
JsonNode
)
reqCtx
.
container
.
readObjectFromRequest
(
reqCtx
.
request
,
JsonNode
.
class
);
if
(
jsonNode
!=
null
){
String
levelStr
=
jsonNode
.
path
(
LEVEL
).
asText
();
MicroserviceApp
.
getsInstance
().
getLogger
().
setLogLevel
(
ILogger
.
EnumLevel
.
getLevel
(
levelStr
));
}
printLogLevel
(
reqCtx
);
}
private
void
printLogLevel
(
RestContext
reqCtx
)
{
BaseRestResponse
brr
=
new
BaseRestResponse
(
true
,
null
);
final
ILogger
logger
=
MicroserviceApp
.
getsInstance
().
getLogger
();
if
(
logger
.
getLogLevel
()
!=
null
)
brr
.
objectNode
=
JsonNodeFactory
.
instance
.
objectNode
().
put
(
LEVEL
,
logger
.
getLogLevel
().
getLevelStr
());
reqCtx
.
container
.
writeObjectToResponse
(
reqCtx
.
response
,
brr
);
}
}
}
src/main/java/microservice/io/iface/ILogger.java
View file @
4ca34a66
package
microservice
.
io
.
iface
;
package
microservice
.
io
.
iface
;
import
java.util.Optional
;
import
java.util.stream.Stream
;
/**
/**
* logger interface to use in the MS
* logger interface to use in the MS
* @author amir
* @author amir
...
@@ -7,10 +10,40 @@ package microservice.io.iface;
...
@@ -7,10 +10,40 @@ package microservice.io.iface;
*/
*/
public
interface
ILogger
public
interface
ILogger
{
{
enum
EnumLevel
{
E_FATAL
(
"fatal"
),
E_ERROR
(
"error"
),
E_WARNING
(
"warning"
),
E_INFO
(
"info"
),
E_DEBUG
(
"debug"
),
E_TRACE
(
"trace"
);
String
levelStr
;
EnumLevel
(
String
levelStr
)
{
this
.
levelStr
=
levelStr
;
}
public
String
getLevelStr
()
{
return
levelStr
;
}
public
static
EnumLevel
getLevel
(
String
levelStr
){
for
(
EnumLevel
enumLevel
:
EnumLevel
.
values
()){
if
(
enumLevel
.
getLevelStr
().
equals
(
levelStr
))
return
enumLevel
;
}
return
null
;
}
}
public
void
fatal
(
String
msg
);
public
void
fatal
(
String
msg
);
public
void
error
(
String
msg
);
public
void
error
(
String
msg
);
public
void
warning
(
String
msg
);
public
void
warning
(
String
msg
);
public
void
info
(
String
msg
);
public
void
info
(
String
msg
);
public
void
debug
(
String
msg
);
public
void
debug
(
String
msg
);
public
void
trace
(
String
msg
);
public
void
trace
(
String
msg
);
public
EnumLevel
getLogLevel
();
public
void
setLogLevel
(
EnumLevel
level
);
}
}
src/main/java/microservice/io/impl/ILogger4jImpl.java
View file @
4ca34a66
...
@@ -61,4 +61,14 @@ public class ILogger4jImpl implements ILogger
...
@@ -61,4 +61,14 @@ public class ILogger4jImpl implements ILogger
}
}
@Override
public
EnumLevel
getLogLevel
()
{
return
null
;
}
@Override
public
void
setLogLevel
(
EnumLevel
level
)
{
}
}
}
src/main/java/microservice/io/impl/ILoggerConsoleImpl.java
View file @
4ca34a66
...
@@ -19,6 +19,7 @@ public class ILoggerConsoleImpl implements ILogger {
...
@@ -19,6 +19,7 @@ public class ILoggerConsoleImpl implements ILogger {
String
name
;
String
name
;
String
prefix
;
String
prefix
;
EnumLevel
level
=
EnumLevel
.
E_INFO
;
// default level
public
ILoggerConsoleImpl
(
String
name
)
{
public
ILoggerConsoleImpl
(
String
name
)
{
this
.
name
=
name
;
this
.
name
=
name
;
...
@@ -32,26 +33,37 @@ public class ILoggerConsoleImpl implements ILogger {
...
@@ -32,26 +33,37 @@ public class ILoggerConsoleImpl implements ILogger {
@Override
@Override
public
void
error
(
String
msg
)
{
public
void
error
(
String
msg
)
{
System
.
out
.
println
(
ANSI_RED
+
prefix
+
msg
+
ANSI_RESET
);
if
(
level
.
ordinal
()
>=
EnumLevel
.
E_ERROR
.
ordinal
())
System
.
out
.
println
(
ANSI_RED
+
prefix
+
msg
+
ANSI_RESET
);
}
}
@Override
@Override
public
void
warning
(
String
msg
)
{
public
void
warning
(
String
msg
)
{
System
.
out
.
println
(
ANSI_YELLOW
+
prefix
+
msg
+
ANSI_RESET
);
if
(
level
.
ordinal
()
>=
EnumLevel
.
E_WARNING
.
ordinal
())
System
.
out
.
println
(
ANSI_YELLOW
+
prefix
+
msg
+
ANSI_RESET
);
}
}
@Override
@Override
public
void
info
(
String
msg
)
{
public
void
info
(
String
msg
)
{
System
.
out
.
println
(
ANSI_BLUE
+
prefix
+
msg
+
ANSI_RESET
);
if
(
level
.
ordinal
()
>=
EnumLevel
.
E_INFO
.
ordinal
())
System
.
out
.
println
(
ANSI_BLUE
+
prefix
+
msg
+
ANSI_RESET
);
}
}
@Override
@Override
public
void
debug
(
String
msg
)
{
public
void
debug
(
String
msg
)
{
System
.
out
.
println
(
ANSI_WHITE
+
prefix
+
msg
+
ANSI_RESET
);
if
(
level
.
ordinal
()
>=
EnumLevel
.
E_DEBUG
.
ordinal
())
System
.
out
.
println
(
ANSI_WHITE
+
prefix
+
msg
+
ANSI_RESET
);
}
}
@Override
@Override
public
void
trace
(
String
msg
)
{
public
void
trace
(
String
msg
)
{
System
.
out
.
println
(
ANSI_GREEN
+
prefix
+
msg
+
ANSI_RESET
);
if
(
level
.
ordinal
()
>=
EnumLevel
.
E_TRACE
.
ordinal
())
System
.
out
.
println
(
ANSI_GREEN
+
prefix
+
msg
+
ANSI_RESET
);
}
@Override
public
EnumLevel
getLogLevel
()
{
return
level
;
}
@Override
public
void
setLogLevel
(
EnumLevel
level
)
{
if
(
level
!=
null
)
this
.
level
=
level
;
}
}
}
}
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