Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance logging subsystem with flexible customization #598

Merged
merged 1 commit into from
Oct 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/caliper-core/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ zookeeper.out
.idea/
**/node_modules/
**/log/
*.log

# Ignore any composer logs
composer-logs/
Expand Down
39 changes: 38 additions & 1 deletion packages/caliper-core/lib/config/Config.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,44 @@ const keys = {
ZooAddress: 'caliper-zooaddress',
ZooConfig: 'caliper-zooconfig',
TxUpdateTime: 'caliper-txupdatetime',
Logging: 'caliper-logging',
LoggingRoot: 'caliper-logging',
Logging: {
Template: 'caliper-logging-template',
FormatsRoot: 'caliper-logging-formats',
Formats: {
Align: 'caliper-logging-formats-align',
Pad: 'caliper-logging-formats-pad',
ColorizeRoot: 'caliper-logging-formats-colorize',
Colorize: {
Level: 'caliper-logging-formats-colorize-level',
Message: 'caliper-logging-formats-colorize-message',
Colors: {
Info: 'caliper-logging-formats-colorize-colors-info',
Error: 'caliper-logging-formats-colorize-colors-error',
Warn: 'caliper-logging-formats-colorize-colors-warn',
Debug: 'caliper-logging-formats-colorize-colors-debug',
}
},
ErrorsRoot: 'caliper-logging-formats-errors',
Errors: {
Stack: 'caliper-logging-formats-errors-stack'
},
JsonRoot: 'caliper-logging-formats-json',
Json: {
Space: 'caliper-logging-formats-json-space'
},
LabelRoot: 'caliper-logging-formats-label',
Label: {
Label: 'caliper-logging-formats-label-label',
Message: 'caliper-logging-formats-label-message'
},
TimestampRoot: 'caliper-logging-formats-timestamp',
Timestamp: {
Format: 'caliper-logging-formats-timestamp-format'
}
},
Targets: 'caliper-logging-targets'
},
Flow: {
Skip: {
Start : 'caliper-flow-skip-start',
Expand Down
2 changes: 1 addition & 1 deletion packages/caliper-core/lib/config/config-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function set(name, value) {
* @param {any} defaultValue The value to return in case the key is not found.
* @return {any} The value of the configuration or the defaultValue parameter if not found.
*/
function get(name, defaultValue) {
function get(name, defaultValue = undefined) {
return _getConfigInstance().get(name, defaultValue);
}

Expand Down
65 changes: 53 additions & 12 deletions packages/caliper-core/lib/config/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,59 @@ caliper:
txupdatetime: 1000
# Configurations related to the logging mechanism
logging:
# Defines a console target with info level
consolelogger:
target: console
level: info
# Defines a daily rotating file target with debug level
filelogger:
target: daily-rotate-file
level: debug
filename: log/caliper-%DATE%.log
datePattern: YYYY-MM-DD-HH
maxSize: 5m
zippedArchive: true
# Specifies the message structure through placeholders
template: '%time% %level% [%label%] [%module%] %message% %meta%'
# Enables the different formats to apply to the log messages FOR ALL transports
# Each format can be disabled by setting it to false
formats:
# adds a tab delimiter before the message to align it in the same place
align: true
# pads the levels to be the same length
pad: true
# defines coloring for the different levels
colorize:
# Apply it to levels
level: true
# Apply it to messages
message: false
# The colors for each level
colors:
info: green
error: red
warn: yellow
debug: grey
# specifies whether to print stack traces
errors:
stack: true
# serializes the log messages as JSON
json: false
# Adds a specified label to every message. Useful for distributed client scenario
label:
label: caliper
message: false
# Adds a timestamp to the messages
timestamp:
# The timestamp format string
format: YYYY.MM.DD-HH:mm:ss.SSS
# Lists the targets (winston transports)
targets:
console:
target: console # Defines a console target
enabled: true # Enables the target
options: # These are passed to the winston console target as-is
level: info
# Defines a target with debug level
file:
target: file
enabled: true
options:
level: debug
filename: caliper.log
maxSize: 5m
zippedArchive: false
options:
flags: a
mode: 0666

# Caliper flow options
flow:
Expand Down
7 changes: 3 additions & 4 deletions packages/caliper-core/lib/utils/caliper-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,12 @@ class CaliperUtils {
/**
* Returns a logger configured with the given module name.
* @param {string} name The name of module who will use the logger.
* @param {winston.LoggerInstance} parentLogger Optional. The logger of the parent module. Defaults to the global Caliper logger.
* @returns {winston.LoggerInstance} The configured logger instance.
* @returns {Logger} The configured logger instance.
*/
static getLogger(name, parentLogger) {
static getLogger(name) {
// logger should be accessed through the Util class
// but delegates to logging-util.js
return loggingUtil.getLogger(name, parentLogger);
return loggingUtil.getLogger(name);
}

/**
Expand Down
Loading