@graphty/graphty-element / logging / GraphtyLogger
Variable: GraphtyLogger ​
constGraphtyLogger:object
Defined in: graphty-element/src/logging/GraphtyLogger.ts:500
Main logger facade for graphty-element.
Usage:
import { GraphtyLogger, LogLevel } from "@graphty/graphty-element/logging";
// Configure logging
await GraphtyLogger.configure({
enabled: true,
level: LogLevel.DEBUG,
modules: "*",
format: { timestamp: true, module: true },
});
// Get a logger for a category
const logger = GraphtyLogger.getLogger(["graphty", "layout"]);
logger.info("Layout started", { nodeCount: 100 });
// Configure with remote logging
await GraphtyLogger.configure({ remoteLogUrl: "https://localhost:9080" });
// Attach a destination by handing over the object...
GraphtyLogger.addSink({
name: "custom",
write: (record) => { ... },
});
// ...or by naming one that registerLogSink registered, which a stored configuration can do
await GraphtyLogger.configure({ sinks: [{ use: "acme-collector", options: { capacity: 200 } }] });Type Declaration ​
addSink ​
addSink: (
sink) =>void
Add a custom sink to the logger.
Attach a destination, letting go of whatever it replaced.
Parameters ​
sink ​
The destination to attach.
Returns ​
void
configure ​
configure: (
config) =>Promise<void> =configureGraphtyLogging
Configure the logging system.
Configure the logging system.
Parameters ​
config ​
What to change. What is absent keeps the value it has.
Returns ​
Promise<void>
A promise that is already settled: the configuration takes effect before this returns, so a caller that does not await it still loses no records.
Throws ​
A GraphtyError with E_UNKNOWN_SINK when sinks names a destination nothing registered.
flush ​
flush: () =>
Promise<void> =flushSinks
Flush all sinks that support flushing.
Flush every destination that buffers, each one on its own.
One destination's failure is reported and does not reject the caller's flush: otherwise a third party's collector could hide whether the element's own remote destination got its records out.
Returns ​
Promise<void>
formatRecord ​
formatRecord: (
record,options?) =>string=formatLogRecord
Render a record the way the element renders its own console line.
Render one record as the element renders its own: [time] [category] [LEVEL] message.
The parts are omitted rather than blanked, so a line with neither a time nor a category is [INFO] message and not two empty brackets.
Parameters ​
record ​
The record to render.
options? ​
What to leave out. Defaults to the current logging configuration's format.
Returns ​
string
The line, with no trailing newline and no structured data -- record.data is passed to a console or a server beside the line rather than flattened into it.
getLogger ​
getLogger: (
category) =>Logger=getGraphtyLogger
Get a logger for the specified category.
Get a logger for the specified category.
Parameters ​
category ​
string[]
Hierarchical category path, e.g., ["graphty", "layout", "ngraph"]
Returns ​
Logger instance for the category
getSinks ​
getSinks: () =>
Sink[]
Get all registered sinks.
Get all registered sinks.
Returns ​
Sink[]
Array of registered sinks
isEnabled ​
isEnabled: () =>
boolean=isLoggingEnabled
Check if logging is enabled.
Check if logging is enabled.
Returns ​
boolean
true if logging is enabled
removeSink ​
removeSink: (
name) =>boolean
Remove a sink by name.
Remove a sink by name.
Parameters ​
name ​
string
The name of the sink to remove
Returns ​
boolean
true if the sink was removed, false if it didn't exist