ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/Logger.py
Revision: 1.1
Committed: Tue Aug 30 17:05:59 2005 UTC (19 years, 8 months ago) by corvo
Content type: text/x-python
Branch: MAIN
CVS Tags: CRAB_1_0_4, CRAB_1_0_3, CRAB_1_0_2, CRAB_0_2_2, CRAB_1_0_1, CRAB_1_0_0_rc1, CRAB_1_0_0_beta4, CRAB_1_0_0_pre1_boss_2, CRAB_1_0_0_pre1_boss
Log Message:
Integration with Monalisa monitoring

File Contents

# User Rev Content
1 corvo 1.1
2     """
3     * ApMon - Application Monitoring Tool
4     * Version: 2.0.4
5     *
6     * Copyright (C) 2005 California Institute of Technology
7     *
8     * Permission is hereby granted, free of charge, to use, copy and modify
9     * this software and its documentation (the "Software") for any
10     * purpose, provided that existing copyright notices are retained in
11     * all copies and that this notice is included verbatim in any distributions
12     * or substantial portions of the Software.
13     * This software is a part of the MonALISA framework (http://monalisa.cacr.caltech.edu).
14     * Users of the Software are asked to feed back problems, benefits,
15     * and/or suggestions about the software to the MonALISA Development Team
16     * (developers@monalisa.cern.ch). Support for this software - fixing of bugs,
17     * incorporation of new features - is done on a best effort basis. All bug
18     * fixes and enhancements will be made available under the same terms and
19     * conditions as the original software,
20    
21     * IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY PARTY FOR
22     * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
23     * OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ANY DERIVATIVES THEREOF,
24     * EVEN IF THE AUTHORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25    
26     * THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES,
27     * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
28     * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. THIS SOFTWARE IS
29     * PROVIDED ON AN "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO
30     * OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR
31     * MODIFICATIONS.
32     """
33    
34     import time
35     import threading
36    
37     FATAL = 0 # When something very bad happened and we should quit
38     ERROR = 1 # Tipically when something important fails
39     WARNING = 2 # Intermediate logging level.
40     INFO = 3 # Intermediate logging level.
41     NOTICE = 4 # Logging level with detailed information.
42     DEBUG = 5 # Logging level for debugging
43    
44     LEVELS = ['FATAL', 'ERROR', 'WARNING', 'INFO', 'NOTICE', 'DEBUG']
45    
46     # Simple logging class
47     class Logger:
48     # Constructor
49     def __init__ (this, defaultLevel = INFO):
50     this.log_lock = threading.Lock();
51     this.logLevel = defaultLevel
52    
53     # Print the given message if the level is more serious as the existing one
54     def log(this, level, message):
55     global LEVELS, FATAL, ERROR, WARNING, INFO, NOTICE, DEBUG
56     this.log_lock.acquire();
57     if(level <= this.logLevel):
58     print time.asctime() + ": ApMon["+LEVELS[level]+"]: "+message;
59     this.log_lock.release();
60    
61     # Set the logging level
62     def setLogLevel(this, strLevel):
63     this.log_lock.acquire();
64     for l_idx in range(len(LEVELS)):
65     if strLevel == LEVELS[l_idx]:
66     this.logLevel = l_idx;
67     this.log_lock.release();
68