Skip to content

Commit e9f039a

Browse files
committed
Update readme.md
1 parent 2371f8c commit e9f039a

File tree

1 file changed

+28
-17
lines changed

1 file changed

+28
-17
lines changed

readme.md

+28-17
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,41 @@
1-
# VBA-UTC
1+
# VBA-Log
22

3-
UTC and ISO 8601 date conversion and parsing for VBA (Windows and Mac Excel, Access, and other Office applications).
3+
Logging helpers for VBA. Logs to Immediate Window by default (`ctrl + g`), but can attach multiple loggers with callbacks.
44

55
Tested in Windows Excel 2013 32-bit and 64-bit and Excel for Mac 2011, but should apply to Windows Excel 2007+.
66

77
# Example
88

99
```VB.net
10-
' Timezone: EST (UTC-5:00), DST: True (+1:00) -> UTC-4:00
11-
Dim LocalDate As Date
12-
Dim UtcDate As Date
13-
Dim Iso As String
10+
Logger.LogDebug "Howdy!"
11+
' -> does nothing because logging is disabled by default
1412

15-
LocalDate = DateValue("Jan. 2, 2003") + TimeValue("4:05:06 PM")
16-
UtcDate = UtcConverter.ConvertToUtc(LocalDate)
13+
Logger.LogEnabled = True
14+
' -> Log all levels (Trace, Debug, Info, Warn, Error)
1715

18-
Debug.Print VBA.Format$(UtcDate, "yyyy-mm-ddTHH:mm:ss.000Z")
19-
' -> "2003-01-02T20:05:06.000Z"
16+
Logger.LogThreshold = 3
17+
' -> Log levels >= 3 (Info, Warn, and Error)
2018

21-
Iso = UtcConverter.ConvertToIso(LocalDate)
22-
Debug.Print Iso
23-
' -> "2003-01-02T20:05:06.000Z"
19+
Logger.LogTrace "Start of logging"
20+
Logger.LogDebug "Logging has started"
21+
Logger.LogInfo "Logged with VBA-Log"
22+
Logger.LogWarn "Watch out!", "ModuleName.SubName"
23+
Logger.LogError "Something went wrong", "ClassName.FunctionName", Err.Number
2424

25-
LocalDate = UtcConverter.ParseUtc(UtcDate)
26-
LocalDate = UtcConverter.ParseIso(Iso)
25+
' Attach alternative logging function(s)
26+
Public Sub LogFile(Level As Long, Message As String, From As String)
27+
' ...
28+
End Sub
2729

28-
Debug.Print VBA.Format$(LocalDate, "m/d/yyyy h:mm:ss AM/PM")
29-
' -> "1/2/2003 4:05:06 PM"
30+
' Log to single function
31+
Logger.LogCallback = "LogFile"
32+
33+
Public Sub LogWorkbook(Level As Long, Message As String, From As String)
34+
' ...
35+
End Sub
36+
37+
' Log to multiple functions
38+
Logger.LogCallback = Array("LogFile", "LogWorkbook")
3039
```
40+
41+
For applications that don't support `Application.Run` (e.g. Access), there is a note in `Logger.Log` for where to put your custom logging function (if desired).

0 commit comments

Comments
 (0)