Npm log levels used for the SAP Cloud SDK logger.
Denotes the OData version.
Default logger for the SAP Cloud SDK for unhandled exceptions.
Format for logging in Kibana.
Format for local logging.
Calls rambda's assoc function if the provided value is neither null nor undefined. Note that this is different to JS idiomatic checks for truthy/falsy values, i.e. an empty string will result in assoc being called.
The key to associate with the given value.
The value to associate with the given key.
A copy of the input object with the new key-value pair if the value is neither null nor undefined.
Returns the OData version in capital letters so V2 or V4.
OData version in lower case: 'v2' or 'v4'
'V2' or 'V4'
Create a logger for the given message context, if available.
Usage:
To create a logger in your module, it is recommended to pass a module identifier that will be logged as messageContext
for all messages from this logger:
const logger = createLogger('my-module');
. Not setting any module identifier will retrieve the default logger.
Use this logger throughout your module. If the module is spread over multiple files, you can retrieve the logger instance by calling the createLogger
function with the respective module identifier.
There will always be only one instance of a logger per module identifier.
You can pass any custom data that you want to be logged in addition by passing an object instead. You can change the default logging level (INFO
) using the level
key in the object.
In those cases, provide the messageContext
as a key in the object:
const logger = createLogger({
messageContext: 'my-module',
myCustomKey: 'my-custom-data',
level: 'debug'
});
You will find these information under the _custom_fields_ key in your Cloud Foundry logs.
To retrieve a logger after its creation use getLogger. If you want to change the log level of a logger use setLogLevel.
Either a key for the message context of all messages produced by the logger or an object with additional keys to set in the message.
A newly created or an already existing logger for the given context.
Disable logging of exceptions. Enabled by default.
Enable logging of exceptions. Enabled by default.
Get the first item from an array. Returns undefined if the array is empty.
Array to get the first item of
Fist item of the array or undefined if the array was empty
Flatten a two dimensional array into a one dimensional array
The array to be flattened.
A one dimensional array.
Get logger for a given message context, if avilable.
A key for the message context of all messages produced by the logger
The logger for the given messageContext if it was created before
Checks whether a value is either null
or undefined
.
Value to check
true for null or undefined, false otherwise.
Get the last item from an array. Returns undefined if the array is empty.
Array to get the last item of
Last item of the array or undefined if the array was empty
Calls rambda's merge function if second object is neither null nor undefined.
The object to merge into.
The object which to merge into a.
A copy of the merge(a, b) or a if b is undefined or null.
Mute all logger output created by the SAP Cloud SDK Logger. This also applies to future loggers created. Useful for tests.
Checks if a chain of properties exists on the given object.
The object to be checked.
Chained properties.
True if the property chain leads to a truthy value, false otherwise.
Takes an object and returns a new object whose keys are renamed according to the provided key mapping. Any keys in the input object not present in the key mapping will be present in the output object as-is. If a key in the key mapping is not present in the input object, the output object will contain the key with value "undefined".
An object mapping keys of the input object to keys of the output object.
The input object.
An object with renamed keys.
Change the global log level of the container which will set default level for all active loggers.
E. g., to set the global log level call setGlobalLogLevel('debug')
.
Change the log level of a logger based on its message context.
E. g., to set the log level for the destination accessor module of the SDK to debug, simply call setLogLevel('debug', 'destination-acessor')
.
level to set the logger to. Use an empty string '' as level to unset context level.
Message context of the logger to change the log level for or the logger itself
Split the given array in chunks
Array to be splitted. The last aray could be shorter.
Size of the chunks
Array with arrays of chunks size.
Remove all duplicates from array
Array that might contain duplicates
Array of unique items
Unmute all logger output created by the SAP Cloud SDK Logger. This also applies to future loggers created. Useful for tests.
@sap-cloud-sdk/util
Package that contains general utility functions that we reuse multiple times in the SDK. While primarily designed for internal usage, they might also be beneficial for consumers of the SDK.
Installation
$ npm install @sap-cloud-sdk/util
Usage
The util package collects useful tools that help build your SAP Cloud Platform application. For example, the following code snippet changes the log level of the destination accessor of the SDK.
import { setLogLevel } from '@sap-cloud-sdk/util'; setLogLevel('debug', 'destination-accessor');
Documentation
Getting started guide API documentation
Helpful Links