we are making some loging issue, where we need write the logentries in the DB. But the process run in a transaction and by rollback are our new logentries also deleted. can I make a write in DB out of the transaction? something like write in temptable with NO-UNDO option...? that the new logentries still remain in DB...?
-
Windows or Unix? How structured is the table you need to write these log entries to (how many columns)? – Abe Voelker Aug 15 '12 at 14:39
6 Answers
Another possibility would be to use an app server. Transactions on app server sessions are independent from transactions in the original session (that's what the optional and redundant "DISTINCT TRANSACTION" syntax is all about).

- 13,405
- 2
- 27
- 33
-
it run not always with app server. the applicaton must running also without it. but thanx for answer. – firhang Aug 16 '12 at 15:45
Another option would be to use a simple messaging system. One very easy to setup and use option is STOMP. It is platform neutral and very easy to get going with.
Julian Lyndon-Smith posted the following on PEG about a month ago, and it really is as easy to setup and use as he says (I've tried it, I used ApacheMQ which is also very easy to setup and use):
Following on from presentations in Boston and Finland, dot.r is pleased to announce the open source Stomp project, available immediately.
Download from either http://www.dotr.com or https://bitbucket.org/jmls/stomp , the dot.r stomp programs allow you to connect your progress session to any other application or service that is connected to the same message broker.
Open source, free message brokers that support Stomp are:
Fuse
(http://fusesource.com/products/fuse-mq-enterprise/) [a Progress company now owned by Red Hat inc] Fuse MQ Enterprise is a standards-based, open source messaging platform that deploys with a very small footprint. The lack of license fees combined with high-performance, reliable messaging that can be used with any development environment provides a solution that supports integration everywhere
ActiveMQ
Apache ActiveMQ (tm) (http://activemq.apache.org/)is the most popular and powerful open source messaging and Integration Patterns server. Apache ActiveMQ is fast, supports many Cross Language Clients and Protocols, comes with easy to use Enterprise Integration Patterns and many advanced features while fully supporting JMS 1.1 and J2EE 1.4.
Apache ActiveMQ is released under the Apache 2.0 License.
RabbitMQ
RabbitMQ is a message broker. The principal idea is pretty simple: it accepts and forwards messages. You can think about it as a post office: when you send mail to the post box you're pretty sure that Mr. Postman will eventually deliver the mail to your recipient. Using this metaphor RabbitMQ is a post box, a post office and a postman.
The major difference between RabbitMQ and the post office is the fact that it doesn't deal with paper, instead it accepts, stores and forwards binary blobs of data - messages.
Please feel free to log any issues on the https://bitbucket.org/jmls/stomp issue system, and fork the project in order to commit back all those new features that you are going to add ...
dot.r Stomp uses the permissive MIT licence (http://en.wikipedia.org/wiki/MIT_License)
Have fun, enjoy !
Julian

- 13,405
- 2
- 27
- 33
Every change to the database must be part of a transaction. If you do not explicitly start one it will be implicitly started for you and scoped to the next outer block with transaction capabilities.
However and although I would not recommend you to, work with sub-transactions. You can invoke a sub transaction by explicitly specifying a DO TRANSACTION within the transaction scope. Although the database will never know about it, the client can roll back the sub transaction while the database can commit the transaction.
But in order to implement something like this you must master the concepts of transaction scope, block behavior and error handling.
RealHeavyDude.

- 66
- 2
-
we are working with subtransaction and DO TRANSACTION blocks. I have read the document about transactions (ABL Essentials - Managing Transactions), but I have seen nothing about exceptions from running transaction... It is with high probability not possible :(... – firhang Aug 15 '12 at 10:26
-
Sub-transaction is not a widely used concept in the ABL. Usually it happens accidentally and if it is detected by the compiler (within the same code block) it will even issue a warning although it will compile it. To be clear: The database only knows about the outer most transaction - THE TRANSACTION, it is completely oblivious to sub-transactions. Nevertheless, every DO TRANSACTION statement within an already active transaction causes a sub-transaction handled by the client session. It can be undone by the client but when the outer transaction is rolled back - so are all sub-transactions. – RealHeavyDude Aug 15 '12 at 10:33
Write your log entries to a no-undo temp-table. When the code will commit a transaction, or transactions aren't active (transactionID = ?) have your code write the log entries out.

- 3,201
- 1
- 17
- 23
-
I'm writing log entries in NO-UNDO temptable. It will copied sometime from this temptable to other temptable. But problem is, when I wait to end of transaction, can the system crash and give no chance to write in DB. – firhang Aug 15 '12 at 15:19
-
Yes, although if your system is _that_ unstable I'd be more concerned about the crashes than missing some log entries. The only way around that is to write to an external file, or publish to an external service (ala STOMP). If you write to a file, each user / session needs to write to it's own file in order to avoid data collisions. – Tim Kuehn Aug 15 '12 at 20:22
-
I don't think there is any way to do this in ABL as you planned either efficiently (sprinkling temp-table flushes or other tidbits all over the place is gross) or reliably (what if the application crashes with an un-flushed temp-table?), as others have mentioned. I would suggest making your complicated logging less coupled to your app by making the database writes asynchronous, occurring outside of your application if possible.
Since you're on Windows, you could change your logging to use the .NET log4net library instead of ABL constructs. log4net has a few appenders that would be useful:
- AdoNetAppender which lets you log directly to a database
- RemoteSyslogAppender which uses the syslog protocol, letting you log to an external Unix syslog or rsyslog daemon (rsyslog supports writing log messages to databases)
- UDPAppender which sends the log messages via UDP packets somewhere else to be handled (e.g. a logFaces server, which supports writing to databases)
If you must do it in ABL then you could use a named output stream specifically for your log messages (OUTPUT TO STREAM
) which writes to a specific location where an external process is listening to handle it. This file could be a pipe created by something like mkfifo
or just a regular text file that is monitored for changes with inotify
(not sure what the Windows equivalents of these are). This external process would handle parsing the messages and writing them to the database (basically re-inventing rsyslog).

- 30,124
- 14
- 81
- 98
-
we are using progress 10.2B and it support no .NET on app server. thanx for answer. for future is it good idea :) – firhang Aug 16 '12 at 15:50
-
Sure. I still think the best way in ABL would be to use some form of IPC to communicate with an external process. Perhaps create a logging class as a facade to hide all complication behind, which would also let you tee your logging to as many places as you want when you initialize it. 0MQ would be a perfect thing to use here for the IPC communication, but from my experiments a while back the AVM chokes on it. I guess you can use ActiveMQ/Stomp but I think that's way too much overhead unless you're implementing an entire centralized logging server. I'd just use a named pipe for your scenario. – Abe Voelker Aug 16 '12 at 18:57
I like the no-undo temp-table idea, just be sure to put the database write part in a "FINALLY" block in case of unhandled exceptions.

- 11
- 3
-
when the application shot down, will the finally block already for nothing. it must write the messages by runnig from process. – firhang Aug 16 '12 at 15:48