1 56 package org.opencrx.kernel.log; 57 58 import java.util.Properties ; 59 60 import org.openmdx.application.Dependencies; 61 import org.openmdx.kernel.exception.VersionMismatchException; 62 import org.openmdx.kernel.log.Config; 63 import org.openmdx.kernel.log.LogLevel; 64 import org.openmdx.kernel.log.SysLog; 65 import org.openmdx.kernel.log.impl.Log; 66 67 public class AuditLog extends Log { 68 69 private AuditLog() {} 70 71 77 public static void setConfigName( 78 String cfgName 79 ) { 80 if (!initialized) { 81 if (cfgName == null) return; cfgName = cfgName.trim(); 83 if (cfgName.length()==0) return; AuditLog.configName = cfgName; 85 }else{ 86 SysLog.error("A config name must be set before any logging " + 87 "takes place", new Exception ()); 88 } 89 } 90 91 123 public static void setLogSource( 124 Object logSource 125 ) { 126 if (logSource == null) return; 127 AuditLog.logSource = logSource; 128 } 129 130 136 public static void setLogProperties( 137 Properties props 138 ) { 139 if (!initialized) { 142 AuditLog.logProperties = props; 143 } else{ 144 SysLog.error("Log properties must be set before any logging " + 145 "takes place", new Exception ()); 146 } 147 } 148 149 154 public static Config getLogConfig( 155 ) { 156 if (!initialized) init(); 157 return new Config(singleton.getConfig()); 158 } 159 160 179 public static boolean isTraceOn( 180 ) { 181 if (!initialized) init(); 182 return (singleton.getLoggingLevel() >= LogLevel.LOG_LEVEL_TRACE); 183 } 184 185 201 public static void criticalError( 202 String logString, 203 Object logObj 204 ) { 205 if (!initialized) init(); 206 207 if (LogLevel.LOG_LEVEL_CRITICAL_ERROR <= singleton.getLoggingLevel()) { 208 singleton.logString( 209 AuditLog.logSource, 210 logString, 211 logObj, 212 LogLevel.LOG_LEVEL_CRITICAL_ERROR, 213 0); 214 } 215 } 216 217 233 public static void error( 234 String logString, 235 Object logObj 236 ) { 237 if (!initialized) init(); 238 if (LogLevel.LOG_LEVEL_ERROR <= singleton.getLoggingLevel()) { 239 singleton.logString( 240 AuditLog.logSource, 241 logString, 242 logObj, 243 LogLevel.LOG_LEVEL_ERROR, 244 0); 245 } 246 } 247 248 258 public static void error( 259 String logString 260 ) { 261 if (!initialized) init(); 262 if (LogLevel.LOG_LEVEL_ERROR <= singleton.getLoggingLevel()) { 263 singleton.logString( 264 AuditLog.logSource, 265 logString, 266 null, 267 LogLevel.LOG_LEVEL_ERROR, 268 0); 269 } 270 } 271 272 291 public static void error( 292 String logString, 293 Object logObj, 294 int callStackOff 295 ) { 296 if (!initialized) init(); 297 if (LogLevel.LOG_LEVEL_ERROR <= singleton.getLoggingLevel()) { 298 singleton.logString( 299 AuditLog.logSource, 300 logString, 301 logObj, 302 LogLevel.LOG_LEVEL_ERROR, 303 callStackOff); 304 } 305 } 306 307 323 public static void warning( 324 String logString, 325 Object logObj 326 ) { 327 if (!initialized) init(); 328 if (LogLevel.LOG_LEVEL_WARNING <= singleton.getLoggingLevel()) { 329 singleton.logString( 330 AuditLog.logSource, 331 logString, 332 logObj, 333 LogLevel.LOG_LEVEL_WARNING, 334 0); 335 } 336 } 337 338 348 public static void warning( 349 String logString 350 ) { 351 if (!initialized) init(); 352 if (LogLevel.LOG_LEVEL_WARNING <= singleton.getLoggingLevel()) { 353 singleton.logString( 354 AuditLog.logSource, 355 logString, 356 null, 357 LogLevel.LOG_LEVEL_WARNING, 358 0); 359 } 360 } 361 362 381 public static void warning( 382 String logString, 383 Object logObj, 384 int callStackOff 385 ) { 386 if (!initialized) init(); 387 if (LogLevel.LOG_LEVEL_WARNING <= singleton.getLoggingLevel()) { 388 singleton.logString( 389 AuditLog.logSource, 390 logString, 391 logObj, 392 LogLevel.LOG_LEVEL_WARNING, 393 callStackOff); 394 } 395 } 396 397 413 public static void info( 414 String logString, 415 Object logObj 416 ) { 417 if (!initialized) init(); 418 if (LogLevel.LOG_LEVEL_INFO <= singleton.getLoggingLevel()) { 419 singleton.logString( 420 AuditLog.logSource, 421 logString, 422 logObj, 423 LogLevel.LOG_LEVEL_INFO, 424 0); 425 } 426 } 427 428 438 public static void info( 439 String logString 440 ) { 441 if (!initialized) init(); 442 if (LogLevel.LOG_LEVEL_INFO <= singleton.getLoggingLevel()) { 443 singleton.logString( 444 AuditLog.logSource, 445 logString, 446 null, 447 LogLevel.LOG_LEVEL_INFO, 448 0); 449 } 450 } 451 452 471 public static void info( 472 String logString, 473 Object logObj, 474 int callStackOff 475 ) { 476 if (!initialized) init(); 477 if (LogLevel.LOG_LEVEL_INFO <= singleton.getLoggingLevel()) { 478 singleton.logString( 479 AuditLog.logSource, 480 logString, 481 logObj, 482 LogLevel.LOG_LEVEL_INFO, 483 callStackOff); 484 } 485 } 486 487 503 public static void detail( 504 String logString, 505 Object logObj 506 ) { 507 if (!initialized) init(); 508 if (LogLevel.LOG_LEVEL_DETAIL <= singleton.getLoggingLevel()) { 509 singleton.logString( 510 AuditLog.logSource, 511 logString, 512 logObj, 513 LogLevel.LOG_LEVEL_DETAIL, 514 0); 515 } 516 } 517 518 528 public static void detail( 529 String logString 530 ) { 531 if (!initialized) init(); 532 if (LogLevel.LOG_LEVEL_DETAIL <= singleton.getLoggingLevel()) { 533 singleton.logString( 534 AuditLog.logSource, 535 logString, 536 null, 537 LogLevel.LOG_LEVEL_DETAIL, 538 0); 539 } 540 } 541 542 561 public static void detail( 562 String logString, 563 Object logObj, 564 int callStackOff 565 ) { 566 if (!initialized) init(); 567 if (LogLevel.LOG_LEVEL_DETAIL <= singleton.getLoggingLevel()) { 568 singleton.logString( 569 AuditLog.logSource, 570 logString, 571 logObj, 572 LogLevel.LOG_LEVEL_DETAIL, 573 callStackOff); 574 } 575 } 576 577 593 public static void trace( 594 String logString, 595 Object logObj 596 ) { 597 if (!initialized) init(); 598 if (LogLevel.LOG_LEVEL_TRACE <= singleton.getLoggingLevel()) { 599 singleton.logString( 600 AuditLog.logSource, 601 logString, 602 logObj, 603 LogLevel.LOG_LEVEL_TRACE, 604 0); 605 } 606 } 607 608 618 public static void trace( 619 String logString 620 ) { 621 if (!initialized) init(); 622 if (LogLevel.LOG_LEVEL_TRACE <= singleton.getLoggingLevel()) { 623 singleton.logString( 624 AuditLog.logSource, 625 logString, 626 null, 627 LogLevel.LOG_LEVEL_TRACE, 628 0); 629 } 630 } 631 632 651 public static void trace( 652 String logString, 653 Object logObj, 654 int callStackOff 655 ) { 656 if (!initialized) init(); 657 if (LogLevel.LOG_LEVEL_TRACE <= singleton.getLoggingLevel()) { 658 singleton.logString( 659 AuditLog.logSource, 660 logString, 661 logObj, 662 LogLevel.LOG_LEVEL_TRACE, 663 callStackOff); 664 } 665 } 666 667 674 public static void setApplicationName(String appName) 675 { 676 setConfigName(appName); 677 } 678 679 690 public static void setLogLevel( 691 int logLevel 692 ) { 693 if (!initialized) init(); 694 singleton.setLoggingLevel(logLevel); 695 } 696 697 private static void init( 698 ) { 699 synchronized(singleton) { 700 if (!initialized) { 701 initialized = true; 702 703 singleton.loadConfig(AuditLog.configName, AuditLog.logProperties); 704 singleton.loadMechanisms(); 705 706 SysLog.register(AuditLog.getLogConfig()); 707 SysLog.trace("AuditLog (CfgName=" + AuditLog.configName + ") initialized"); 708 709 AuditLog.info("openMDX kernel version : " 711 + org.openmdx.kernel.Version.getImplementationVersion()); 712 713 AuditLog.info("openMDX base version : " 714 + org.openmdx.base.Version.getImplementationVersion()); 715 716 AuditLog.info("openMDX application version: " 717 + org.openmdx.application.Version.getImplementationVersion()); 718 719 try { 721 Dependencies.checkDependencies(); 722 } 723 catch (VersionMismatchException exception) { 724 AuditLog.error("Dependency check failed", exception); 725 throw exception; 726 } 727 } 728 } 729 } 730 731 732 final private static String LOGNAME = "AuditLog"; 733 final static String LOGSOURCE = "Audit"; 734 735 739 private static volatile Log singleton = newLog("AuditLog", AuditLog.class); 740 741 private static volatile boolean initialized = false; 742 743 744 private static Properties logProperties = null; 745 746 747 private static String configName = LOGNAME; 748 749 750 private static Object logSource = LOGSOURCE; 751 } 752 753 755 | Popular Tags |