{"id":15509558,"url":"https://github.com/huan/gasl","last_synced_at":"2025-04-23T02:33:29.684Z","repository":{"id":91647171,"uuid":"47741813","full_name":"huan/gasl","owner":"huan","description":"Google Apps Script Logging-framework","archived":false,"fork":false,"pushed_at":"2020-12-16T16:36:29.000Z","size":163,"stargazers_count":24,"open_issues_count":0,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-12T05:03:03.034Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/huan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-12-10T06:07:08.000Z","updated_at":"2024-12-02T23:10:32.000Z","dependencies_parsed_at":"2024-01-30T20:47:53.252Z","dependency_job_id":null,"html_url":"https://github.com/huan/gasl","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/huan%2Fgasl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/huan%2Fgasl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/huan%2Fgasl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/huan%2Fgasl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/huan","download_url":"https://codeload.github.com/huan/gasl/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250357950,"owners_count":21417386,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-02T09:43:15.030Z","updated_at":"2025-04-23T02:33:29.666Z","avatar_url":"https://github.com/huan.png","language":"JavaScript","funding_links":[],"categories":["Logging","6. Logging"],"sub_categories":["Services","Libraries and tools for implementing advanced logging capabilities in Google Apps Script projects."],"readme":"# GasL - Google Apps Script Logging-framework\n\nGasL is a unix syslog similar to the logging framework of Google Apps Script (GAS). It offers an easy way for GAS programs to log messages into Spreadsheets, LogEntries, RESTFUL API and GAS logger.\n\nGithub: \u003chttps://github.com/huan/gasl\u003e\n\nIn order to write into different log destinations, GasL comes with a components called `Printer`, which uses DI (Dependency Injection) to provide log entry functionalities. Behind the scenes, each Printer component is simply a function that accepts a parameter for message, and ouputs the content into log destinations.\n\nThe sample scripts below are executable. You can copy/paste it to google script editor for testing purposes.\n\n## Example 1 - Basic Usage\n\nThis sample uses Logger for output. \"Ctrl + Enter\" to get your logs.\n\n```javascript\nif ((typeof GasLog)==='undefined') { // GasL Initialization. (only if not initialized yet.)\n  eval(UrlFetchApp.fetch('https://raw.githubusercontent.com/huan/gasl/master/src/gas-log-lib.js').getContentText())\n} // Class GasLog is ready for use now!\n\nvar log = new GasLog()\n\nlog('Hello, %s!', 'World')\n```\n\n## Example 2 - Log to Google Spreadsheet:\n\nThis sample uses a spreadsheet for output. You can view the log output from this URL: \u003chttps://docs.google.com/spreadsheets/d/1_KRAtoDz2Pdcj9IPZI007I_gMzRyfmXf7gicgxVwYJc/edit#gid=0\u003e\n\n```javascript\nif ((typeof GasLog)==='undefined') { // GasL Initialization. (only if not initialized yet.)\n  eval(UrlFetchApp.fetch('https://raw.githubusercontent.com/huan/gasl/master/src/gas-log-lib.js').getContentText())\n} // Class GasLog is ready for use now!\n\nvar sheetPrinter = new GasLog.Printer.Spreadsheet({\n  url: 'https://docs.google.com/spreadsheets/d/1_KRAtoDz2Pdcj9IPZI007I_gMzRyfmXf7gicgxVwYJc/edit#gid=0'\n  , sheetName: 'Logs'\n  , clear: true\n  , scroll: 'UP'\n})\n\nvar log = new GasLog({\n  printer: sheetPrinter\n  , priority: 'INFO'\n})\n\nlog(log.INFO, 'Hello, %s!', 'Spreadsheet')\n```\n\nGasL is designed for running javascript on Google Apps Script environment ONLY.\n\n## Module Methods\n\nA simple example of GasL demo code can be found at https://github.com/zixia/gasl/blob/master/src/gasl-demo.js.\n\n### `GasLog`: GasL Module\n\nEval is used to get GasLog module in the code:\n\n```javascript\nif ((typeof GasLog)==='undefined') { // GasL Initialization. (only if not initialized yet.)\n  eval(UrlFetchApp.fetch('https://raw.githubusercontent.com/zixia/gasl/master/src/gas-log-lib.js').getContentText())\n} // Class GasLog is ready for use now!\n```\n\nGasLog is the main module of GasL.\n\nConstructor parameters:\n\n1. `printer`: Printer Component of DI. See the following `Printer` part.\n1. `priority`: Log priority. See the following `log(priority, format, ...)` part.\n1. `ident`: The name of the program that are logging.\n\n```javascript\nvar loggerPrinter = new GasLog.Printer.Logger()\n\nvar log = new GasLog({\n  printer: loggerPrinter\n  , priority: 'INFO'\n  , ident: 'foo'\n})\n```\n\n### `Printer`: Component of output DI\n\nGasLog.Printer is used by injector to enable output to different destination of GasT.\n\nIt currently supports 2 Printers: (more printers can be easily supported in the furture) \n\n1. `GasLog.Printer.Logger`\n1. `GasLog.Printer.Spreadsheet`\n1. `GasLog.Printer.LogEntries`\n\n#### `GasLog.Printer.Logger`: Default Printer of GasLog\n\nIt uses Logger.log of Google Apps Script to output.\n\nNo need to set any parameters.\n\n```javascript\nif ((typeof GasLog)==='undefined') { // GasL Initialization. (only if not initialized yet.)\n  eval(UrlFetchApp.fetch('https://raw.githubusercontent.com/huan/gasl/master/src/gas-log-lib.js').getContentText())\n} // Class GasLog is ready for use now!\n\nvar loggerPrinter = new GasLog.Printer.Logger()\n\nvar log = new GasLog({\n  printer: loggerPrinter // could be omitted.\n})\n```\n\n#### `GasLog.Printer.Spreadsheet`: Print to a spreadsheet\n\nIt uses a Spreadsheet URL or ID to specify a particular sheet, then log into that sheet.\n\nThe following parameters need to be configured: \n\n1. `spreadsheet`(Spreadsheet): Google Spreadsheet object. You must have the write permisstion for that spreadsheet. (one of spreadsheet/url/id must be set)\n1. `id`(string): Google Spreadsheet id. You must have the write permisstion for that spreadsheet. (one of spreadsheet/url/id must be set)\n1. `url`(string): Google Spreadsheet url. You must have the write permisstion for that spreadsheet. (one of spreadsheet/url/id must be set)\n1. `sheetName`(string): Tab name of the output sheet. Will be created if not exist. default `GasLog`. (OPTIONAL)\n1. `clear`(bool): true for clear the sheet before output. default false. (OPTIONAL)\n1. `scroll`(string): 'UP' for insert new log to the top. default 'DOWN'. (OPTIONAL)\n\n```javascript\nif ((typeof GasLog)==='undefined') { // GasL Initialization. (only if not initialized yet.)\n  eval(UrlFetchApp.fetch('https://raw.githubusercontent.com/huan/gasl/master/src/gas-log-lib.js').getContentText())\n} // Class GasLog is ready for use now!\n\nvar sheetPrinter = new GasLog.Printer.Spreadsheet({\n  url: 'https://docs.google.com/spreadsheets/d/1_KRAtoDz2Pdcj9IPZI007I_gMzRyfmXf7gicgxVwYJc/edit#gid=0'\n  , sheetName: 'Logs'\n  , clear: true\n  , scroll: 'UP'\n})\n  \nvar log = new GasLog({\n  printer: sheetPrinter\n  , logLevel: 'INFO'\n})\n```\n\n#### `GasLog.Printer.LogEntries`: The Printer for LogEntries.com\n\nIt uses cloud logging service LogEntries to output.\n\n[Logentries](https://logentries.com) is a software as a service provider for log management and intelligence. LogEntries collects and analyzes data found inside log files, in real-time with a cloud-delivered approach.\n\nCreate a new log set in LogEntries.com, with `Manual - Token TCP` option, then you will get a TOKEN for your log.\n\nPut TOKEN in the only options: token.\n\n```javascript\nif ((typeof GasLog)==='undefined') { // GasL Initialization. (only if not initialized yet.)\n  eval(UrlFetchApp.fetch('https://raw.githubusercontent.com/zixia/gasl/master/src/gas-log-lib.js').getContentText())\n} // Class GasLog is ready for use now!\n\nvar logentriesPrinter = new GasLog.Printer.LogEntries({\n  token: '4ea178f8-928d-3130-99ca-1f20ad803ec2' // this token is my logentries test log. welcome to write hello to me! :]\n})\n\nvar log = new GasLog({\n  printer: logentriesPrinter\n})\n```\n\nThen all logs will be outputed to LogEntries cloud.\n\n### `log(message)`: the simplest version\n\nSimply use it as below:\n\n```javascript\nlog('Hello, World!')\n```\n\nThen your message will be logged.\n\n### `log(priority, format, ...)`: the unix syslog-like function\n\nlog the message by `format` of `priority`.\n\n1. `format`: only supports '%s' because javascript only provides this.\n1. `priority`: should be one of the following.\n  1. `log.EMERG`\n  1. `log.ALERT`\n  1. `log.CRIT`\n  1. `log.ERR`\n  1. `log.WARNING`\n  1. `log.NOTICE`\n  1. `log.INFO`\n  1. `log.DEBUG`\n\n\n```javascript\nvar msg = 'test'\nlog(log.WARNING, 'This is a warning message: %s', msg)\n```\n\n### `log.setPriority(priority)`\n\nSet priority of this log.\n\n```javascript\nlog.setPriority(log.ERR)\n```\n\n### `log.getPriority()`\n\nGet priority of this log.\n\n```javascript\nvar priority = log.getPriority()\n```\n\n### `log.disable()`\n\nDisable for logging. all messages will be discarded when the log is set in Disabled state.\n\n```javascript\nlog.disable()\n```\nIt's useful when we are inside a `Custom Function` of spreadsheet. We have limited priviliges and can't write out.\n\n### `log.enable()`\n\nEnable for logging.\n\n```javascript\nlog.enable()\n```\n\n## Screen Snapshot\n\n![GasL(GasLog) for GAS(Google Apps Script)](https://raw.githubusercontent.com/huan/gasl/master/gasl-script-editor-screenshot.png)\n\nAn online version of google spreadsheet bounded with GasL google apps scripts can be found here:\n\n* Spreadsheet - \u003chttps://docs.google.com/spreadsheets/d/19M2DY3hunU6tDQFX5buJmZ_f3E8VFmlqAtodyC-J8Ag/edit#gid=1761137024\u003e\n* Script editor - \u003chttps://script.google.com/a/zixia.net/macros/d/Mta4oea1VMIugfSGRo4QrAnKRT9d30hqB/edit?uiv=2\u0026mid=ACjPJvGt4gnXjJwXnToB0jIMEbSvqKUF6vH-uq-m59SqnjXqTQ03NDn_khlNE6ha_mPnrOAYEnyFk80nHYmt_hppO3AgDkO_vVLrYJXzcPPagwRromd0znfLreNFAu4p0rYTC-Jlo-sAKOM\u003e\n\n## How to use GasL in Google Apps Script\n\nUse GasL is very simple: just copy/paste the following javascript section to your Code.gs file, then you are ready to use GasL.\n\n```javascript\nif ((typeof GasLog)==='undefined') { // GasL Initialization. (only if not initialized yet.)\n  eval(UrlFetchApp.fetch('https://raw.githubusercontent.com/huan/gasl/master/src/gas-log-lib.js').getContentText())\n} // Class GasLog is ready for use now!\n```\n\nThen you are ready to use:\n\n```javascript\nvar log = new GasLog(...)\nlog(...)\n```\n\n## How to implement a new Printer\n\nPrinter for GasL is a function to write log message into certain destinations. \n\nAdding a new Printer requires 2 steps:\n\n1. Write a new Printer function. (The default GasL Printer: `LoggerPrinter()` is a good template to start with.)\n1. Register the new Printer to GasL.\n\n### Write a new Printer function\n\nYou can find the default LoggerPrinter() function in gas-log-lib.js and modify it to make your own Printer.\n\n```javascript\nfunction LoggerPrinter() {\n  var loggerPrinter_ = function (priority, message) {\n    return Logger.log(message)\n  }\n  \n  loggerPrinter_.isPrinter = function () { return 'Logger' }\n  return loggerPrinter_\n}\n```\n\nNotice that `isPrinter()` is required to return a Printer name. If this function does not exist or returns false, then GasL will not consider this Printer usable.\n\n### Register the new Printer to GasL\n\nAfter creating your own Printer, this Printer must be registered to GasL before use.\n\nFind the following code in gas-log.js, then add your new Printer to the end.\n\n```javascript\ngasLog_.Printer = {\n  Logger: LoggerPrinter\n  , Spreadsheet: SpreadsheetPrinter\n  , LogEntries: LogEntriesPrinter\n}\n```\n\nYou are all set!\n\n## Support\n\nThe GasL source code repository is hosted on GitHub. There you can submit bugs on the issue tracker or submit tested pull requests for review. (\u003chttps://github.com/huan/gasl/issues\u003e)\n\nFor real-world examples from open-source projects using GasL, see Projects Using TasL on the wiki. (\u003chttps://github.com/zixia/gasl/wiki\u003e)\n\n## Version history\n\n### [v0.4.0](https://github.com/huan/gasl/releases/tag/v0.4.0) (December 14, 2015)\n\n* bug fix for spreadsheet printer\n* support multi log instance for different ident\n* LogEntries support\n* new function: disable() \u0026 enable()\n* GasLog.Printer implement document\n* Support set ident name in options\n\nUse v0.4.0 in GAS\n\n```javascript\n/**\n*\n* GasL v0.4.0 Initialization. (only if not initialized yet.)\n* https://github.com/zixia/gasl\n*\n*/\nif ((typeof GasLog)==='undefined') { // GasL Initialization. (only if not initialized yet.)\n  eval(UrlFetchApp.fetch('https://github.com/zixia/gasl/blob/v0.4.0/src/gas-log-lib.js').getContentText())\n} // Class GasLog is ready for use now!\n```\n\n### v0.1.0 (December 10, 2015)\n\n* Initial public release.\n\n-------------------------------------------\n© 2015 Huan LI \u003czixia@zixia.net\u003e. GasL is released under an MIT-style license; see LICENSE for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhuan%2Fgasl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhuan%2Fgasl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhuan%2Fgasl/lists"}