Skip to content

Instantly share code, notes, and snippets.

@atao
Last active December 19, 2019 10:00
Show Gist options
  • Select an option

  • Save atao/1ab32d886688c706cba315bc0739c12d to your computer and use it in GitHub Desktop.

Select an option

Save atao/1ab32d886688c706cba315bc0739c12d to your computer and use it in GitHub Desktop.

Revisions

  1. atao revised this gist Dec 19, 2019. 1 changed file with 5 additions and 5 deletions.
    10 changes: 5 additions & 5 deletions journalisation.ps1
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    #region Journalisation
    function initLog {
    param(
    [string]$loggerPath
    [string]$loggerPath = "$PSScriptRoot\file.log"
    )
    if (!(Test-Path $loggerPath)){New-Item -Path $loggerPath -ItemType File}
    loggerInfo "-----------------------------------------------" $loggerPath
    @@ -12,8 +12,8 @@ function initLog {

    function loggerInfo {
    Param (
    [string]$msg,
    [string]$loggerPath
    [parameter(Mandatory = $true)][string]$msg,
    [string]$loggerPath = "$PSScriptRoot\file.log"
    )
    # Verification de la presence du chemin temporaire de l'utilisateur
    If (Test-Path -Path $loggerPath)
    @@ -34,8 +34,8 @@ function loggerInfo {

    function loggerErreur {
    Param (
    [string]$msg,
    [string]$loggerPath
    [parameter(Mandatory = $true)][string]$msg,
    [string]$loggerPath = "$PSScriptRoot\file.log"
    )
    # Verification de la presence du chemin temporaire de l'utilisateur
    If (Test-Path -Path $loggerPath)
  2. atao created this gist Dec 18, 2019.
    56 changes: 56 additions & 0 deletions journalisation.ps1
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,56 @@
    #region Journalisation
    function initLog {
    param(
    [string]$loggerPath
    )
    if (!(Test-Path $loggerPath)){New-Item -Path $loggerPath -ItemType File}
    loggerInfo "-----------------------------------------------" $loggerPath
    loggerInfo "+ Programme : BackupAndSend" $loggerPath
    loggerInfo "+ Version : 18/12/2019" $loggerPath
    loggerInfo "-----------------------------------------------" $loggerPath
    }

    function loggerInfo {
    Param (
    [string]$msg,
    [string]$loggerPath
    )
    # Verification de la presence du chemin temporaire de l'utilisateur
    If (Test-Path -Path $loggerPath)
    {
    # Recuperation de la date actuelle
    $dateActuelle = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
    "$dateActuelle [INFO] $msg" | Out-File -FilePath $loggerPath -Append
    If (!($?))
    {
    loggerErreur "Impossible d'écrire dans le fichier $loggerPath"
    }
    }
    Else
    {
    loggerErreur "Impossible de trouver le chemin $loggerPath"
    }
    }

    function loggerErreur {
    Param (
    [string]$msg,
    [string]$loggerPath
    )
    # Verification de la presence du chemin temporaire de l'utilisateur
    If (Test-Path -Path $loggerPath)
    {
    # Recuperation de la date actuelle
    $dateActuelle = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
    "$dateActuelle [ERROR] $msg" | Out-File -FilePath $loggerPath -Append
    If (!($?))
    {
    loggerErreur "Impossible d'écrire dans le fichier $loggerPath"
    }
    }
    Else
    {
    loggerErreur "Impossible de trouver le chemin $loggerPath"
    }
    }
    #endregion Journalisation