Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/samerde/write-this

A little function to help write output to the console and log files at the same time to keep your actual code cleaner.
https://github.com/samerde/write-this

powershell utilities utility-function

Last synced: 26 days ago
JSON representation

A little function to help write output to the console and log files at the same time to keep your actual code cleaner.

Awesome Lists containing this project

README

        

# Write-This

[![GitHub stars](https://img.shields.io/github/stars/samerde/Write-This?cacheSeconds=3600)](https://github.com/samerde/Write-This/stargazers/)
[![GitHub contributors](https://img.shields.io/github/contributors/samerde/Write-This.svg)](https://github.com/samerde/Write-This/graphs/contributors/)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)

![GitHub top language](https://img.shields.io/github/languages/top/SamErde/Write-This)
[![Codacy Badge](https://app.codacy.com/project/badge/Grade/ae92f0d929de494690e712b68fb3b52c)](https://app.codacy.com/gh/SamErde/Write-This/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade)

## Synopsis

Write a message to the console and a log file at the same time.

## Description

A little function to help write output to the console and log files at the same time to keep your actual code cleaner. Instead of having separate lines for interactive output and log files, one function can handle both.

## Example

Until this is an actual module, the following example shows how to manually import the three scripts and use them:

```powershell
. .\Start-WriteThis.ps1
. .\Write-This.ps1
. .\Stop-WriteThis.ps1

Start-WriteThis -LogFile "TestLog"

Write-This -LogText "First!" -Output Both -ForegroundColor White -BackgroundColor DarkBlue
$Directories = Get-ChildItem -Directory $env:TEMP
$DirectoryCount = $Directories.Count
Write-This -LogText "Found $DirectoryCount directories in the current folder." -Output Both
Write-This -LogText "These details are only going into the log file:`n$Directories" -Output LogOnly
Write-This -LogText "Let's finish this up." -ForegroundColor Green -BackgroundColor Black

Stop-WriteThis -LogFile $script:LogFile
```