Skip to content
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

Add documentation for v1.1.0 #22

Merged
merged 14 commits into from
Jun 16, 2019
48 changes: 48 additions & 0 deletions documentation/UserGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Users can configure the way the logger works and the image will use this configu
For specific cases, a specialized logger can be used.

- [User documentation of TinyLogger](#user-documentation-of-tinylogger)
* [Quick start](#quick-start)
* [Configure your logger](#configure-your-logger)
+ [Add sub-loggers to your `TinyLogger`](#add-sub-loggers-to-your--tinylogger-)
+ [Remove sub-loggers](#remove-sub-loggers)
Expand All @@ -16,6 +17,40 @@ For specific cases, a specialized logger can be used.
+ [Record a single line log](#record-a-single-line-log)
+ [Recording the execution of a task](#recording-the-execution-of-a-task)
* [Use another logger than the global logger](#use-another-logger-than-the-global-logger)

## Quick start

This section will explain in 30 seconds how to create a logger for an application and use it. Then we will explore more advance features.
jecisc marked this conversation as resolved.
Show resolved Hide resolved

Here is an example fo snippet to create a logger using a file `Progress.log`:
jecisc marked this conversation as resolved.
Show resolved Hide resolved

```Smalltalk
TinyLogger default
addFileLoggerNamed: 'Progress.log'.
```

This code need to be executed **one time** in the image. For an application, it will probably be added to a method *initialize* on the class side of a class to be executed one time at the loading of the project in the image.

In case you need to execute the code multiple times you can use this snippet instead:
jecisc marked this conversation as resolved.
Show resolved Hide resolved

```Smalltalk
TinyLogger default
ensureFileLoggerNamed: 'Progress.log'.
```

Then write a message to the log using `record`:

```Smalltalk
'Uh oh. Something happened.' record
```

Or wrap the execution of an action by logs using `execute:recordedAs:`:
jecisc marked this conversation as resolved.
Show resolved Hide resolved

```Smalltalk
self execute: [ "Some code doing something" ] recordedAs: 'Launching bananas.'
jecisc marked this conversation as resolved.
Show resolved Hide resolved
```

Now, if you want to know more about the project, let's proceed on a more detailed documentation.

## Configure your logger

Expand Down Expand Up @@ -50,6 +85,19 @@ TinyLogger default
addFileLoggerNamed: '../logs/MyOtherLog.log'.
```

Additionaly to those methods, `TinyLogger` also propose ways to add loggers only if they have no equivalent already registered.

In order to archieve this result, you can use the equivalent of the methods previously explained, replacing `add` by `ensure`:
jecisc marked this conversation as resolved.
Show resolved Hide resolved
```Smalltalk
TinyLogger default
ensureStdoutLogger;
ensureTranscriptLogger;
ensureFileLogger;
ensureFileLoggerNamed: '../logs/MyOtherLog.log'.
```

With those methods, Transcript and Stdout loggers will be limited to one, and file loggers will be limited to one by file name.

### Remove sub-loggers

If at some point you wants to remove one or multiple loggers, `TinyLogger` has some API elements to do that.
jecisc marked this conversation as resolved.
Show resolved Hide resolved
Expand Down