Last active
November 29, 2018 17:01
-
-
Save plencovich/5cbf9c544be03b7bcca3ace0f21d3734 to your computer and use it in GitHub Desktop.
Google Cloud Logging / Stackdriver Logs / Codeigniter / PHP -> by Plen.co
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
defined('BASEPATH') OR exit('No direct script access allowed'); | |
// Libreria Cloud Log para Codeigniter | |
use Google\Cloud\Logging\LoggingClient; | |
class Cloudlog | |
{ | |
private $projectId; | |
private $logging; | |
public function __get($var) | |
{ | |
return get_instance()->$var; | |
} | |
public function __construct() { | |
$this->projectId = 'project-id-google'; | |
$this->logging = new LoggingClient([ | |
'keyFile' => json_decode(file_get_contents('./key/gcloud.json'), true), | |
'projectId' => $this->projectId | |
]); | |
} | |
function write_log($loggerName, $message,$severity) | |
{ | |
$logger = $this->logging->logger($loggerName, [ | |
'resource' => [ | |
'type' => 'global' | |
] | |
]); | |
$logger->write(['message' => $message],['severity' => $severity]); | |
} | |
function delete_logger($loggerName) | |
{ | |
$logger = $this->logging->logger($loggerName); | |
$logger->delete(); | |
printf("Deleted a logger '%s'." . PHP_EOL, $loggerName); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"require": { | |
"google/cloud-logging": "^1.14" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Carga libreria | |
$this->load->library('Cloudlog'); | |
// Escribe LOG | |
$this->cloudlog->write_log('logger_name','message_text',500); // Code severity https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#LogSeverity | |
// Borra LOG | |
$this->cloudlog->delete_logger('logger_name'); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment