@btfuse/core
Version:
A native-first framework for building hybdrid web-native applications
99 lines (98 loc) • 3.88 kB
TypeScript
import { IFuseLogger, INativeLogEntry } from './IFuseLogger';
import { TSerializable } from './TSerializable';
import { ISerializable } from './ISerializable';
import { FuseLoggerLevel } from './FuseLoggerLevel';
/**
* A serializer for logging. This is different than a {@link FuseSerializer} in
* that in serializer transforms objects into a printable string representation.
*/
export declare class FuseLoggerSerializer {
constructor();
protected _serializeToString(obj: TSerializable): string;
protected _serializePrimitiveToString(obj: number | string | boolean): string;
protected _serializeErrorToString(obj: Error): string;
protected _serializeDateToString(obj: Date): string;
/**
* @remarks
* Serializes an object into a printable string.
*
* @param obj - The object to serialize
* @returns A printable string
*/
serialize(obj: TSerializable): string;
protected _isISerializable(x: any): x is ISerializable;
}
/**
* A base logger implementation which includes a serializer for common types.
* It will serialize/accept all values that TSerializable accepts, however Blob/ArrayBuffer
* or other binary data types will not be serialized. Instead it will print an
* object identifier, with mime type if present, along with the size of the buffer.
*
* The base logger does not provide any native bridging. While usable for purely webview side,
* use the FuseLoggerFactory to get a logger specific for your runtime environment.
*/
export declare class FuseLogger implements IFuseLogger {
private $level;
private $enableNativeBridge;
private $serializer;
constructor();
protected _registerNativeCalblack(): void;
/**
*
* @param level - A bitmask option to indicate which levels to log.
*
* @example
* To report on WARN and ERROR only, you would set:
*
* ```typescript
* logger.setLevel(FuseLoggerLevel.WARN | FuseLoggerLevel.ERROR);
* ```
*/
setLevel(level: number): void;
/**
*
* @returns The current log level bitmask.
*/
getLevel(): number;
/**
* @remarks
* If enabled, The native FuseLogger will pass native log messages to
* the webview and will be logged into the JS console. Logs passed through
* this logger will also be passed to the native environment and will be
* logged in the native's logging console.
*
* This can be helpful in debugging where all logs will be in the same place,
* however, logging can be verbose and can cause a degration of performance,
* therefore it may not be desirable to have enabled for production builds.
*
* This feature is currently enabled by default, however this is subject to
* change.
*
* @param flag - enables the native bridge logging if enabled.
*/
enableNativeBridge(flag: boolean): void;
protected _onNativeLogEntry(entry: INativeLogEntry): void;
/**
* @virtual - Implementators use this method to call on the native logging API.
* @param level - The log level for this log print
* @param message - Overridable hook to send logs to the native environment
*/
protected _logToNative(level: FuseLoggerLevel, message: string): void;
private $logToNative;
/**
* @param args - variadic arguments of serializable objects to log to the console
*/
debug(...args: TSerializable[]): void;
/**
* @param args - variadic arguments of serializable objects to log to the console
*/
info(...args: TSerializable[]): void;
/**
* @param args - variadic arguments of serializable objects to log to the console
*/
warn(...args: TSerializable[]): void;
/**
* @param args - variadic arguments of serializable objects to log to the console
*/
error(...args: TSerializable[]): void;
}