1 /*******************************************************************************
2 3 Common struct to store `ocean.util.log` event internally
4 5 Contains all information about a logging event, and is passed around
6 between methods once it has been determined that the invoking logger
7 is enabled for output.
8 9 Note that Event instances are maintained in a freelist rather than
10 being allocated each time, and they include a scratchpad area for
11 EventLayout formatters to use.
12 13 Copyright:
14 Copyright (c) 2004 Kris Bell.
15 Some parts copyright (c) 2009-2016 dunnhumby Germany GmbH.
16 All rights reserved.
17 18 License:
19 Tango Dual License: 3-Clause BSD License / Academic Free License v3.0.
20 See LICENSE_TANGO.txt for details.
21 22 *******************************************************************************/23 24 moduleocean.util.log.Event;
25 26 importocean.transition;
27 importocean.core.Verify;
28 importocean.time.Clock;
29 importocean.util.log.model.ILogger;
30 31 ///32 publicstructLogEvent33 {
34 privatecstringmsg_, name_;
35 privateTimetime_;
36 privateILogger.Levellevel_;
37 privateILogger.Contexthost_;
38 39 /// Set the various attributes of this event.40 voidset (ILogger.Contexthost, ILogger.Levellevel, cstringmsg, cstringname)
41 {
42 time_ = Clock.now;
43 level_ = level;
44 host_ = host;
45 name_ = name;
46 msg_ = msg;
47 }
48 49 /// Return the message attached to this event.50 cstringtoString ()
51 {
52 returnmsg_;
53 }
54 55 /// Return the name of the logger which produced this event56 cstringname ()
57 {
58 returnname_;
59 }
60 61 /// Return the logger level of this event.62 ILogger.Levellevel ()
63 {
64 returnlevel_;
65 }
66 67 /// Return the hierarchy where the event was produced from68 ILogger.Contexthost ()
69 {
70 returnhost_;
71 }
72 73 /// Return the time this event was produced,74 /// relative to the start of this executable75 TimeSpanspan ()
76 {
77 returntime_ - Clock.startTime();
78 }
79 80 /// Return the time this event was produced relative to Epoch81 Timetime ()
82 {
83 returntime_;
84 }
85 86 /// Return the logger level name of this event.87 cstringlevelName ()
88 {
89 returnILogger.convert((&this).level_);
90 }
91 92 /// Convert a time value (in milliseconds) to ascii93 staticmstringtoMilli (mstrings, TimeSpantime)
94 {
95 verify (s.length > 0);
96 longms = time.millis;
97 98 autolen = s.length;
99 do {
100 s[--len] = cast(char)(ms % 10 + '0');
101 ms /= 10;
102 } while (ms && len);
103 returns[len..s.length];
104 }
105 }