-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Log output keeps line numbers #4
Comments
If you use webpack or browserify, the easiest way to keep line numbers and also add prefix is to use An example for webpack that adds module: {
rules: [
{
test: /\.m?js$/,
exclude: /(node_modules|bower_components)/,
use: [
{
loader: "babel-loader"
},
{
loader: "string-replace-loader",
options: {
search: "(logger\\.(?:trace|debug|info|warn|error))\\((.*)\\)",
replace: (match, p1, p2) => {
// All string must be wrapped in double quote
const inBracket = [false, false];
const splitLoc = [];
for (let i = 0; i < p2.length; i++) {
if (p2[i] === '"' && (i == 0 || p2[i - 1] !== "\\")) {
inBracket[0] = !inBracket[0];
} else if (p2[i] === "`") {
inBracket[1] = !inBracket[1];
}
if (p2[i] === "," && !inBracket[0] && !inBracket[1]) {
splitLoc.push(i);
}
}
const args = [];
for (let i = 0; i < splitLoc.length; i++) {
const iBegin = i == 0 ? 0 : splitLoc[i - 1] + 1;
args.push(p2.slice(iBegin, splitLoc[i]));
}
if (splitLoc.length === 0) {
args.push(p2);
} else {
args.push(p2.slice(splitLoc[splitLoc.length - 1] + 1));
}
return `${p1}("[Super-preloader]", ${args.join(",")})`;
},
flags: "g"
}
}
]
}
]
}, |
Do we have a solution for non webpack users? |
One of the features of loglevel is to keep the original line numbers. This plugin breaks this feature. |
If someone helps. I made a modification in the LogLevel code to add the formatted suffix: https://github.com/itamayo/loglevel |
logs don't keeps line numbers
The text was updated successfully, but these errors were encountered: