Instant Messaging using erlang and XMPP — Part 4

Sep 16, 2021

Note: When I started writing this, I was using customized mongooseim version 3.7.1, now latest updates using TOML config and such have come up as on July 2021. So, if you want to refer to the latest documentation, feel free to read it here .

Important files and hierarchies

Last part, we saw how a stanza is represented in Erlang Terms (erlang records). This part we’ll be seeing the important files and how they fit into the functioning of MongooseIM.

Folder Hierarchy

# Some of the directories and files have been left out for convenience
/mongooseim-src
├── asn1
├── asngen
├── big_tests
├── c_src
├── examples
├── include
├── priv
├── rel
├── src
├── test
└── tools

10 directories

As a developer, we’ll only need to modify certain folders or files in order to achieve a certain functionality such as

include/mongoose_logger.hrl

Erlang developers already know about io:format(arg1, arg2) method to display or inspect values in the erlang shell and also we will be tempted to use the same here. There is no harm in doing it, but we will be bypassing the log from the mongooseim’s configured logger module, which might result in our debug statements left out from the corresponding log files.

The header file contains macros to make your life easier in including debug statements. You want to add a debug log in a source file, include this header file somewhere along after module statement in the source file as -include("mongoose_logger.hrl").

Now you can simply add a debug statement, which will be shown in the mongooseim console output when the application is running. Simple example of a debug statement is as follows:

# without variables
?DEBUG("Hello this is a sample debug message!~n", []),
...
# Console Output
16:25:02.374 [debug] Hello this is a sample debug message!
# with variables
Author = "Jonas",
?DEBUG("Hello this is a sample debug message! Welcome ~p~n", [Author]),
...
# Console Output
16:25:02.374 [debug] Hello this is a sample debug message! Welcome Jonas

You don’t have to explicitly import this header file, instead if you include the include/mongoose.hrl file, it already has included the mongoose_logger.hrl file.

include/mongoose_ns.hrl

The ns stands for namespace which is relevant to the XML stanzas. This file holds all of supported namespaces for our XML stanzas and we can also define our custom namespaces here and use them anywhere in the source files. Any source file in mongooseim you see, they would have this file inclusion.

With this covered, let’s get on with understanding hooks and handlers in the coming parts.


   erlang (8) , mongooseim (4) , ejabberd (4) , xmpp (4) , instant-messaging (4)