-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from ellemenno/v1.0.0
v1.0.0
- Loading branch information
Showing
14 changed files
with
764 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
bin/ | ||
lib/build/ | ||
logs/ | ||
releases/ | ||
test/bin/ | ||
TEST-*.xml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,116 @@ | ||
# log-ls | ||
log-ls | ||
====== | ||
|
||
a simple logging framework for Loom, plus a handy config reader | ||
|
||
|
||
## installation | ||
|
||
Download the library into its matching sdk folder: | ||
|
||
$ curl -L -o ~/.loom/sdks/sprint34/libs/Log.loomlib \ | ||
https://github.com/pixeldroid/log-ls/releases/download/v1.0.0/Log-sprint34.loomlib | ||
|
||
To uninstall, simply delete the file: | ||
|
||
$ rm ~/.loom/sdks/sprint34/libs/Log.loomlib | ||
|
||
|
||
## usage | ||
|
||
### Log | ||
|
||
0. import `Log` (once per class) | ||
0. declare a label (once per class) | ||
0. set the log level (once at app startup, ideally from a config file value) | ||
0. submit a message generator at some verbosity level (`debug`, `info`, `warn`, `error`, `fatal`) | ||
|
||
```ls | ||
package | ||
{ | ||
import loom.Application; | ||
import pixeldroid.util.Log; | ||
import pixeldroid.util.LogLevel; | ||
public class LogTest extends Application | ||
{ | ||
private const _logName:String = getFullTypeName(); | ||
override public function run():void | ||
{ | ||
Log.level = LogLevel.INFO; | ||
Log.info(_logName, function():String { return _logName +' is running!'; }); | ||
} | ||
} | ||
} | ||
``` | ||
|
||
### Config | ||
|
||
0. create a json file named `app.config` in the `assets/` folder of the project root | ||
0. import `Config` | ||
0. retrieve values | ||
|
||
```json | ||
{ | ||
"app_version": "1.0.0", | ||
"log_level": "DEBUG", | ||
"my_string": "string value", | ||
"my_number": 123.456, | ||
"my_integer": 789 | ||
} | ||
``` | ||
> _assets/app.config_ | ||
```ls | ||
package | ||
{ | ||
import loom.Application; | ||
import pixeldroid.util.Config; | ||
import pixeldroid.util.Log; | ||
import pixeldroid.util.LogLevel; | ||
public class ConfigTest extends Application | ||
{ | ||
private const _logName:String = getFullTypeName(); | ||
override public function run():void | ||
{ | ||
Log.level = LogLevel.INFO; | ||
Log.info(_logName, function():String { return 'app version: ' +Config.appVersion; }); | ||
Log.info(_logName, function():String { return 'log level: ' +Config.logLevel; }); | ||
Log.info(_logName, function():String { return 'my string: ' +Config.getString('my_string'); }); | ||
Log.info(_logName, function():String { return 'my number: ' +Config.getNumber('my_number'); }); | ||
Log.info(_logName, function():String { return 'my integer: ' +Config.getInteger('my_integer'); }); | ||
} | ||
} | ||
} | ||
``` | ||
|
||
## working from source | ||
|
||
first install [loomtasks][loomtasks] | ||
|
||
### compiling | ||
|
||
$ rake lib:install | ||
|
||
this will build the Log library and install it in the currently configured sdk | ||
|
||
### running tests | ||
|
||
$ rake test | ||
|
||
this will build the Log library, install it in the currently configured sdk, build the test app, and run the test app. | ||
|
||
|
||
## contributing | ||
|
||
Pull requests are welcome! | ||
|
||
|
||
[loomtasks]: https://github.com/pixeldroid/loomtasks "loomtasks" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
LIB_NAME = 'Log' | ||
LIB_VERSION_FILE = File.join('lib', 'src', 'pixeldroid', 'util', 'Log.ls') | ||
|
||
begin | ||
load(File.join(ENV['HOME'], '.loom', 'tasks', 'loomlib.rake')) | ||
rescue LoadError | ||
abort([ | ||
'error: missing loomlib.rake', | ||
' please install loomtasks before running this Rakefile:', | ||
' https://github.com/pixeldroid/loomtasks/', | ||
].join("\n")) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"app_version": "0.0.0", | ||
"log_level": "DEBUG", | ||
"string": "string value", | ||
"number": 123.456, | ||
"integer": 789 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"sdk_version": "sprint34" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"name": "Log", | ||
"version": "1.0", | ||
"outputDir": "build", | ||
"references": [ | ||
"System" | ||
], | ||
"modules": [ | ||
{ | ||
"name": "Log", | ||
"version": "1.0", | ||
"sourcePath": [ | ||
"." | ||
] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
package pixeldroid.util | ||
{ | ||
import pixeldroid.util.LogLevel; | ||
|
||
/** | ||
Provides access to configuration values defined in `assets/app.config`. | ||
*/ | ||
class Config | ||
{ | ||
private static var _fileContents:String; | ||
private static var _json:JSON; | ||
|
||
/** | ||
Retrieve the verbosity level to be used for the logging system. | ||
*/ | ||
public static function get logLevel():LogLevel | ||
{ | ||
var value:String = json.getString('log_level'); | ||
|
||
return LogLevel.fromString(value); | ||
} | ||
|
||
/** | ||
Retrieve the raw contents of the app.config file. | ||
*/ | ||
public static function get fileContents():String | ||
{ | ||
if (!_fileContents) | ||
{ | ||
var filePath:String = 'assets/app.config'; | ||
if (File.fileExists(filePath)) _fileContents = File.loadTextFile(filePath); | ||
else Debug.assertException(new Error("no config file found at '" +filePath +"'")); | ||
} | ||
|
||
return _fileContents; | ||
} | ||
|
||
/** | ||
Reload the config values from file. | ||
*/ | ||
public static function refresh():void | ||
{ | ||
_fileContents = null; | ||
_json.loadString(fileContents); | ||
} | ||
|
||
/** | ||
Retrieve the app version string. | ||
*/ | ||
public static function get appVersion():String | ||
{ | ||
var value:String = json.getString('app_version'); | ||
|
||
return value; | ||
} | ||
|
||
/** | ||
Retrieve an arbitrary string value from app.config. | ||
*/ | ||
public static function getString(key:String):String | ||
{ | ||
var value:String = json.getString(key); | ||
|
||
return value; | ||
} | ||
|
||
/** | ||
Retrieve an arbitrary number value from app.config. | ||
Note: the number must be defined with a decimal point. | ||
*/ | ||
public static function getNumber(key:String):Number | ||
{ | ||
var value:Number = json.getFloat(key); | ||
|
||
return value; | ||
} | ||
|
||
/** | ||
Retrieve an arbitrary integer value from app.config. | ||
*/ | ||
public static function getInteger(key:String):Number | ||
{ | ||
var value:Number = json.getInteger(key); | ||
|
||
return value; | ||
} | ||
|
||
|
||
private static function get json():JSON | ||
{ | ||
if (!_json) | ||
{ | ||
_json = new JSON(); | ||
if (!_json.loadString(fileContents)) | ||
{ | ||
Debug.assertException(new Error("error parsing json file: '" +_json.getError() +"'")); | ||
} | ||
} | ||
|
||
return _json; | ||
} | ||
} | ||
} |
Oops, something went wrong.