Edits history of script submission #8890 for ' Write Log (gcloud)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    import { Logging } from "@google-cloud/logging";
    
    type Gcloud = {
      type: string;
      project_id: string;
      private_key_id: string;
      private_key: string;
      client_email: string;
      client_id: string;
      auth_uri: string;
      token_uri: string;
      auth_provider_x509_cert_url: string;
      client_x509_cert_url: string;
      universe_domain: string;
    };
    
    export async function main(
      resource: Gcloud,
      logName: string,
      message: string,
      severity?:
        | "DEFAULT"
        | "DEBUG"
        | "INFO"
        | "NOTICE"
        | "WARNING"
        | "ERROR"
        | "CRITICAL"
        | "ALERT"
        | "EMERGENCY"
    ) {
      const loggingClient = new Logging({
        credentials: resource,
        projectId: resource.project_id,
      });
    
      const log = loggingClient.log(logName);
    
      const metadata = {
        severity: severity || "DEFAULT",
      };
    
      const options = {
        resource: { type: "global" },
      };
    
      const entry = log.entry(metadata, message);
      await log.write(entry, options);
    
      return { success: true };
    }
    

    Submitted by hugo697 692 days ago

  • bun
    import { Logging } from "@google-cloud/logging";
    
    type Gcloud = {
      type: string;
      project_id: string;
      private_key_id: string;
      private_key: string;
      client_email: string;
      client_id: string;
      auth_uri: string;
      token_uri: string;
      auth_provider_x509_cert_url: string;
      client_x509_cert_url: string;
      universe_domain: string;
    };
    
    export async function main(
      resource: Gcloud,
      logName: string,
      message: string,
      severity?:
        | "DEFAULT"
        | "DEBUG"
        | "INFO"
        | "NOTICE"
        | "WARNING"
        | "ERROR"
        | "CRITICAL"
        | "ALERT"
        | "EMERGENCY"
    ) {
      const loggingClient = new Logging({
        credentials: resource,
        projectId: resource.project_id,
      });
    
      const log = loggingClient.log(logName);
    
      const metadata = {
        severity: severity || "DEFAULT",
      };
    
      const options = {
        resource: { type: "global" },
      };
    
      const entry = log.entry(metadata, message);
      await log.write(entry, options);
    
      return { success: true };
    }
    

    Submitted by hugo697 693 days ago

  • bun
    import { Logging } from '@google-cloud/logging'
    
    type Gcloud = {
    	projectId: string
    	privateKey: string
    	clientEmail: string
    }
    
    export async function main(
    	resource: Gcloud,
    	logName: string,
    	message: string,
    	severity?:
    		| 'DEFAULT'
    		| 'DEBUG'
    		| 'INFO'
    		| 'NOTICE'
    		| 'WARNING'
    		| 'ERROR'
    		| 'CRITICAL'
    		| 'ALERT'
    		| 'EMERGENCY'
    ) {
    	const credentials = {
    		client_email: resource.clientEmail,
    		private_key: resource.privateKey.replace(/\\n/g, '\n')
    	}
    
    	const loggingClient = new Logging({
    		credentials,
    		projectId: resource.projectId
    	})
    
    	const log = loggingClient.log(logName)
    
    	const metadata = {
    		severity: severity || 'DEFAULT'
    	}
    
    	const options = {
    		resource: { type: 'global' }
    	}
    
    	const entry = log.entry(metadata, message)
    	await log.write(entry, options)
    
    	return { success: true }
    }
    

    Submitted by hugo697 693 days ago