dlog 0.0.3
Simple and modular logging library
To use this package, run the following command in your project's root directory:
Manual usage
Put the following dependency into your project's dependences section:
dlog
Simple and modular logging library
[2021-Dec-23 11:17:35.3527637] (source/dlog/testing/thing.d:12): This is a log message
Usage
We recommend you use dub to add dlog to your project as follows:
dub add dlog
Components
dlog is formed out of two main components:
Logger- The logger contains the needed barebones for facilitating the actual logging of text
MessageTransform- A MessageTransform is attached to a logger and performs manipulation on the text input into the logger for logging
- They may be chained as to perform multiple transformations in a stream-like fashion
Quick start
If you want to immediately begin logging text usin the defaults and don't care about implementing your own transformations then you can simply use the defaulkt logger as follows:
import dlog;
Logger logger = new DefaultLogger();
logger.log("This is a log message");
logger.log(1);
logger.log(1==1);
logger.log([1,2,3]);
This will output the following:
[2021-Dec-23 11:17:35.3527637] (source/dlog/testing/thing.d:12): This is a log message
[2021-Dec-23 11:17:35.3527717] (source/dlog/testing/thing.d:13): 1
[2021-Dec-23 11:17:35.3527789] (source/dlog/testing/thing.d:14): true
[2021-Dec-23 11:17:35.3527871] (source/dlog/testing/thing.d:15): [1, 2, 3]
As you can see file and line numbering of where the log() function is called appears in the log message which can be quite helpful
for debugging.
Custom loggers
Perhaps the default transformation, DefaultTransform, may not be what you want. Maybe you want the module name included in the logged
messages or perhaps don't want the date-and-timestamp included at all. All of this can be up to you if you choose to implement your own
message transform.
You will need to start off with a class that inherits from the MessageTransform class and then which overrides the transform method as shown below:
import dlog;
public class CustomTranform : MessageTransform
{
public override string transform(string text, string[] context)
{
string transformed;
return transformed;
}
}
Additional information, besides the text being logged itself (this is the string text argument), comes in the form of a string array as string[] context
the contents of which are described below:
context[0]- This contains
__FILE_FULL_PATH__which is the full path (absolute) to the source file wherelog()was called
- This contains
context[1]- This contains
__FILE__which is the path (starting atsource/to the source file wherelog()was called
- This contains
context[2]- This contains a stringified version of
__LINE__which is the line number of the call tolog()
- This contains a stringified version of
context[3]- This contains
__MODULE__which is the name of the module the call tolog()appeared in
- This contains
context[4]- This contains
__FUNCTION__which is the name of the functionlog()was called in
- This contains
context[5]- This contains
__PRETTY_FUNCTION__which is the same as above but with type information
- This contains
context[5..X]- This contains optional extras that were set when the
log()function was called with thecontextExtrasset - Example:
log("Hello world", contextExtras=[this])
- This contains optional extras that were set when the
License
LGPLv2
- 0.0.3 released 4 years ago
- deavmi/dlog
- LGPLv2
- Copyright © 2021, Tristan B. Kildaire
- Authors:
- Dependencies:
- none
- Versions:
-
Show all 42 versions1.0.2 2025-Mar-21 1.0.1 2024-Apr-10 1.0.0 2024-Apr-10 0.3.19 2023-Mar-03 0.3.18 2023-Mar-03 - Download Stats:
-
-
0 downloads today
-
7 downloads this week
-
143 downloads this month
-
3358 downloads total
-
- Score:
- 1.3
- Short URL:
- dlog.dub.pm