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.
Adds a key value pair to the given objects and returns a shallow copy. If the key is already present it will be overwritten.
key to be added
value to be added
object the key value pair is added to.
the object with the key value pair added
Adds the value to the object if it 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 key/value pairs beeing added.
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.
Same as pipe but for asynchronous functions: asynvPipe(finc1,func2,...funcN)(start) executes all functions in sequence awaiting the result and piping the response through in other words await funcN(... await func2(await func1(start))...)
a list of asynchronous functions to be executed in sequence
the reponse of the last function in the list.
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.
Flattens a array: [1,[2,[3,4]],5] will become [1,2,3,4,5]. Non primitive values are copied by reference.
array to be flattened
the flat 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
Identity function
Any object
the given argument without doing something
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
Merges the two object if second object is neither null nor undefined. If a key exists on a and b the value from b is taken
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.
Selects properties of an objects and returns a shallow copy. Non existing keys in the source object are ignored.
properties to be selected
object from which the values are taken
an object with the selected keys and corresponding values.
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.
We want to provide methods which accept a variable single number of elements and arrays. The overloaded signature to achieve this is: function doSomething(array: T[]) function doSomething(...varArgs: T[]) functiondoSomething(first: undefined | T | T[], ...rest: T[]) { //implementation } This wrapper methods makes it easy build an array from the input.
Either an array, the first element of the var args or undefined if no argument was given.
Second to last element if var args were used, empty array if the frist argument is an array.
Array from the input or empty array if no input was given.
@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