How to store Mosquitto Logs to file

Asked by prasad

Hi ,

I am publishing topics to mqtt broker and showing the values in console.
I dont want show the logs on console and store them in log file.

Regards
Prasad.

Question information

Language:
English Edit question
Status:
Answered
For:
mosquitto Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Roger Light (roger.light) said :
#1

Do you mean you are using e.g. mosquitto_sub to display messages on
the console? In that case, simple redirection would work:

mosquitto_sub -t foo/bar > log_file

If you need something more complicated, you'll have to write your own
client using one of the many client libraries available.

On Wed, Jul 30, 2014 at 6:52 AM, prasad
<email address hidden> wrote:
> New question #252384 on mosquitto:
> https://answers.launchpad.net/mosquitto/+question/252384
>
> Hi ,
>
> I am publishing topics to mqtt broker and showing the values in console.
> I dont want show the logs on console and store them in log file.
>
> Regards
> Prasad.
>
> --
> You received this question notification because you are a member of
> Mosquitto PPA, which is an answer contact for mosquitto.

Revision history for this message
prasad (l-prasad64) said :
#2

Dear Roger,
I think you have misunderstood. Let me explain my scenario clearly.

I have a mosquitto broker installed in a Linux environment.
Multiple clients connect to it.
Currently the broker in the console displays the clients which are getting connected and disconnected by their IP address and client ID.
I want to capture this information in a log file so that I could audit the IP address.

I have tried to redirect the console log to a file
./mosquitto >> Log.txt
Though the file got created but no content was being written into it (the file size is also zero).
The console is still displaying the log.

I have also tried to write the log using mosquitto inbuilt logging mechanism by including mosquitto.conf.
My mosquitto.conf contains
log_dest filename path
log_type debug
connection_type true

In this case no file is being created at all.
The console is still displaying the log.

Am I doing something wrong here.
Please analyze.

-Prasad

Revision history for this message
Roger Light (roger.light) said :
#3

You have "log_dest filename path"

It should be "log_dest file <path to your log file>"

It should also give you an error about that though. Are you sure that
the user you are running the broker as has permission to create the
log file?

On Wed, Jul 30, 2014 at 11:08 AM, prasad
<email address hidden> wrote:
> Question #252384 on mosquitto changed:
> https://answers.launchpad.net/mosquitto/+question/252384
>
> Status: Answered => Open
>
> prasad is still having a problem:
> Dear Roger,
> I think you have misunderstood. Let me explain my scenario clearly.
>
> I have a mosquitto broker installed in a Linux environment.
> Multiple clients connect to it.
> Currently the broker in the console displays the clients which are getting connected and disconnected by their IP address and client ID.
> I want to capture this information in a log file so that I could audit the IP address.
>
> I have tried to redirect the console log to a file
> ./mosquitto >> Log.txt
> Though the file got created but no content was being written into it (the file size is also zero).
> The console is still displaying the log.
>
> I have also tried to write the log using mosquitto inbuilt logging mechanism by including mosquitto.conf.
> My mosquitto.conf contains
> log_dest filename path
> log_type debug
> connection_type true
>
> In this case no file is being created at all.
> The console is still displaying the log.
>
> Am I doing something wrong here.
> Please analyze.
>
> -Prasad
>
> --
> You received this question notification because you are a member of
> Mosquitto PPA, which is an answer contact for mosquitto.

Revision history for this message
prasad (l-prasad64) said :
#4

Dear Roger,

I am sure that i have permissions to my mosquitto broker.

You have mentioned about "log_dest" the path is perfect there but still there is same problem.

Revision history for this message
Roger Light (roger.light) said :
#5

You definitely use "file" not "filename"?

What version of the broker and what platform are you using?

On Wed, Jul 30, 2014 at 2:02 PM, prasad
<email address hidden> wrote:
> Question #252384 on mosquitto changed:
> https://answers.launchpad.net/mosquitto/+question/252384
>
> Status: Answered => Open
>
> prasad is still having a problem:
> Dear Roger,
>
> I am sure that i have permissions to my mosquitto broker.
>
> You have mentioned about "log_dest" the path is perfect there but still
> there is same problem.
>
> --
> You received this question notification because you are a member of
> Mosquitto PPA, which is an answer contact for mosquitto.

Revision history for this message
Mikkel Kirkgaard Nielsen (mikini) said :
#6

Hi prasad,
old question, but thought my input might still be valuable for you or anybody else listening.

If no "log_dest" configuration clauses are specified in the mosquitto configuration file(s) then log_dest will default to stderr which will normally output the log on the console/terminal as you have experienced.
If you would like to capture this you obviously need to redirect stderr. Unfortunately your use of ">> log.txt" will only redirect to stdout, not stderr.
To redirect stderr you could use either "2>> log.txt" to specifically redirect only stderr or ">> log.txt 2>&1" to redirect both stderr and stdout (usually good if you want to be sure to record as much info as possible).

Running the broker with a "log_dest file" configuration clause should also produce a log file, however I have seen the below caveats in current version 1.3.5 that to my knowledge is unaddressed at the moment making the mechanism close to unusable not to say confusing:

1) the logfile is opened at broker start, but is not flushed (written) regularly. That is only done when reloading the configuration at SIGHUP signal and server termination on SIGINT/SIGTERM.
2) if created on broker start it is done before privileges are dropped (thus as root), making it inaccessible to the later non-root broker on reload using SIGHUP (related to this issue; https://bugs.eclipse.org/bugs/show_bug.cgi?id=452914).
3) if someone (say logrotate) moves the active log file it is undetected by the broker and logging continues under the new file name (this is a great filesystem feature, but normally you'd expect logging to continue under the configured file name).

Whether the pending v1.4 fixes any of these I haven't investigated yet.

Hope this will help.
Mikkel

Can you help with this problem?

Provide an answer of your own, or ask prasad for more information if necessary.

To post a message you must log in.