Commands / Invoke-sqmLogging
Invoke-sqmLogging
sqmTool Config sqmSQLTool v1.8.2+ · Utility
Writes a single log message to the current day's log file of the calling function. This is the internal logging primitive every other sqmSQLTool function calls behind the scenes, exposed publicly so scripts calling into sqmSQLTool can write to the same log stream (e.g. from a wrapper script or a custom Agent job step). One log file is created per calling function per day, in the configured LogPath (see Get-sqmConfig). Writing only happens once the module has finished its own initialization ($script:sqmLoggingReady); calls made before that point are silently skipped rather than failing.
Not under -WhatIf: logging is treated as a side channel and deliberately runs with -WhatIf:$false internally, so a caller's own -WhatIf never leaks in and turns log writes into no-op "What if: Output to File" noise instead of an actual log entry.

Parameters

ParameterTypeRequiredDefaultNotes
-MessagestringRequired, The text to log.
-FunctionNamestringOptional'General'Used in the log file name: sqmSQLTool_<yyyyMMdd>_<FunctionName>.log.
-LevelstringOptional'INFO'One of: INFO, WARNING, ERROR, DEBUG, VERBOSE.

Execution Flow

START $script:sqmLoggingReady -and LogPath configured? NO Silently skipped YES Ensure LogPath directory exists New-Item -Force (in case deleted after module import) Append "[HH:mm:ss] [Level] Message" sqmSQLTool_<yyyyMMdd>_<FunctionName>.log one file per calling function, per day Write failed? (e.g. permissions) YES Write-Warning (last resort - never throws) NO DONE

Examples

Write an informational log entry from a custom wrapper script
Invoke-sqmLogging -Message "Nightly job started" -FunctionName "MyWrapper" -Level "INFO"
Write a warning
Invoke-sqmLogging -Message "Backup share almost full" -FunctionName "MyWrapper" -Level "WARNING"