mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-06-01 23:30:35 +00:00
### Description
See
454996d496
for manual changes (excluded auto-generated formatting changes)
### Why
Because the toolsets for old clang-format is out-of-date. This reduces
the development efficiency.
- The NPM package `clang-format` is already in maintenance mode. not
updated since 2 years ago.
- The VSCode extension for clang-format is not maintained for a while,
and a recent Node.js security update made it not working at all in
Windows.
No one in community seems interested in fixing those.
Choose Prettier as it is the most popular TS/JS formatter.
### How to merge
It's easy to break the build:
- Be careful of any new commits on main not included in this PR.
- Be careful that after this PR is merged, other PRs that already passed
CI can merge.
So, make sure there is no new commits before merging this one, and
invalidate js PRs that already passed CI, force them to merge to latest.
46 lines
1.4 KiB
TypeScript
46 lines
1.4 KiB
TypeScript
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
// Licensed under the MIT License.
|
|
|
|
import { Env } from 'onnxruntime-common';
|
|
|
|
import { logLevelStringToEnum } from '../wasm-common';
|
|
|
|
type LogLevel = NonNullable<Env['logLevel']>;
|
|
type MessageString = string;
|
|
type MessageFunction = () => string;
|
|
type Message = MessageString | MessageFunction;
|
|
|
|
const logLevelPrefix = ['V', 'I', 'W', 'E', 'F'];
|
|
|
|
const doLog = (level: number, message: string): void => {
|
|
// eslint-disable-next-line no-console
|
|
console.log(`[${logLevelPrefix[level]},${new Date().toISOString()}]${message}`);
|
|
};
|
|
|
|
let configLogLevel: LogLevel | undefined;
|
|
let debug: boolean | undefined;
|
|
|
|
export const configureLogger = ($configLogLevel: LogLevel, $debug: boolean): void => {
|
|
configLogLevel = $configLogLevel;
|
|
debug = $debug;
|
|
};
|
|
|
|
/**
|
|
* A simple logging utility to log messages to the console.
|
|
*/
|
|
export const LOG = (logLevel: LogLevel, msg: Message): void => {
|
|
const messageLevel = logLevelStringToEnum(logLevel);
|
|
const configLevel = logLevelStringToEnum(configLogLevel);
|
|
if (messageLevel >= configLevel) {
|
|
doLog(messageLevel, typeof msg === 'function' ? msg() : msg);
|
|
}
|
|
};
|
|
|
|
/**
|
|
* A simple logging utility to log messages to the console. Only logs when debug is enabled.
|
|
*/
|
|
export const LOG_DEBUG: typeof LOG = (...args: Parameters<typeof LOG>) => {
|
|
if (debug) {
|
|
LOG(...args);
|
|
}
|
|
};
|