Discussion:
[Gambas-user] how to log to stdout/stderr
PICCORO McKAY Lenz
2017-07-13 16:47:44 UTC
Permalink
how can i log to stdout and stderr my program actions/methods/things ?

note that due vendor/client i cannot use gambas 3.5+ only 3.4... due its
the already installed..

some time ago benoit respond me that recent version of gambas implements
something similar already,
but i cannot find the main in the horrible sourgeforce heavyweith web
interface


Lenz McKAY Gerardo (PICCORO)
http://qgqlochekone.blogspot.com
Tobias Boege
2017-07-13 18:11:25 UTC
Permalink
Post by PICCORO McKAY Lenz
how can i log to stdout and stderr my program actions/methods/things ?
note that due vendor/client i cannot use gambas 3.5+ only 3.4... due its
the already installed..
some time ago benoit respond me that recent version of gambas implements
something similar already,
but i cannot find the main in the horrible sourgeforce heavyweith web
interface
The PRINT instruction writes to stdout (by default) and the ERROR
instruction to stderr (by default). There is also DEBUG which writes
to stderr and includes the filename, function name and line number
where it is executed at the beginning of the output. It is for print-
style debugging and if you don't compile the project with gbc3's
"-g" switch the DEBUG statements will NOT be compiled, so don't do
anything in those statements which could have side effects.

You can change the default stream PRINT and ERROR/DEBUG operate on
by OUTPUT TO and ERROR TO.

Those things must have been in Gambas since forever, there is by far
no 3.x version requirement. The more sophisticated (by always broken
when I tried it, IIRC) component gb.logging was added in Gambas 3.5,
but if you just want to print to stdout and stderr, there is no reason
to use it.

Regards,
Tobi
--
"There's an old saying: Don't change anything... ever!" -- Mr. Monk
PICCORO McKAY Lenz
2017-07-13 19:39:35 UTC
Permalink
hello toby, when i set the gambas binary to backgroud to runs as daemon
...and lauch other gambas process from that gambas ...

then the stdout and stderr does not have that behaviour you said!
so then?

Lenz McKAY Gerardo (PICCORO)
http://qgqlochekone.blogspot.com
Post by Tobias Boege
Post by PICCORO McKAY Lenz
how can i log to stdout and stderr my program actions/methods/things ?
note that due vendor/client i cannot use gambas 3.5+ only 3.4... due its
the already installed..
some time ago benoit respond me that recent version of gambas implements
something similar already,
but i cannot find the main in the horrible sourgeforce heavyweith web
interface
The PRINT instruction writes to stdout (by default) and the ERROR
instruction to stderr (by default). There is also DEBUG which writes
to stderr and includes the filename, function name and line number
where it is executed at the beginning of the output. It is for print-
style debugging and if you don't compile the project with gbc3's
"-g" switch the DEBUG statements will NOT be compiled, so don't do
anything in those statements which could have side effects.
You can change the default stream PRINT and ERROR/DEBUG operate on
by OUTPUT TO and ERROR TO.
Those things must have been in Gambas since forever, there is by far
no 3.x version requirement. The more sophisticated (by always broken
when I tried it, IIRC) component gb.logging was added in Gambas 3.5,
but if you just want to print to stdout and stderr, there is no reason
to use it.
Regards,
Tobi
--
"There's an old saying: Don't change anything... ever!" -- Mr. Monk
------------------------------------------------------------
------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Gambas-user mailing list
https://lists.sourceforge.net/lists/listinfo/gambas-user
Tobias Boege
2017-07-13 20:11:00 UTC
Permalink
Post by PICCORO McKAY Lenz
hello toby, when i set the gambas binary to backgroud to runs as daemon
...and lauch other gambas process from that gambas ...
then the stdout and stderr does not have that behaviour you said!
so then?
You're wrong, it does exactly what you wanted and specifically asked about:
print to stdout and stderr.

As we discussed recently [1], stdout and stderr are redirected to /dev/null
when you daemonise, so there is not really any value in wanting to print
there if you want to make a daemon.

If you still want the output of your system daemon to arrive somewhere, you
have to point stdout and stderr to somewhere meaningful again, like your
syslog. You can also make your own log files as was discussed in [1], if you
don't have a real *system* daemon that should be integrated into the systemd
(or what have you) ecosystem. There is information available about this on
the net [2], which is completely independent of Gambas, BTW.

There's an(other) old saying: If you want a good answer you have to ask a
very good question.

Regards,
Tobi

[1] https://sourceforge.net/p/gambas/mailman/gambas-user/thread/1498036647346-59450.post%40n7.nabble.com/#msg35904830
[2] https://stackoverflow.com/questions/17954432/creating-a-daemon-in-linux
--
"There's an old saying: Don't change anything... ever!" -- Mr. Monk
PICCORO McKAY Lenz
2017-07-13 21:02:56 UTC
Permalink
ok, thanks.. that's the mail ([1])

the problem of make right answer its the languaje barrier.. in my countrie
its very spensive make a english course, and internet connection are very
slowly and spensive too

Lenz McKAY Gerardo (PICCORO)
http://qgqlochekone.blogspot.com
Post by Tobias Boege
Post by PICCORO McKAY Lenz
hello toby, when i set the gambas binary to backgroud to runs as daemon
...and lauch other gambas process from that gambas ...
then the stdout and stderr does not have that behaviour you said!
so then?
print to stdout and stderr.
As we discussed recently [1], stdout and stderr are redirected to /dev/null
when you daemonise, so there is not really any value in wanting to print
there if you want to make a daemon.
If you still want the output of your system daemon to arrive somewhere, you
have to point stdout and stderr to somewhere meaningful again, like your
syslog. You can also make your own log files as was discussed in [1], if you
don't have a real *system* daemon that should be integrated into the systemd
(or what have you) ecosystem. There is information available about this on
the net [2], which is completely independent of Gambas, BTW.
There's an(other) old saying: If you want a good answer you have to ask a
very good question.
Regards,
Tobi
[1] https://sourceforge.net/p/gambas/mailman/gambas-user/
thread/1498036647346-59450.post%40n7.nabble.com/#msg35904830
[2] https://stackoverflow.com/questions/17954432/creating-a-
daemon-in-linux
--
"There's an old saying: Don't change anything... ever!" -- Mr. Monk
------------------------------------------------------------
------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Gambas-user mailing list
https://lists.sourceforge.net/lists/listinfo/gambas-user
Fernando Cabral
2017-07-13 23:54:04 UTC
Permalink
Post by Tobias Boege
As we discussed recently [1], stdout and stderr are redirected to /dev/null
when you daemonise, so there is not really any value in wanting to print
there if you want to make a daemon.
I don't know if I have understood you correctly and completely.
I am an old timer and Linux may have changed things as compared to UNIX.
A daemon is supposed to run in the background. Typically, when you put
something to
run in the background, Unix would send the standard output to... standard
output.

Now, if you do "nohup something.gambas", standard outuput will to to
"nohup.out".
But, if you do "nohup something.gambas >x &" or "something.gambas >x",
standard output wll be sent to "x".

In any case, if you don't want to preserve any output, you should redirect
stderr and
stdout to /dev/null.

I would guess that a daemon started at startup or by cron would give the
same result.
Am I wrong?

Regards

- fernando
Post by Tobias Boege
[1] https://sourceforge.net/p/gambas/mailman/gambas-user/
thread/1498036647346-59450.post%40n7.nabble.com/#msg35904830
[2] https://stackoverflow.com/questions/17954432/creating-a-
daemon-in-linux
--
"There's an old saying: Don't change anything... ever!" -- Mr. Monk
------------------------------------------------------------
------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Gambas-user mailing list
https://lists.sourceforge.net/lists/listinfo/gambas-user
--
Fernando Cabral
Blogue: http://fernandocabral.org
Twitter: http://twitter.com/fjcabral
e-mail: ***@gmail.com
Facebook: ***@fcabral.com.br
Telegram: +55 (37) 99988-8868
Wickr ID: fernandocabral
WhatsApp: +55 (37) 99988-8868
Skype: fernandojosecabral
Telefone fixo: +55 (37) 3521-2183
Telefone celular: +55 (37) 99988-8868

Enquanto houver no mundo uma só pessoa sem casa ou sem alimentos,
nenhum político ou cientista poderá se gabar de nada.
PICCORO McKAY Lenz
2017-07-14 00:21:09 UTC
Permalink
in part you have right fernando.. but that was dicuss several time
previously.. i want to no made special commands to daemonize my app.. i
want my app are daemon by selft..

now my app are a property daemon.. and every night at 00:00 restart all
setting and starts a new day to regist people..

the log must also be manage by the application.. if not then its not a
proper daemon..

the nohup trick not always work.. for that there's the gambas redirection
print.. that's why i ask previously how i detec if are runnig inside ide..
if are inside ide. let normal print, if not, redirect...

Lenz McKAY Gerardo (PICCORO)
http://qgqlochekone.blogspot.com
Post by Tobias Boege
Post by Tobias Boege
As we discussed recently [1], stdout and stderr are redirected to
/dev/null
Post by Tobias Boege
when you daemonise, so there is not really any value in wanting to print
there if you want to make a daemon.
I don't know if I have understood you correctly and completely.
I am an old timer and Linux may have changed things as compared to UNIX.
A daemon is supposed to run in the background. Typically, when you put
something to
run in the background, Unix would send the standard output to... standard
output.
Now, if you do "nohup something.gambas", standard outuput will to to
"nohup.out".
But, if you do "nohup something.gambas >x &" or "something.gambas >x",
standard output wll be sent to "x".
In any case, if you don't want to preserve any output, you should redirect
stderr and
stdout to /dev/null.
I would guess that a daemon started at startup or by cron would give the
same result.
Am I wrong?
Regards
- fernando
Post by Tobias Boege
[1] https://sourceforge.net/p/gambas/mailman/gambas-user/
thread/1498036647346-59450.post%40n7.nabble.com/#msg35904830
[2] https://stackoverflow.com/questions/17954432/creating-a-
daemon-in-linux
--
"There's an old saying: Don't change anything... ever!" -- Mr. Monk
------------------------------------------------------------
------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Gambas-user mailing list
https://lists.sourceforge.net/lists/listinfo/gambas-user
--
Fernando Cabral
Blogue: http://fernandocabral.org
Twitter: http://twitter.com/fjcabral
Telegram: +55 (37) 99988-8868
Wickr ID: fernandocabral
WhatsApp: +55 (37) 99988-8868
Skype: fernandojosecabral
Telefone fixo: +55 (37) 3521-2183
Telefone celular: +55 (37) 99988-8868
Enquanto houver no mundo uma só pessoa sem casa ou sem alimentos,
nenhum político ou cientista poderá se gabar de nada.
------------------------------------------------------------
------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Gambas-user mailing list
https://lists.sourceforge.net/lists/listinfo/gambas-user
Fernando Cabral
2017-07-14 00:54:57 UTC
Permalink
Post by PICCORO McKAY Lenz
the nohup trick not always work.. for that there's the gambas redirection
print.. that's why i ask previously how i detec if are runnig inside ide..
if are inside ide. let normal print, if not, redirect...
I am not sure I have understood what you said. What I can say is that, for
logging purpose, you can just open a regular file and then write to or
append to.

In order to determine if your application is running as a daemon or not, if
can be quite easy and fool proof. For intance, you can create a command
line options like, say "-d". If it is present, your applicaiton should run
as a daemon, so you act accordingly. Otherwise the application is not
running as daemon, so you should act as a regular application.

As to printing (if you mean, printing to a printer proper) you can either
open a pipe to the printer daemon or else create a file and then use a
shell () instruction to print and delete that file. Both should work well.

- fernando
Post by PICCORO McKAY Lenz
Lenz McKAY Gerardo (PICCORO)
http://qgqlochekone.blogspot.com
Post by Tobias Boege
Post by Tobias Boege
As we discussed recently [1], stdout and stderr are redirected to
/dev/null
Post by Tobias Boege
when you daemonise, so there is not really any value in wanting to
print
Post by Tobias Boege
Post by Tobias Boege
there if you want to make a daemon.
I don't know if I have understood you correctly and completely.
I am an old timer and Linux may have changed things as compared to UNIX.
A daemon is supposed to run in the background. Typically, when you put
something to
run in the background, Unix would send the standard output to... standard
output.
Now, if you do "nohup something.gambas", standard outuput will to to
"nohup.out".
But, if you do "nohup something.gambas >x &" or "something.gambas >x",
standard output wll be sent to "x".
In any case, if you don't want to preserve any output, you should
redirect
Post by Tobias Boege
stderr and
stdout to /dev/null.
I would guess that a daemon started at startup or by cron would give the
same result.
Am I wrong?
Regards
- fernando
Post by Tobias Boege
[1] https://sourceforge.net/p/gambas/mailman/gambas-user/
thread/1498036647346-59450.post%40n7.nabble.com/#msg35904830
[2] https://stackoverflow.com/questions/17954432/creating-a-
daemon-in-linux
--
"There's an old saying: Don't change anything... ever!" -- Mr. Monk
------------------------------------------------------------
------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Gambas-user mailing list
https://lists.sourceforge.net/lists/listinfo/gambas-user
--
Fernando Cabral
Blogue: http://fernandocabral.org
Twitter: http://twitter.com/fjcabral
Telegram: +55 (37) 99988-8868
Wickr ID: fernandocabral
WhatsApp: +55 (37) 99988-8868
Skype: fernandojosecabral
Telefone fixo: +55 (37) 3521-2183
Telefone celular: +55 (37) 99988-8868
Enquanto houver no mundo uma só pessoa sem casa ou sem alimentos,
nenhum político ou cientista poderá se gabar de nada.
------------------------------------------------------------
------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Gambas-user mailing list
https://lists.sourceforge.net/lists/listinfo/gambas-user
------------------------------------------------------------
------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Gambas-user mailing list
https://lists.sourceforge.net/lists/listinfo/gambas-user
--
Fernando Cabral
Blogue: http://fernandocabral.org
Twitter: http://twitter.com/fjcabral
e-mail: ***@gmail.com
Facebook: ***@fcabral.com.br
Telegram: +55 (37) 99988-8868
Wickr ID: fernandocabral
WhatsApp: +55 (37) 99988-8868
Skype: fernandojosecabral
Telefone fixo: +55 (37) 3521-2183
Telefone celular: +55 (37) 99988-8868

Enquanto houver no mundo uma só pessoa sem casa ou sem alimentos,
nenhum político ou cientista poderá se gabar de nada.
Loading...