・ Je recherche un outil de journalisation cloud ・ J'ai plusieurs PC distants en cours d'exécution et je souhaite agréger les journaux. ・ Je souhaite l'utiliser gratuitement (à compter de la date de publication, jusqu'à 50 Go par mois gratuit)
Créez et téléchargez les informations d'identification à partir de Configuration de l'authentification.
Renommez le fichier json des informations d'authentification téléchargé en quelque chose comme "service.json".
pip install google-cloud-logging
Exemple de codage
import os
import sys
from google.cloud import logging
from pathlib import Path
class Logger(object):
    def __init__(self, log_name):
        #S'il n'y a pas de nom de journal, faites une erreur d'initialisation
        if log_name == None or log_name == '':
            print('ERROR : log_name is blank')
            sys.exit()
      
        parameter = {}
        parameter['project_name'] = '[Entrez le nom du projet Google qui a créé les informations d'identification ("My Project"Tel)】'
        parameter['credential_path'] = '[Entrez le chemin relatif du fichier json des informations d'authentification (s'il s'agit du même répertoire)"service.json"Tel】'
        os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = str((Path(Path.cwd()))/parameter['credential_path'])
        logging_client = logging.Client()
        self.logger = logging_client.logger(log_name)
    #Ecrire le DEBUG au niveau du journal
    def debug(self, text):
        self.logger.log_text(text, severity='DEBUG')
        print('Logged[DEBUG]: {}'.format(text))
    #Écrire INFO au niveau du journal
    def info(self, text):
        self.logger.log_text(text, severity='INFO')
        print('Logged[INFO]: {}'.format(text))
    #Ecrire le niveau de journal AVERTISSEMENT
    def warning(self, text):
        self.logger.log_text(text, severity='WARNING')
        print('Logged[WARNING]: {}'.format(text))
    #ERREUR de niveau de journal d'écriture
    def error(self, text):
        self.logger.log_text(text, severity='ERROR')
        print('Logged[ERROR]: {}'.format(text))
    #Ecrire le niveau de journal CRITIQUE
    def critical(self, text):
        self.logger.log_text(text, severity='CRITICAL')
        print('Logged[CRITICAL]: {}'.format(text))
if __name__ == '__main__':
  logger = Logger('my-log')
  logger.debug('test debug')
  logger.info('test info')
  logger.warning('test warning')
  logger.error('test error')
  logger.critical('test critical')
Affichez les journaux sur l'explorateur de journaux de Google (https://console.cloud.google.com/logs/).

Puisque vous pouvez suivre le journal graphiquement, il semble être raisonnablement facile à utiliser.
Recommended Posts