import { get } from 'lodash' ; import { IScopedClusterClient } from 'src/core/server' ; import { DeprecationLoggingStatus } from '../../common/types' ; export async function getDeprecationLoggingStatus ( dataClient ) { const { body : response } = await dataClient . asCurrentUser . cluster . getSettings ( { include_defaults : true , } ) ; return { isDeprecationLogIndexingEnabled : isDeprecationLogIndexingEnabled ( response ) , isDeprecationLoggingEnabled : isDeprecationLoggingEnabled ( response ) , } ; } export async function setDeprecationLogging ( dataClient , isEnabled ) { const { body : response } = await dataClient . asCurrentUser . cluster . putSettings ( { body : { persistent : { 'logger.deprecation' : isEnabled ? 'WARN' : 'ERROR' , 'cluster.deprecation_indexing.enabled' : isEnabled , } , transient : { 'logger.deprecation' : isEnabled ? 'WARN' : 'ERROR' , 'cluster.deprecation_indexing.enabled' : isEnabled , } , } , } ) ; return { isDeprecationLogIndexingEnabled : isEnabled , isDeprecationLoggingEnabled : isDeprecationLoggingEnabled ( response ) , } ; } export function isDeprecationLogIndexingEnabled ( settings ) { const clusterDeprecationLoggingEnabled = [ 'defaults' , 'persistent' , 'transient' ] . reduce ( ( currentLogLevel , settingsTier ) => get ( settings , [ settingsTier , 'cluster' , 'deprecation_indexing' , 'enabled' ] , currentLogLevel ) , 'false' ) ; return clusterDeprecationLoggingEnabled === 'true' ; } export function isDeprecationLoggingEnabled ( settings ) { const deprecationLogLevel = [ 'defaults' , 'persistent' , 'transient' ] . reduce ( ( currentLogLevel , settingsTier ) => get ( settings , [ settingsTier , 'logger' , 'deprecation' ] , currentLogLevel ) , 'WARN' ) ; return [ 'ALL' , 'TRACE' , 'DEBUG' , 'INFO' , 'WARN' ] . includes ( deprecationLogLevel ) ; }