"Availability of a system is typically measured as a factor of its reliability – as reliability increases, so does availability." (Wikipedia)
Availability is very important when trying to create a reliable system. But, how do we offer that kind of system and how can we create/provide something that makes us feel confortable?
Logging your program is an important task when you're developing an app because it allows you to know more about the behavior and performance of your app. That way, you can build fixes and execute decisions whenever you find bugs in your product.
Nowdays checking log results is very difficult because logs typically reside either within a server, a virtualization, a virtual server, or a cloud service.
Lonline allows you to log your program into the cloud and is powered by the Dynamicloud service. Cloud-based logging avoids server access and disk usage. Lonline provides 6 levels of logging and 2 methods of executing reports. Its Dynamicloud service facilitates data storage and access. Furthermore, Lonline allows you to set more features, and thus track more than just text, level, and program traces.
In this guide, I will cover the following content:
Lonline has one dependendency: Dynamicloud Nodejs API
Dynamicloud also provides APIs for Java and Ruby language, so you can use Lonline in Java or Ruby programs.
You can install this module in your system using the Node Package Manager (npm) command:
npm install lonline
Lonline needs basic settings to be configured. These settings are within a "Settings" file that comes with the Lonline package.
These are the settings of Lonline:
1/**
2 * Options Documentation:
3 */
4var ops = {
5 //OPTIONAL: This is the current logger object you're using in your program.
6 //Lonline will call the same function in legacy object, for example:
7 //lonlineLogger.error("It couldn't process the data");
8 // The line above will execute the method error from legacy object passing the log
9 // and the error as follow: legacyObject.error(log, error);
10 legacy: myOwnLogger
11 //OPTIONAL: This attribute indicates the path to load the settings, if this attribute is present all the
12 //below attributes will be skipped.
13 //This file must be a compatible json file.
14 fileName: '../setting.json',
15 //This attribute indicates the level of lonline
16 //The following table is an explanation of levels in Lonline (Descriptions from the great Java Log4j library):
17 //------------------------------------------------------------------------------------------------------------
18 //| Level | Activated levels | Description |
19 //------------------------------------------------------------------------------------------------------------
20 //| fatal | Fatal | Designates very severe error events that will presumably lead |
21 //| | | the application to abort. |
22 //------------------------------------------------------------------------------------------------------------
23 //| error | Fatal, Error | Designates error events that might still allow the application |
24 //| | | to continue running. |
25 //------------------------------------------------------------------------------------------------------------
26 //| warn | Fatal, Error, Warn | Designates potentially harmful situations. |
27 //------------------------------------------------------------------------------------------------------------
28 //| info | Fatal, Error, Warn, Info | Designates informational messages that highlight the progress |
29 //| | | of the application at coarse-grained level. |
30 //------------------------------------------------------------------------------------------------------------
31 //| debug | Fatal, Error, Info, Warn | Designates fine-grained informational events that are most |
32 //| | Debug | useful to debug an application. |
33 //------------------------------------------------------------------------------------------------------------
34 //| trace | All levels | Traces the code execution between methods, lines, etc. |
35 //------------------------------------------------------------------------------------------------------------
36 //| off | None | The highest possible rank and is intended to turn off logging. |
37 //------------------------------------------------------------------------------------------------------------
38 level: 'error',
39 //Credentials for REST APIs
40 //Go to https://www.dynamicloud.org/manage and get the API keys available in your profile
41 //If you don't have an account in Dynamicloud, visit https://www.dynamicloud.org/signupform
42 //You can easily use a social network to sign up
43 csk: 'csk#...',
44 aci: 'aci#...',
45 //This is the model identifier for test and development environment
46 //The model contains the structure to store logs into the cloud
47 //For more information about models in Dynamicloud visit https://www.dynamicloud.org/documents/mfdoc
48 modelIdentifier: 000,
49 //OPTIONAL: Shows every warning like rejected request from Dynamicloud and other warnings in lonline
50 warning: true,
51 //OPTIONAL: report_limit indicates how many records lonline will execute to fetch data from Dynamicloud.
52 //If you need to increase this value, please think about the available requests per month in your account.
53 //Dynamicloud uses a limit of records per request, at this time the max records per request is 20. So,
54 //report_limit=100 are 5 request.
55 reportLimit: 100,
56 //Send the backtrace (the ordered method calls) of the log. If you want to avoid this sets to false
57 backtrace: true,
58};
Lonline allows you to put the settings into a file. The file's path must be passed through the attribute fileName
.
1//OPTIONAL: This attribute indicates the path to load the settings, if this attribute is present all the
2//below attributes will be skipped.
3//This file must be a compatible json file.
4fileName: "../settings.json";
settings.json
1{
2 "csk": "csk#...",
3 "aci": "aci#...",
4 "modelIdentifier": 000,
5 "backtrace": true,
6 "level": "trace"
7}
Lonline needs API credentials from a Dynamicloud account. These credentials allow Lonline to access your account's structure (Model). The mandatory model in your account should be composed for a model with at least three fields. For further information about models and fields in Dynamicloud, visit its documentation at Models & Fields
*Let's set up your account in Dynamicloud. Don't worry, it is very easy:**
a. Fields:
Field identifier | Field label | Field comments | Field type | Is a required field in form? |
---|---|---|---|---|
lonlinetext | Log text | Contains the trace of this log | Textarea | Yes |
lonlinelevel | Log level | Contains the log level | Combobox | Yes |
lonlinetrace | Complete Trace | Contains the complete trace of the log | Textarea | No |
b. lonlinelevel
is a combobox. You need to add the following options:
Value | Text |
---|---|
fatal | Fatal |
error | Error |
warn | Warn |
info | Info |
debug | Debug |
trace | Trace |
To add these options follow the steps below:
lonlinelevel
c. Add model
A model is the container of these fields. To add a model:
settings.json
file.1{
2 "modelIdentifier": "Enter_Model_Id"
3}
settings.json
file.settings.json
file.1{
2 "csk": "Enter_Client_Secret_Key",
3 "aci": "Enter_API_Client_Id"
4}
At this moment you can start to log your program into the cloud.
Lonline is easy to use; one line of code logs and stores into the cloud.
1var lonline = require("lonline");
2var logger = lonline.getLogger({ fileName: "settings.json" });
3
4logger.trace("Calling method Y");
5logger.debug("Creating new object");
6logger.info("Process has finished");
7logger.warn("It could'n create this object, the process will try later.");
8logger.error("Unable to load setting file");
9logger.fatal("The app has crashed and its state is unavailable");
Lonline allows you to log additional data. If you want to log more information (for example, whether the module in your application has executed the log), just pass a LonlineLog object with the corresponding attributes and values. Remember that these additional attributes must match with the fields in your model, so you need to add these fields to the model before logging.
To log additional information, follow the code below:
1var lonline = require("lonline");
2var logger = lonline.getLogger({ fileName: "settings.json" });
3
4logger.trace("Calling method Y", null /*This is the error object*/, {
5 module: "financialModule"
6});
Lonline allows you to execute reports about the executed logs and count how many logs have been created so far.
1var lonline = require('lonline');
2
3var today = new Date();
4
5var fromDate = new Date(today.getFullYear(), today.getMonth() - 1, today.getDate(), 0, 0, 1, 0);
6var tomorrow = new Date(today.getFullYear(), today.getMonth(), today.getDate() + 1, 23, 59, 59, 0);
7
8var reporter = lonline.getReporter({fileName: './settings.json'});
9reporter.fetch(reporter.ERROR, new Date(), new Date(), function(logs) {
10 _.each(logs, function(log) {
11 console.log(log['lonlinelevel']);
12 console.log(log['lonlinetext']);
13 console.log(log['lonlinetrace']);
14 console.log(log['module']);
15 .
16 .
17 .
18 .
19 });
20});
21
22reporter.count(reporter.FATAL, fromDate, tomorrow, function (count) {
23 console.log(count > 0);
24});
Below are some common problems that arise when you configure Lonline
setting.json
file in the wrong Dynamicloud ModelId.setting.json
file contains the wrong CSK and ACI from Dynamicloud. These are the credentials to gain access to the service, so they need to be authentic.Dynamicloud has a Contact form online in case you need additional troubleshooting. See the Dynamicloud contact form.
Hopefully this guide helps you raise app efficiency through the Lonline logging method. If you found this tutorial informative, don't hesitate to hit the like button. Please leave all feedback in the comments section!