Skip to content

Commit 499f334

Browse files
committed
updated doc with scriptingAPI
1 parent 7e7d475 commit 499f334

File tree

2 files changed

+104
-35
lines changed

2 files changed

+104
-35
lines changed

doc/README.md

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -218,42 +218,8 @@ The InfoLogger library allows to inject messages directly from programs, as show
218218
219219
* InfoLogger library is also available for: Tcl, Python, Go.
220220
It allows to log message from scripting languages. A simplified subset of the InfoLogger C++ API is made available through SWIG-generated modules.
221-
Example usage is shown below. Files listed there are available from the infoLogger library installation directory.
221+
Details of the functions accessible from the scripting interface are provided in [a separate document](scriptingAPI.md).
222222
223-
* Tcl
224-
** Library files: infoLoggerForTcl.so
225-
** Code example: (interactive interpreter from the command line)
226-
```
227-
tclsh
228-
load infoLoggerForTcl.so
229-
set logHandle [InfoLogger]
230-
$logHandle logInfo "This is a test"
231-
$logHandle logError "Something went wrong"
232-
```
233-
* Python
234-
** Library files: _infoLoggerForPython.so and infoLoggerForPython.py
235-
** Code example: (interactive interpreter from the command line)
236-
```
237-
python
238-
import infoLoggerForPython
239-
logHandle=infoLoggerForPython.InfoLogger()
240-
logHandle.logInfo("This is a test")
241-
logHandle.logError("Something went wrong")
242-
```
243-
* Go
244-
** Library files: infoLoggerForGo.a and infoLoggerForGo.go (to be copied to ${GOPATH}/src/infoLoggerForGo)
245-
** Build: CGO_LDFLAGS="${GOPATH}/src/infoLoggerForGo/infoLoggerForGo.a -lstdc++" go build
246-
** Code example:
247-
```
248-
package main
249-
import "infoLoggerForGo"
250-
func main() {
251-
var logHandle=infoLoggerForGo.NewInfoLogger()
252-
logHandle.LogInfo("This is a test")
253-
logHandle.LogError("Something went wrong")
254-
}
255-
```
256-
257223
258224
## Configuration
259225

doc/scriptingAPI.md

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
# Scripting API
2+
3+
This document describes the interface to be used to inject messages into the InfoLogger logging system
4+
from languages other than C or C++.
5+
6+
Languages currently supported are: Tcl, Python, Go, Javascript (node.js/v8).
7+
8+
A subset of the InfoLogger C++ API (covering most use-cases) is exported using SWIG-generated modules.
9+
This avoids the tedious work of manually writing native bindings calling the C++ library for each language
10+
(although this is still possible for the brave). InfoLogger provides them ready to use!
11+
12+
This documentation includes a reference of the exported functions, and language-specific example code
13+
calling the infoLogger module.
14+
15+
As the C++ interface uses some complex types which can not be transparently converted to all languages,
16+
we defined this simplified API with string-only parameters.
17+
Although some overhead is added by the generalized used of strings to access the logging message structure fields
18+
(compared to the native C++ API), the performance loss is not significant for most situations. A typical machine
19+
can still log over 100000 messages per second from a script.
20+
21+
22+
23+
## Classes reference
24+
25+
Default constructor and destructor are not shown here.
26+
27+
* class InfoLogger
28+
The main class, to create a handle to the logging system. It provides the methods to inject log messages.
29+
Methods:
30+
* logInfo(string message)
31+
Sends a message with severity Info.
32+
* logError(string message)
33+
Sends a message with severity Error.
34+
* logWarning(string message)
35+
Sends a message with severity Warning.
36+
* logFatal(string message)
37+
Sends a message with severity Fatal.
38+
* logDebug(string message)
39+
Sends a message with severity Debug.
40+
* log(message)
41+
Sends a message with default severity and metadata.
42+
* log(InfoLoggerMetadata metadata, string message)
43+
Send a message with specific metadata (instead of the default, if one defined).
44+
* setDefaultMetadata(InfoLoggerMetadata metadata);
45+
Define some metadata to be used by default for all messages.
46+
* unsetDefaultMetadata();
47+
Reset the default metadata.
48+
49+
* class InfoLoggerMetadata
50+
It is used to specify extra fields associated to a log message.
51+
An object of this type can be optionnaly provided to the logging function to set some specific message fields.
52+
Methods:
53+
* setField(string key, string value)
54+
Set one of the field to a specific value. An empty value reset this field to the default.
55+
List of valid fields include: Severity, Level, ErrorCode, SourceFile, SourceLine, Facility, Role, System, Detector, Partition, Run
56+
* InfoLoggerMetadata(InfoLoggerMetadata)
57+
Copy-constructor, to copy an existing InfoLoggerMetadata object to a new one.
58+
59+
60+
61+
62+
63+
64+
## Example usage
65+
66+
Example usage is shown below. Library files listed there are available from the infoLogger library installation directory.
67+
68+
* Tcl
69+
** Library files: infoLoggerForTcl.so
70+
** Code example: (interactive interpreter from the command line)
71+
```
72+
tclsh
73+
load infoLoggerForTcl.so
74+
set logHandle [InfoLogger]
75+
$logHandle logInfo "This is a test"
76+
$logHandle logError "Something went wrong"
77+
```
78+
* Python
79+
** Library files: _infoLoggerForPython.so and infoLoggerForPython.py
80+
** Code example: (interactive interpreter from the command line)
81+
```
82+
python
83+
import infoLoggerForPython
84+
logHandle=infoLoggerForPython.InfoLogger()
85+
logHandle.logInfo("This is a test")
86+
logHandle.logError("Something went wrong")
87+
```
88+
* Go
89+
** Library files: infoLoggerForGo.a and infoLoggerForGo.go (to be copied to ${GOPATH}/src/infoLoggerForGo)
90+
** Build: CGO_LDFLAGS="${GOPATH}/src/infoLoggerForGo/infoLoggerForGo.a -lstdc++" go build
91+
** Code example:
92+
```
93+
package main
94+
import "infoLoggerForGo"
95+
func main() {
96+
var logHandle=infoLoggerForGo.NewInfoLogger()
97+
logHandle.LogInfo("This is a test")
98+
logHandle.LogError("Something went wrong")
99+
}
100+
```
101+
102+
103+
NB: don't forget to delete the objects if necessary!

0 commit comments

Comments
 (0)