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 module ocean.util.log.Event;
25 
26 import ocean.meta.types.Qualifiers;
27 import ocean.core.Verify;
28 import ocean.time.Clock;
29 import ocean.util.log.ILogger;
30 
31 ///
32 public struct LogEvent
33 {
34     private cstring         msg_, name_;
35     private Time            time_;
36     private ILogger.Level   level_;
37     private ILogger.Context host_;
38 
39     /// Set the various attributes of this event.
40     void set (ILogger.Context host, ILogger.Level level, cstring msg, cstring name)
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     cstring toString ()
51     {
52         return msg_;
53     }
54 
55     /// Return the name of the logger which produced this event
56     cstring name ()
57     {
58         return name_;
59     }
60 
61     /// Return the logger level of this event.
62     ILogger.Level level ()
63     {
64         return level_;
65     }
66 
67     /// Return the hierarchy where the event was produced from
68     ILogger.Context host ()
69     {
70         return host_;
71     }
72 
73     /// Return the time this event was produced,
74     /// relative to the start of this executable
75     TimeSpan span ()
76     {
77         return time_ - Clock.startTime();
78     }
79 
80     /// Return the time this event was produced relative to Epoch
81     Time time ()
82     {
83         return time_;
84     }
85 
86     /// Return the logger level name of this event.
87     cstring levelName ()
88     {
89         return ILogger.convert(this.level_);
90     }
91 }