1 /******************************************************************************* 2 3 Tests the Log.stats() API 4 5 Copyright: 6 Copyright (c) 2016-2017 dunnhumby Germany GmbH. 7 All rights reserved. 8 9 License: 10 Boost Software License Version 1.0. See LICENSE_BOOST.txt for details. 11 Alternatively, this file may be distributed under the terms of the Tango 12 3-Clause BSD License (see LICENSE_BSD.txt for details). 13 14 *******************************************************************************/ 15 16 module integrationtest.loggerstats.main; 17 18 import ocean.util.log.Logger; 19 import ocean.core.Test; 20 import ocean.io.device.File; 21 22 /******************************************************************************* 23 24 Runs the test 25 26 *******************************************************************************/ 27 28 version (unittest) {} else 29 void main ( ) 30 { 31 auto dev_null = new File("/dev/null", File.WriteAppending); 32 Log.config(dev_null); 33 34 auto log1 = Log.lookup("MyLog1"); 35 log1.level = log1.Error; 36 37 auto log2 = Log.lookup("MyLog2"); 38 log2.level = log2.Warn; 39 40 // Clear any previous logger stats state 41 Log.stats(); 42 43 // Confirm that stats are auto reset 44 for (auto i = 0; i < 3; i++) 45 { 46 // Will emit 47 log1.fatal("Oh no"); 48 log1.error("Oh no"); 49 log2.fatal("Oh no"); 50 log2.error("Oh no"); 51 log2.warn("Oh no"); 52 53 // Will not emit 54 log1.warn("Shouldn't count"); 55 log1.info("Shouldn't count"); 56 log2.trace("Shouldn't count"); 57 58 auto stats = Log.stats(); 59 60 test!("==")(stats.logged_fatal, 2); 61 test!("==")(stats.logged_error, 2); 62 test!("==")(stats.logged_warn, 1); 63 test!("==")(stats.logged_info, 0); 64 test!("==")(stats.logged_trace, 0); 65 test!("==")(stats.total, 5); 66 } 67 }