Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cutting and Pasting BetterLog - have not been able to figure it out #8

Closed
MikeSchwartz opened this issue Jun 23, 2016 · 2 comments
Closed

Comments

@MikeSchwartz
Copy link

Hi -

First, thank you very much for BetterLog. It's a great tool.

For security reasons I'm not able to use Libraries in my script. I'm using BetterLog as a library during development but will soon need to cut and paste it so that my scripts are self-contained. The instructions imply this is possible, but I haven't been able to figure out how. I am a complete noob at GAS and Javascript in general so I am probably missing something very simply.

Here's what I've done

  • File -> New -> Project
  • In that project, File -> New -> Script file
  • Named the new file BetterLog.gs
  • Cut-and-pasted https://raw.githubusercontent.com/peterherrmann/BetterLog/master/Code.gs into that file.
  • Wrote the following test function in the project's Code.js file
    function testBetterLog() {
    Logger = BetterLog.useSpreadsheet("1v5PMxB1XomareGgLOjo9LNEuj6GNBdMjczJ3YnPra5Q");
    Logger.log("hello");
    }
  • Saved both files
  • Run
  • Acknowledge the permissions
  • Get the error: ReferenceError: "BetterLog" is not defined. (line 2, file "Code")

Please advise how I can use the source of BetterLog in my application.

Thanks again,
Mike

@andrewroberts
Copy link

andrewroberts commented Jun 23, 2016

You'll need to wrap all of the code in an object and modify the function definitions to use it locally. Note the commas after each function. In the same way I've done it with the CBL library. If you make a start I'll be happy to look it over:

var BetterLog = (function() {

return {

// Public Functions
.
.
.

info: function() {

},

} // return

// Private Functions
.
.
.

})() // BetterLog

@xentan
Copy link

xentan commented Jul 2, 2016

I just pasted it in the same file i have been using for my project. And i pasted it first.

I then just did: var Logger = useSpreadsheet('my doc');

then i can freely use Logger.log("log me");

and it logs to my Log sheet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants