mirror of
https://github.com/OpenNebula/one.git
synced 2025-01-10 01:17:40 +03:00
F OpenNebula/one#5422: Add option to truncate logs (#3039)
Signed-off-by: Victor Hansson <vhansson@opennebula.io> Co-authored-by: Tino Vázquez <cvazquez@opennebula.io>
This commit is contained in:
parent
bdaf6442f7
commit
b9d08e6c6c
@ -38,6 +38,11 @@ subscriber_endpoint: tcp://localhost:2101
|
||||
#
|
||||
debug_level: 2
|
||||
|
||||
# Maximum length of log messages (chars)
|
||||
# Messages exceeding this limit will be truncated
|
||||
# -1 => No limit
|
||||
truncate_max_length: 150
|
||||
|
||||
################################################################################
|
||||
# Global API Timeout
|
||||
################################################################################
|
||||
|
@ -45,16 +45,17 @@ const AutocompleteController = memo(
|
||||
|
||||
const selected = multiple
|
||||
? renderValue ?? []
|
||||
: values.find(({ value }) => value === renderValue) ?? null
|
||||
: values.find(({ value }) => value === renderValue) || renderValue
|
||||
|
||||
const handleChange = useCallback(
|
||||
(_, newValue) => {
|
||||
const newValueToChange = multiple
|
||||
? newValue?.map((value) =>
|
||||
// In case that is an object, get value attribute
|
||||
['string', 'number'].includes(typeof value) ? value : value.value
|
||||
typeof value === 'object' ? value.value : value
|
||||
)
|
||||
: newValue?.value
|
||||
: typeof newValue === 'object'
|
||||
? newValue.value
|
||||
: newValue
|
||||
|
||||
onChange(newValueToChange ?? '')
|
||||
if (typeof onConditionChange === 'function') {
|
||||
@ -70,24 +71,31 @@ const AutocompleteController = memo(
|
||||
color="secondary"
|
||||
onBlur={onBlur}
|
||||
onChange={handleChange}
|
||||
onInputChange={(_, newInputValue, reason) => {
|
||||
// Processes the input in freesolo mode
|
||||
if (
|
||||
reason === 'input' &&
|
||||
(fieldProps?.freeSolo || !optionsOnly) &&
|
||||
!multiple
|
||||
) {
|
||||
onChange(newInputValue)
|
||||
if (typeof onConditionChange === 'function') {
|
||||
onConditionChange(newInputValue)
|
||||
}
|
||||
}
|
||||
}}
|
||||
options={values}
|
||||
value={selected}
|
||||
multiple={multiple}
|
||||
freeSolo={!optionsOnly}
|
||||
renderTags={(tags, getTagProps) =>
|
||||
// render when freesolo prop
|
||||
tags.map((tag, index) => {
|
||||
// When the component is multiple and has values, map to show the label that corresponds to the value
|
||||
const labelTag =
|
||||
values &&
|
||||
values.length > 0 &&
|
||||
values.find((item) => item.value === tag)
|
||||
? values.find((item) => item.value === tag).text
|
||||
: tag
|
||||
values.find((item) => item.value === tag)?.text || tag
|
||||
|
||||
return (
|
||||
<Chip
|
||||
key={labelTag}
|
||||
key={index}
|
||||
size="small"
|
||||
variant="outlined"
|
||||
label={labelTag}
|
||||
@ -96,8 +104,12 @@ const AutocompleteController = memo(
|
||||
)
|
||||
})
|
||||
}
|
||||
getOptionLabel={(option) => option.text}
|
||||
isOptionEqualToValue={(option) => option.value === renderValue}
|
||||
getOptionLabel={(option) =>
|
||||
typeof option === 'object' ? option.text : option
|
||||
}
|
||||
isOptionEqualToValue={(option, value) =>
|
||||
typeof option === 'object' ? option.value === value : option === value
|
||||
}
|
||||
renderInput={({ inputProps, ...inputParams }) => (
|
||||
<TextField
|
||||
label={<Translate word={label} />}
|
||||
|
@ -61,13 +61,16 @@ const NAME = {
|
||||
name: 'name',
|
||||
label: T.Name,
|
||||
type: INPUT_TYPES.AUTOCOMPLETE,
|
||||
disableEnter: true,
|
||||
optionsOnly: false,
|
||||
multiple: false,
|
||||
values: () => useSelector((state) => state.persistent.userInputSuggestionsVR),
|
||||
validation: string()
|
||||
.trim()
|
||||
.required()
|
||||
.default(() => undefined),
|
||||
grid: { sm: 6, md: 4 },
|
||||
fieldProps: { freeSolo: true },
|
||||
}
|
||||
|
||||
/** @type {Field} Type field */
|
||||
|
@ -64,7 +64,7 @@ const appConfig = getFireedgeConfig()
|
||||
genFireedgeKey()
|
||||
|
||||
// set logger
|
||||
initLogger(appConfig.debug_level)
|
||||
initLogger(appConfig.debug_level, appConfig.truncate_max_length)
|
||||
|
||||
// destructure imports
|
||||
const unsecureServer = http.createServer
|
||||
|
@ -128,6 +128,7 @@ const defaults = {
|
||||
defaultProvisionPath: internalProvisionPath,
|
||||
defaultProvidersConfigPath: 'providers.d',
|
||||
defaultLogsLevels: ['error', 'warm', 'info', 'http', 'verbose', 'debug'],
|
||||
defaultLogMessageLength: 100,
|
||||
defaultTypeLog: 'prod',
|
||||
defaultWebpackMode: 'development',
|
||||
defaultProductionWebpackMode: 'production',
|
||||
|
@ -17,29 +17,51 @@
|
||||
const { env } = require('process')
|
||||
const { global } = require('window-or-global')
|
||||
const { transports, format, createLogger } = require('winston')
|
||||
const { printf } = format
|
||||
const { sprintf } = require('sprintf-js')
|
||||
const morgan = require('morgan')
|
||||
const _ = require('lodash')
|
||||
const { defaults } = require('server/utils/constants')
|
||||
const { defaultWebpackMode, defaultLogsLevels } = defaults
|
||||
const { defaultWebpackMode, defaultLogsLevels, defaultLogMessageLength } =
|
||||
defaults
|
||||
|
||||
let logger = null
|
||||
|
||||
const getTruncFormat = (truncateMaxLength) =>
|
||||
printf(({ timestamp, level, message }) => {
|
||||
const formattedMessage =
|
||||
truncateMaxLength === -1
|
||||
? message
|
||||
: _.truncate(message, { length: truncateMaxLength })
|
||||
|
||||
return `[${timestamp}] - [${level}] ${formattedMessage}`
|
||||
})
|
||||
|
||||
/**
|
||||
* Initialize logger.
|
||||
*
|
||||
* @param {number} logLevel - log level
|
||||
* @param {number} truncate_max_limit - max limit to truncate log messages
|
||||
*/
|
||||
const initLogger = (logLevel = 0) => {
|
||||
const initLogger = (
|
||||
logLevel = 0,
|
||||
truncate_max_limit = defaultLogMessageLength
|
||||
) => {
|
||||
if (global && global.paths && global.paths.FIREEDGE_LOG) {
|
||||
const levelString = parseInt(logLevel, 10)
|
||||
const logString = defaultLogsLevels && defaultLogsLevels[levelString]
|
||||
|
||||
const trans = []
|
||||
|
||||
const loggerFormat = format.combine(
|
||||
format.timestamp(),
|
||||
getTruncFormat(truncate_max_limit)
|
||||
)
|
||||
|
||||
if (env && env.NODE_ENV && env.NODE_ENV === defaultWebpackMode) {
|
||||
trans.push(
|
||||
new transports.Console({
|
||||
format: format.simple(),
|
||||
format: loggerFormat,
|
||||
})
|
||||
)
|
||||
} else {
|
||||
@ -49,7 +71,7 @@ const initLogger = (logLevel = 0) => {
|
||||
level: logString,
|
||||
filename: global.paths.FIREEDGE_LOG,
|
||||
handleExceptions: true,
|
||||
format: format.simple(),
|
||||
format: loggerFormat,
|
||||
maxsize: 5242880, // 5MB
|
||||
colorize: false,
|
||||
})
|
||||
@ -66,10 +88,11 @@ const initLogger = (logLevel = 0) => {
|
||||
writeInLogger(message)
|
||||
},
|
||||
}
|
||||
|
||||
if (env && env.NODE_ENV && env.NODE_ENV === defaultWebpackMode) {
|
||||
logger.clear().add(
|
||||
new transports.Console({
|
||||
format: format.simple(),
|
||||
format: loggerFormat,
|
||||
})
|
||||
)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user