From 1e1caa17fae594b82d9e03c7c7cc10bd50683c3a Mon Sep 17 00:00:00 2001 From: Andrew Janke Date: Sun, 18 Feb 2018 11:16:00 -0500 Subject: [PATCH] add File Exchange text --- README.md | 4 +++ doc/Text for File Exchange.md | 60 +++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 doc/Text for File Exchange.md diff --git a/README.md b/README.md index 0489f0be..6c2d5c84 100644 --- a/README.md +++ b/README.md @@ -79,3 +79,7 @@ log4j was chosen as the back-end because that's what ships with Matlab. ## License SLF4M is dual licensed under the business-friendly Apache 2.0 and BSD 2-clause licenses. Pick whichever you like. + +## Author + +SLF4M is developed by [Andrew Janke](https://apjanke.net). Its home page is [the repo on GitHub](https://github.com/apjanke/SLF4M). diff --git a/doc/Text for File Exchange.md b/doc/Text for File Exchange.md new file mode 100644 index 00000000..f79216ac --- /dev/null +++ b/doc/Text for File Exchange.md @@ -0,0 +1,60 @@ +SLF4M is a simple but flexible logging framework for Matlab, built on top of SLF4J and Apache log4j. You can +use it to do runtime-configurable logging from your Matlab scripts and programs. This can be more informative and more manageable than commenting in and out `fprintf()` statements. + +The API is simple enough that you can get up and running with it quickly, or even use it casually in scripts, but it's flexible and powerful enough to be useful for larger systems. + +Usage +------------------------- + + +The logging functions are in the `+logm` package. Call them from within your Matlab code. + +``` +function helloWorld(x) + +if nargin < 1 || isempty(x) + x = 123.456; + % These debug() calls will only show up if you set log level to DEBUG + logm.debug('Got empty x input; defaulted to %f', x); +end +z = x + 42; + +logm.info('Answer z=%f', z); +if z > intmax('int32') + logm.warn('Large value z=%f will overflow int32', z); +end + +try + some_bad_operation(x); +catch err + logm.error('Something went wrong in some_bad_operation(%f): %s', ... + x, err.message); +end + +end +``` + +The output looks like this: + +``` +>> helloWorld +08:57:47.178 INFO helloWorld() - Answer z=165.456000 +08:57:47.179 ERROR helloWorld() - Something went wrong in some_bad_operation(123.456000): Undefined function 'some_bad_operation' for input arguments of type 'double'. +``` + +Thanks to `dispstr()`, you can also pass Matlab objects to the `%s` conversions. + +``` +>> m = containers.Map; +>> m('foo') = 42; m('bar') = struct; +>> logm.info('Hello, world! %s', m) +09:52:29.809 INFO base - Hello, world! 2-by-1 containers.Map +``` + +For more details, see the User's Guide included in the distribution. + +Author +----------------------------------- + +SLF4M's home page is the repo on GitHub: https://github.com/apjanke/SLF4M. +