mirror of
https://github.com/JustinSDK/dotSCAD.git
synced 2025-08-19 04:51:26 +02:00
never used
This commit is contained in:
@@ -126,7 +126,6 @@ Too many dependencies? Because OpenSCAD doesn't provide namespace management, I
|
||||
- Other
|
||||
- [turtle2d](https://openhome.cc/eGossip/OpenSCAD/lib-turtle2d.html)
|
||||
- [turtle3d](https://openhome.cc/eGossip/OpenSCAD/lib-turtle3d.html)
|
||||
- [log](https://openhome.cc/eGossip/OpenSCAD/lib-log.html)
|
||||
|
||||
## Bugs and Feedback
|
||||
|
||||
|
@@ -1,46 +0,0 @@
|
||||
# log
|
||||
|
||||
A log module which supports simple level configurations and color titles.
|
||||
|
||||
## Parameters
|
||||
|
||||
- `$log_level` : The accepted values are `"OFF"` (-1), `"INFO"` (20),
|
||||
`"WARNING"` (30), `"ERROR"` (40) or positive integers. The default value is `"INFO"`.
|
||||
- `level` : The accepted values are `"OFF"` (-1), `"INFO"` (20),
|
||||
`"WARNING"` (30), `"ERROR"` (40) or positive integers. If the value is greater or equal to `$log_level`, the `echo` message will display in the console.
|
||||
- `level_color` : Controls the color of level title. It accepts the same values as the CSS `color` property.
|
||||
|
||||
## Examples
|
||||
|
||||
include <log.scad>;
|
||||
|
||||
log()
|
||||
echo(" INFO message");
|
||||
|
||||
log("WARNING")
|
||||
echo(" WARNING message");
|
||||
|
||||
log("ERROR") {
|
||||
echo(" ERROR message 1");
|
||||
echo(" ERROR message 2");
|
||||
}
|
||||
|
||||

|
||||
|
||||
include <log.scad>;
|
||||
|
||||
$log_level = "WARNING";
|
||||
|
||||
log()
|
||||
echo(" INFO message");
|
||||
|
||||
log("WARNING", "purple")
|
||||
echo(" WARNING message");
|
||||
|
||||
log("ERROR", "rgb(255, 100, 100)") {
|
||||
echo(" ERROR message 1");
|
||||
echo(" ERROR message 2");
|
||||
}
|
||||
|
||||

|
||||
|
70
src/log.scad
70
src/log.scad
@@ -1,70 +0,0 @@
|
||||
/**
|
||||
* log.scad
|
||||
*
|
||||
* @copyright Justin Lin, 2017
|
||||
* @license https://opensource.org/licenses/lgpl-3.0.html
|
||||
*
|
||||
* @see https://openhome.cc/eGossip/OpenSCAD/lib-log.html
|
||||
*
|
||||
**/
|
||||
|
||||
/*
|
||||
The accepted values are "OFF" (-1), "INFO" (20),
|
||||
"WARNING" (30), "ERROR" (40) or positive integers.
|
||||
*/
|
||||
$log_level = "INFO";
|
||||
|
||||
module log(level = "INFO", level_color) {
|
||||
default_level_ints = [
|
||||
["OFF", -1],
|
||||
["INFO", 20],
|
||||
["WARNING", 30],
|
||||
["ERROR", 40]
|
||||
];
|
||||
|
||||
default_level_colors = [
|
||||
["INFO", "green"],
|
||||
["WARNING", "orange"],
|
||||
["ERROR", "red"]
|
||||
];
|
||||
|
||||
/*
|
||||
The built-in lookup function require integer keys.
|
||||
I overwrite it so that using string keys is ok.
|
||||
*/
|
||||
function lookup(key, mappings, i = 0) =
|
||||
i == len(mappings) ? key : (
|
||||
key == mappings[i][0] ?
|
||||
mappings[i][1] :
|
||||
lookup(key, mappings, i + 1)
|
||||
);
|
||||
|
||||
if($log_level != "OFF") {
|
||||
argu_level = lookup(level, default_level_ints);
|
||||
golbal_level = lookup(
|
||||
$log_level == undef ? "INFO" : $log_level,
|
||||
default_level_ints
|
||||
);
|
||||
|
||||
if(argu_level >= golbal_level) {
|
||||
c = level_color == undef ? lookup(level, default_level_colors) : level_color;
|
||||
lv = str(len(level) == undef ? "LEVEL " : "", level);
|
||||
|
||||
// level text
|
||||
echo(
|
||||
str(
|
||||
"<b>",
|
||||
"<span style='color:", c, "'>",
|
||||
lv,
|
||||
"</span>",
|
||||
"</b>"
|
||||
)
|
||||
);
|
||||
|
||||
// echo
|
||||
for(i = [0:$children - 1]) {
|
||||
children(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user