Developer log in Joomla? - joomla

Does Joomla have a general purpose API for logging debug information to a file, or to the database, so that extension writers can capture debug info from a live site?
Enabling debug output and logging to screen is not an option. It's a live site.
Something like Drupal's watchdog would be nice.

I'm sorry for the short answer :)
This page might help: https://docs.joomla.org/Using_JLog
It shows how to configure the log output and how to use logging in your own code.
EDIT, in case the link dies:
Enable "Log Everything" under the properties of the System - Debug plugin.
To create log records:
JLog::add("Hello world", JLog::INFO);
If within a namespace, qualify JLog:
\JLog::add("Hello world", \JLog::INFO);
There's no built-in log reading UI, just look at administrator/logs/everything.php.

Related

How to debug web development in Google Application Script?

I am testing/learning webhook. How to send, receive it. So I thought I would use GAS.
I have this simple script and I wonder why Logger does not work. In Projects/Executions I can see that the script doPost was executed but no logs. Email was sent and the script returned the value.
using old, Legacy Editor (no idea how to get the new one)
in Menu-Resources-Cloud Platform Project is said "This script has an Apps Script-managed Cloud Platform project."
when I open the project in editor I get this message "This project is running on our new Apps Script runtime powered by Chrome V8."
exception logging set to "exceptionLogging": "STACKDRIVER" is set to default
I tried console.log(e); but it did not work for me.
function doPost(e) {
Logger.log("I was called")
if(typeof e !== 'undefined'){
Logger.log(e.parameter);
Logger.log("I was called 2")
MailApp.sendEmail({
to: "radek#gmail.com",
subject: "Call Sucessful",
htmlBody: "I am your <br>" +
JSON.stringify(e)+ "<br><br>" +
JSON.stringify(e.parameters)
});
}
return ContentService.createTextOutput(JSON.stringify(e))
}
Question1: Can I make Logger work?
Question2: I would like to see accepted data in Debugger, is that possible?
Question3: Is there any way the GAS pushes the data it received to my web browser. Of course the browser is NOT sending the data.
Question4: No related to the topic but ... Would you know what I need to do in order to be able to use new Editor?
If you want your own custom log information to go to Stackdriver, then you need to create a Google Cloud Platform project, and associate that GCP project with your Apps Script project.
First create a new GCP Project:
Go to your GCP dashboard:
https://console.cloud.google.com/home/dashboard?authuser=0
In the blue bar at the top, there is a drop down menu for project names. Click that, and a dialog should appear with a button to create a new project.
Create a new Google Cloud Platform project.
Copy the Project Number.
Go back to the Apps Script editor.
From the legacy Apps Script editor, click the "Resources" menu.
Click Cloud Platform project.
Paste in the Project Number and click the button.
Now, any console.log() statements you have will send the logs to Stackdriver.
And Stackdriver can be viewed in your browser.
Note: Some people set up their own logging system to log information from server side Apps Script code to a Google Sheet. There are some open source repos that are available.
The new code editor does have a "built-in" way to log server side information to a log pane code editor window. But, of course this assumes that you are running code from the code editor. This new feature avoids the need for changing browser tabs to see your logging output. I don't know of any way to log server side info to your browser console. You could save log info into an object, and then send it back to the client after the server code completed, and then log everything in the console.
The way that it might be possible to get logging information depends on how the code was originally triggered.
From code editor
From a user using your app
From a Http Request to your Web App
Logging in Apps Script works differently depending upon:
run time version being used - V8 or DEPRECATED_ES5 - Set in appsscript.json file or through the "Run" menu in the Legacy editor, Set in "Settings" in new IDE - New Apps Script projects default to V8 so chances are your project is using V8.
Is your Apps Script project associated with a Google Cloud Platform
(GCP) default or standard project
Is exception logging set to "exceptionLogging": "STACKDRIVER" - Set in appsscript.json file - Default is always to include it - Probably already correct unless you deleted it.
Using either Logger.log or console.log
Using console.log in the server ".gs" file or client side ".html"
file. console.log can be used in both server and client side code
but the log print out goes to different places. You can't see logs
in the browser dev tools from a console.log statement in your
server code. If you use console.log in server side .gs files, and the Apps Script project is not associated with a standard GCP project, then the log only gets sent to your "Executions." I believe that the only way that you can get your logs sent to Stackdriver is by using a standard GCP project. The problem with that, is that you only have so many GCP projects that you can use without requesting an increase in your quota.
Plus there may be issues (bugs) depending upon how you have logging set up and other factors.
For example:
https://issuetracker.google.com/issues/134374008
As lots of people specified, you can use console.log for this.
However, I also work with webhooks from time to time. And I find it much more comfortable to debug directly into google spreadsheets, using code like this
function doPost(e) {
log('# doPost', JSON.stringify(e));
try {
// Some webhook-processing logic here
if(e.parameter.action == 'test-error') {
item.something = nothing;
}
if(e.parameter.action == 'test-log') {
log('# custom log', 'Some data');
}
} catch(error) {
log('# error', JSON.stringify([error, error.stack]));
}
}
function log(event, message){
SpreadsheetApp.getActive().getSheetByName('Log').appendRow([new Date(), event, message])
}
Example spreadsheet:
https://docs.google.com/spreadsheets/d/144i9pxDIB_C8ZRZ-6vd9DiPIw8Rt85hTtVoqk7dtHQg/edit?usp=sharing
You can trigger logging by something like this
curl -X POST https://script.google.com/macros/s/AKfycby3EoaQ8DOt8H_Mc4vjH6JZkhsaAwYHk_sa9HE5Be3qVo0Ym0b2/exec?action=test-error
or
curl -X POST https://script.google.com/macros/s/AKfycby3EoaQ8DOt8H_Mc4vjH6JZkhsaAwYHk_sa9HE5Be3qVo0Ym0b2/exec?action=test-log
You can use same log for your custom logging of some intermediate variable during webhook resolution.
The reason I prefer this over standard stackdriver logging is that google sheets are more explicit and easier to manage.
You can use console.log() to see things within "My Executions".

Form displays blank fields instead of DB data values

I have a from with a plugin that updates a record in the DB. I see the updated data in the record in the DB, but when i load the form the updated data does not show.
there are no business rules, the is no JS OnLoad event.
The record is inactive in the DB when the data is updated, but i don' think that should matter
Any ideas as to what I am overlooking?
You're correct that the changes should still save to an inactive record.
Under Advanced Settings > Administration > System Settings > Customization you can set "Enable logging to plug-in trace log" to "All".
Then in the plugin you can use the ITracingService to log messages, which are then visible in Advanced Settings > Plugin-In Trace Log.
You could log the fields' values before and after you set them to confirm that they're getting set.
Or, for a "quick and dirty" option store the fields' values before you set them, then after you set them, throw an InvalidPluginExecution exception containing the "before and after" values. The exception message will pop up right in the UI.
We'd be better able to analyze the issue if you post your code.
On a related note, when writing plugins I often separate the logic out into a Visual Studio Shared Project. I reference that project from a console app and the plugin assembly. The console app enables me to test and debug locally with full VS debugging capabilities before publishing the plugin. Of course there are certain things from the context that can be tricky to mock in the Console app, so your mileage may vary depending on the application.
There are also testing frameworks like FakeXrmEasy, but I have yet to try any of those.

Can't see metrics on Azure sent by AppInsights-Ruby gem

I have a Rails application and I want to start tracking some metrics and events.
I must track this information using Microsoft Azure, so I found a the gem AppInsights-Ruby developed by Microsoft itself.
I got my instrumentation_key and did what the README says but I can't see any information on the Azure portal.
I thought it could be a problem with the queues so I filled up the queue with
2000.times {|x| tc.track_metric 'My metric', x }
6000.times {|x| tc.track_event 'My event' }
But again, there is no metrics or events on the Azure portal.
Does anybody used this gem?
Am I missing something?
There is potentially a JSON issue in v0.3.0 of this gem. After investigating we saw that the return information from the API said our JSON was invalid (but the JSON was created by the gem.)
v0.5.0 changes how it uses JSON and that seemed to have resolved the issue.
The v0.5.0 changes are here
where are you looking for them?
when you use track_metric, the metrics by themselves don't show up as "events", you have to use track_event (or others) to send events.
metrics like this should, though, show up in metrics explorer. (open your overview page, find the "metrics explorer" part, click it, and then in the edit blade scroll to the bottom, there should be a "Custom Metrics" section, and your metrics should show up there.
If you attach the metrics in a track_[event|pageview|request|exception|trace], then you'll see those events in the diagnostic search list and the metrics will appear as event properties, in the properties blade.
If you don't see them at all on the portal, try using something like fiddler to watch the outbound requests, and see if you see data going to dc.services.visualstudio.com, where the data is collected. Those requests/responses should indicate if data is successfully being transmitted.

How to enable Joomla debug mode from the URL

I often need performance information from live sites. Since I cannot show debug information to the end users, I need a way to enable Joomla! debug mode with a URL parameter, that is,
http://example.com/?debug=1
I have only been able to achieve this with a core hack of includes/framework.php at line 91 (Joomla 2.5.9):
define('JDEBUG', $config->debug || JRequest::getVar('debug','0')=='1');
Which alternatively could be played on configuration.php:
public $debug = JRequest::getVar('debug','0')=='1';
I just tested overriding the configuration with a system plugin following Mark Dexter and Louis Landry's post at Using Plugins to Override Core Classes. But a quick-test with Ivan Rajkovic suggestion,
print_r(JLoader::getClassList());
shows that the configuration is already loaded, so it cannot be overridden.
Can you suggest a better way to achieve this without a core hack?
Is there a solution for Joomla! 3?
I think if you enabled the debug plugin (in the plugins list) and set its access level to Superuser or whatever your rank is, no one else will be able to see the debug information except you.
Update
There's a plugin (for Joomla! 1.5 though) that limit the debug output for certain IPs to make it possible for you to debug a live site without exposing it to everyone. Not sure how easy is it to make it work with Joomla! 2.5

Effective way to debug a Google Apps Script Web App

I have had some experience writing container-bound scripts, but am totally new to web apps.
How do I debug (e.g. look at variable values, step through code etc) a web app? In a container bound script it was easy, because I could set breakpoints, use the apps script debugger - how do I go about this in a web page e.g. when I execute a doPost?
In his excellent book "Google Script", James Ferreira advocates setting up your own development environment with three browser windows; one for the code, one for the live view (in Publish, Deploy as web app, you are provided with a "latest code" link that will update the live view to the latest save when it is refreshed), and one for a spreadsheet that logs errors (using try/catch wrapped around bits of code you want to keep an eye on).
In Web Apps, even the most basic debugging of variables through Logger.log() does not work!
A great solution to have at least simple variable logging available is Peter Herrmann's BetterLog for Apps Script. It allows you to log into a spreadsheet (the same as your working spreadsheet or a separate one).
Installation is very simple - just add an external resource (see the Github readme) and a single line of code to override the standard Logger object:
Logger = BetterLog.useSpreadsheet('your-spreadsheet-key-goes-here');
Remember, that the spreedsheet that you give here as a parameter will be used for the logging output and thus must be writable by anybody!
BetterLog will create a new sheet called "Log" in the given spreadsheet and will write each log call into a separate row of that sheet.
So, for me, I debug the front-end using inspector, I haven't found a way to step through code yet, but you can use 'debugger' in your javascript (along with console.log) to stop the code and check variables.
to debug the backend, what I've been doing is to write my functions like
function test_doSomething(){
payload = "{item1: 100, item2: 200}" //<- copy paste from log file
backend_doSomething(payload)
}
function backend_doSomething(payload){
Logger.log(payload)
params = JSON.parse(payload)
...
}
Then after refreshing your project on the backend, you can look at executions, grab the payload from the log file, and paste it into your test_doSomething() function.
From there, you are re-creating the call that you want to debug and you can run that, stepping through the backend code as usual.

Resources