@fliegwerk/logsemts
Install using
npm install @fliegwerk/logsemts
You can access these members by importing the module:
import { member } from '@fliegwerk/logsemts';
serialize
function serialize
(
value
:
any
)
:
any
Serialize a value to the SerializedTransportFormat
specifications
@param:
value the value that gets serialized
@return:
the serialized JSON string
@see:
@example:
let a = {};
let b = { a:a }
a['b'] = a;
JSON.stringify(a); // throws Error because of cyclic dependency
// serialize a, which returns "instructions" for re-building its structure
const serialized = serialize(a);
// rebuild a's structure from "instructions"
const deserialized = deserialize(serialized);
console.log(deserialized); // logs the "correct" structure
deserialize
function deserialize
(
serialized
:
string
)
:
any
Deserialize a JSON string representing a SerializedTransportFormat
.
SerializedTransportFormat
interface
SerializedTransportFormat
@author:
Pablo Klaschka
@packageDocumentation:
@example:
let a = {};
let b = { a:a }
a['b'] = a;
JSON.stringify(a); // throws Error because of cyclic dependency
// serialize a, which returns "instructions" for re-building its structure
const serialized = serialize(a);
// rebuild a's structure from "instructions"
const deserialized = deserialize(serialized);
console.log(deserialized); // logs the "correct" structure
pool
Type:
any[]
A memory pool for values the pointers in pointers
can point to
pointers
Type:
{ [key: string]: number }
Pointers (indexes) of values stored in the pool
in the order they can get built in.
Separations are achieved using the ->
string.
The pointer to the serialized value is ''
, meaning pointers['']
is the serialized element's index in the
pool
.
@example:
// the serialized value points to an object (`s`) that is at index 0 in the pool
// `s['a']` has the value of an array stored at index 1 in the pool.
// this array has `s` as its only member, i.e., `s['a'][0] === s`:
{ '': 0, '->a': 1, '->a->0': 1 }
types
Type:
(
| 'undefined'
| 'object'
| 'boolean'
| 'number'
| 'string'
| 'symbol'
| 'function'
| 'bigint'
| 'regexp'
| 'Date'
)[]
The tye of the value in the pool
with the same index.
Can be either a value "returned" by the typeof
operator or a special value for supported types:
regexp
- a RegExp
objectBrowserLogger
const
:
() => LogFunction
A LogFunctionFactory
to log the the browser developer tools
See: LogFunction
@returns:
the LogFunction
@category:
LogFunction / LogFunction Factory
@example:
import { BrowserLogger } from '@fliegwerk/logsemts';
const loggers = [
BrowserLogger() // a LogFunction to log into the browser dev tools
];
PlainLoggerOptions
interface
PlainLoggerOptions
Options for PlainLogger
logFunction
Type:
(...args: any) => void
The function that logs the contents
@param:
args
@default:
console.log
PlainLogger
const
:
(
options?: PlainLoggerOptions
) => LogFunction
A LogFunctionFactory
to log in environments that don't support color
@return:
the LogFunction
@category:
LogFunction / LogFunction Factory
@see:
@see:
@example:
import { PlainLogger } from '@fliegwerk/logsemts';
const loggers = [
PlainLogger(), // a LogFunction to log into the browser dev tools
PlainLogger({logFunction: myFunction}) // use myFunction instead of console.log
];
ChalkLogger
const
:
(ch: Chalk) => LogFunction
A LogFunctionFactory
to log the the terminal in NodeJS using the https://github.com/chalk/chalk|chalk
library
@param:
ch The chalk object.
@returns:
the LogFunction
@see:
@see:
@category:
LogFunction / LogFunction Factory
@example:
import { ChalkLogger } from '@fliegwerk/logsemts';
import chalk from 'chalk';
const loggers = [
ChalkLogger(chalk) // generates a new LogFunction using the chalk object
];
WebhookLoggerOptions
interface
WebhookLoggerOptions
Options for the WebhookLogger
address
Type:
string
the address to which the POST
requests for logs get sent
WebhookLogger
const
:
(
options: WebhookLoggerOptions
) => LogFunction
A LogFunctionFactory
to send serialized form of message to a specific web address in a POST request
@return:
the LogFunction
@category:
LogFunction / LogFunction Factory
@see:
@see:
@see:
@example:
import { WebhookLogger } from '@fliegwerk/logsemts';
const loggers = [
// sends a serialized JSON form of the message to the specified address
WebHookLogger({address: 'http://localhost:8080'})
];
ComponentLogger
class
ComponentLogger
A logger for a specific component like API Client, Message Provider, or similar
@example:
const = new ComponentLogger((type, style, ...args) => {
const componentStyle = new Style(
'red' // text color
componentBackgroundColor // background color
);
logFunction(type, style, componentName, componentStyle, ...args);
);
constructor
function
(
semanticLogFunction
:
(
type: string,
style: Style,
...args: any[]
) => void
)
:
any
@param:
semanticLogFunction A semantic log function that can already process the type and style of the semantic log type.
debug (...)
function debug
(
...
args
:
any[]
)
:
any
Log some debug information
@param:
args information that gets logged
success (...)
function success
(
...
args
:
any[]
)
:
any
Log some success information
@param:
args information that gets logged
error (...)
function error
(
...
args
:
any[]
)
:
any
Log an error
@param:
args error information that gets logged
warn (...)
function warn
(
...
args
:
any[]
)
:
any
Log a warning
@param:
args warning that gets logged
info (...)
function info
(
...
args
:
any[]
)
:
any
Log some information
@param:
args information that gets logged
Logger
class
Logger
A semantic logger written in TypeScript
Manages a number of LogFunctions, to which logs get passed. These can, e.g., log the entries to the browser console or send it to a remote database.
For each subsystem (e.g., an API Client), a new component logger gets used which can be fetched using Logger.getComponentLogger
This ComponentLogger
then contains multiple semantic logging functions including ComponentLogger.success
, ComponentLogger.error
, ComponentLogger.warn
, and ComponentLogger.debug
.
The console output is color-coded. The semantic log levels have pre-defined colors and the components get color-coded with a color that's from their name.
@see:
@see:
@example:
import Logger, {BrowserLogger} from '@fliegwerk/logsemts';
const logger = new Logger({loggers: [BrowserLogger]});
logger.getComponentLogger('API Client').success('fetched API data');
constructor
function
(
options
:
LoggerOptions
)
:
any
Create a new Logger
. Usually gets used only once per application (as a singleton)
@param:
options
getSubsystemLogger (...)
function getSubsystemLogger
(
subsystemName
:
string
)
:
any
Returns the logger for a specific subsystem or component
@param:
subsystemName the subsystem's or component's name
@deprecated:
Use getComponentLogger
instead.
getComponentLogger (...)
function getComponentLogger
(
componentName
:
string
)
:
any
Returns the logger for a specific component
@param:
componentName the component's name