Home > Domino Tips > Developer > Permanent NotesLog and Java log come in handy
Domino Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

LOTUSSCRIPT

Permanent NotesLog and Java log come in handy


Chuck Connell
03.02.2005
Rating: -4.43- (out of 5)


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


Keywords: Notes, Domino, LotusScript, Java, error, log, NotesLog
Technical Level: Advanced

I have written before about proper error handling within LotusScript code (part 1: "Check those LotusScript errors!" and part 2: "LotusScript error handling"). I am even speaking on this topic at the upcoming Admin2005 conference in Boston.

A particularly useful feature of LotusScript error handling, which I have not addressed, until now, is the NotesLog class. The NotesLog object allows you to create robust permanent error logs from LotusScript programs. And, there is a matching Java class named Log.

So why is this of interest to administrators, as well as programmers? When you run Notes code interactively at a workstation, as a rule you are not concerned about a permanent log of the session. If you get an error report on the screen, you just fix the problem and then run the code again. But suppose you are administering a Domino server with nightly agents. When you arrive at the office in the morning, the first thing you want to do (after you get your hazelnut mochaccino) is find out whether your nightly agents ran correctly.

If your LotusScript code contains simple print statements to report errors, you have to search the Domino server log looking for these messages. The NotesLog class provides a much better way of recording error and status messages from agents. You can designate that each agent writes to its own log file, or that several agents share the same log.

Below is a sample LotusScript program that uses the NotesLog class, followed by some detailed comments about the code.

1) Sub Initialize
2)  
3) Const NAME_VIEW = "AllByName"
4) Const INFO_FIELD = "Info"
5) Const SEARCH_STRING =
 "Tim Lewis"
6) Const LOG_ID = "Log Test"       
' the name of this log stream
7) Const LOG_SERVER = ""     
   'local machine for now
8) Const LOG_FILE = "
C:\Notes6\Logs\
MyErrors.nsf" 'from 
ALOG4.NTF, must use full path
9) Const GENERAL_ERROR = 1001
10)
11) Dim Sess As NotesSession
12) Dim ThisDb As NotesDatabase
13) Dim NameView As NotesView
14) Dim Doc As NotesDocument
15) Dim ErrorLog As NotesLog
16) Dim Information  As String
17) 
18) On Error Goto ErrorReturn
19)
20) Set Sess = New NotesSession
21) Set ThisDb = Sess.CurrentDatabase
22)
23) Set ErrorLog = New NotesLog
(LOG_ID)
24) Call ErrorLog.OpenNotesLog
(LOG_SERVER, LOG_FILE)
25) Call ErrorLog.LogAction ("Successfully 
opened log database.")
26) 
27) Set NameView = ThisDb.GetView (NAME_VIEW)
28) If NameView Is Nothing Then Error
 GENERAL_ERROR, "Unable to open view " + 
NAME_VIEW + "."
29) 
30) Set Doc = NameView.GetDocumentByKey 
(SEARCH_STRING)
31) If Doc Is Nothing Then Error 
GENERAL_ERROR, "Cannot find " + 
SEARCH_STRING 
+ "."
32) 
33) Information  = Doc.GetItemValue
(INFO_FIELD)(0)        
34) Information = Trim$(Information)
35) If Information = "" 
Then Error GENERAL_ERROR, "Info for " +
 SEARCH_STRING 
+ " was empty."
36) 
37) Call ErrorLog.LogAction
 ("The information field is " + Information + ".")
38) 
39) NormalReturn:
40) Call ErrorLog.LogAction 
("Program finished with no errors.")
41) Call ErrorLog.Close
43) Exit Sub
43) 
44) ErrorReturn:
45) Call ErrorLog.LogError(Err, "Err Msg: " 
+ Error$ + ". Near line: " + Cstr
(Erl) + ".")
46) Call ErrorLog.Close
47) Resume ErrorReturn2
48) ErrorReturn2:
49) Exit Sub
50)  
51) End Sub

Line 23 creates the NotesLog object, giving it a name taken from line 6. This name is not the filename of the log, but a separate convenient identifier.

Line 24 associates the NotesLog object with a Notes database that will receive the log messages. The database must exist first and should normally be created from the ALOG4.NTF template.

Line 25 makes the first use of the newly opened log database, calling the LogAction method to write a simple status message to the log.

Line 28 invokes an error handling routine if the designated view cannot be opened. The error handler, lines 44 to 49, shows two other methods from the NotesLog class. LogError writes an error message to the log. The first argument to LogError is the error code for the error, and the second argument is any string you want. The error code is included because it is displayed conveniently in the views of the ALOG4 template. The Close method completes the NotesLog stream before the subroutine exits.

Lines 31 and 35 show additional calls to the error handling routine, and lines 40 and 41 show how the log is used during successful program termination.

Bonus question for readers: Why have I included a Resume statement at line 47, which simply transfers control to line 48? One hour of free consulting to the first person with the right answer. (Answers to bonus@chc-3.com.)

For more information, see Domino Designer 6 Help / Index / NotesLog.

Chuck Connell is president of CHC-3 Consulting, which helps organizations with all aspects of Lotus Domino and Notes, including software development, security and system management.

Do you have comments on this tip? Let us know.

Please let others know how useful it is via the rating scale below. Do you have a useful Notes/Domino tip or code to share? Submit it to our monthly tip contest and you could win a prize and a spot in our Hall of Fame.

Rate this Tip
To rate tips, you must be a member of SearchDomino.com.
Register now to start rating these tips. Log in if you are already a member.


Submit a Tip




Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


RELATED CONTENT
Domino
Mimic Lotus Notes Domino application functionality on the Web
A single form to view and edit any Lotus Notes document
DECS and DCR external data access considerations
How to create non-scrolling Lotus Domino view headers on the Web
Disabling the 'Submit' button on a form
An easier way to update a rich text field
Results from Default Notes Search have # of responses in brackets
Lotus Notes/Domino veteran offers comprehensive list of app dev tools
Notes to XML. . .and back again
Creating thumbnail images using LS2J in LotusScript

Java
How to execute a stored procedure in Lotus Notes Domino using Java
How to return an HTML representation of a Lotus Notes rich-text field
Shrink Lotus Notes databases with many attachments
Converting Lotus Notes Domino Web pages to PDF files with a Java agent
A bevy of Notes/Domino development tips
Converting Web pages to images using Java
Creating Microsoft Word documents from Lotus Notes
FAQ: Java for Lotus Notes and Domino
Automatically scan Lotus Notes database document attachments for viruses
Creating PDF documents from Lotus Notes

LotusScript
Reading a binary field in an Oracle database with LotusScript
LotusScript equivalent of @Picklist for Lotus Notes
Launch large attachments within an email from a Notes database
How to find files on a hard drive or mapped network with LotusScript
Update the ACL from the Roles view with LotusScript
LotusScript agent moves tagged spam email to junk mail folder
Create a personalized greeting for Lotus Notes database users
Fail-safe rich-text validation using LotusScript
How to export Lotus Notes views to a Microsoft Excel database
Create file system labels for Microsoft Excel and Word mail merges

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary

DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.

HomeNewsTopicsITKnowledge ExchangeTipsAsk the ExpertsMultimediaWhite PapersDomino IT Downloads
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides enterprise IT professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective IT purchase decisions and managing their organizations' IT projects - with its network of technology-specific Web sites, events and magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Reprints  |  Site Map




All Rights Reserved, Copyright 1999 - 2008, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts