What is the actual syntax to log in SailsJS?
Docs don't have anything, but found the following line in the site's roadmap
"Pull out Sails.log (winston wrapper) as a separate module so it can
be used by waterline"
I image it's something like:
Sails.log(...)
Sails.error(...)
Sails.warn(...)
In your controllers, models, services, and anywhere else that the sails global is available, you can log with one of:
sails.log();
sails.log.warn();
sails.log.info();
sails.log.debug();
sails.log.error();
sails.log.verbose();
sails.log.silly();
The logging level (that is, the level at which logs will be output to the console) is set in /config/log.js.
To extend on the Scott Answer, dont forget to add the filePath: property to log.js file... otherwise it will not work :)
So it should be something like:
log: {
level: 'info',
maxSize: 1000,
filePath: 'c://serverlogs/mylogfilename.log'
Answer is changed based on Joseph question.
Related
I am playing with the new Azure API Apps (template in Visual Studio 2013 w/ the new SDK bits from 3/24/15) and I'd like have my Swagger UI group my calls by Version #. In my case, I'm currently versioning by URI (I realize REST purists will tell me not to do this - please don't try to "correct my error" here). For instance, I may have these calls:
http://example.com/api/Contacts <-- "latest"
http://example.com/api/1/Contacts
http://example.com/api/2/Contacts
http://example.com/api/Contacts{id} <-- "latest"
http://example.com/api/1/Contacts/{id}
http://example.com/api/2/Contacts/{id}
Functionally, this works great! (Yes, I know some of you will cringe. Sorry this hurts your feelings.) However, my problem is w/ Swagger UI organization. By default, Swagger UI groups these by the Controller Name (Contacts in this case). I see in the SwaggerConfig.cs file that I can change this:
// Each operation be assigned one or more tags which are then used by consumers for various reasons.
// For example, the swagger-ui groups operations according to the first tag of each operation.
// By default, this will be controller name but you can use the "GroupActionsBy" option to
// override with any value.
//
//c.GroupActionsBy(apiDesc => apiDesc.HttpMethod.ToString());
What I don't understand is how I can tweak this to group all of the "latest" together and then all of v1 together and then all of v2 together, etc.
How can I do this? If it absolutely must require that I add the word "latest" (or equiv) into the path in place of the version number, then I can do that but I'd prefer not have to do that.
I believe what you're looking to do is to uncomment a line a few lines below that one in SwaggerConfig.cs
c.OrderActionGroupsBy(new DescendingAlphabeticComparer());
except you'd change the name of the class to something like ApiVersionComparer() and then implement it as a new class:
public class ApiVersionComparer : IComparer<string>
{
public int Compare(string x, string y)
{
// Write whatever comparer you'd like to here.
// Yours would likely involve parsing the strings and having
// more complex logic than this....
return -(string.Compare(x, y));
}
}
If you've gotten far enough to ask this question, I'm sure I can leave the sort implementation for you. :-)
(I'm about to answer this question as well, because I've found the solution, but Google didn't really help, so hopefully this will gain some PageRank for the search terms I was using.)
We have a big Umbraco site with several sections, but most locales don't have section homepages. So if the structure looks like:
- Homepage
- Section1
- Page1-1
- Page1-2
- Section2
- Page2-1
- Page2-2
and so on, then going to ~/section1/ would redirect you to ~/section1/page1-1/ (and, likewise ~/section2/ redirects you to ~/section2/page2-1/).
At the moment, we use a macro that checks a property in the locale homepage and then redirects:
var node = Model.AncestorOrSelf("SiteHome");
var useCSSV2 = node.GetProperty("useCSSV2").Value;
if (useCSSV2 == "1")
{
Response.Redirect(Model.Children.First().Url);
}
We're seeing a bunch of occasions where macros don't load properly, with errors like
Error loading MacroEngine script (file: PrimaryNavigationSwitcher.cshtml)
displaying instead. Looking at the UmbracoTraceLog, I can see things like:
2014-11-25 00:11:28,226 [5] WARN umbraco.macro - [Thread 39] Error loading MacroEngine script (file: PrimaryNavigationSwitcher.cshtml, Type: ''. Exception: System.Threading.ThreadAbortException: Thread was being aborted.
at System.Threading.Thread.AbortInternal()
at System.Threading.Thread.Abort(Object stateInfo)
at System.Web.HttpResponse.AbortCurrentThread()
at System.Web.HttpResponseWrapper.Redirect(String url)
at ASP._Page_macroScripts_SecondLevelPageRedirection_cshtml.Execute() in d:\webroot\www.mysite.com\macroScripts\SecondLevelPageRedirection.cshtml:line 8
at System.Web.WebPages.WebPageBase.ExecutePageHierarchy()
at System.Web.WebPages.WebPage.ExecutePageHierarchy()
at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage)
at umbraco.MacroEngines.RazorMacroEngine.ExecuteRazor(MacroModel macro, INode currentPage)
at umbraco.MacroEngines.RazorMacroEngine.Execute(MacroModel macro, INode currentPage)
at umbraco.macro.loadMacroScript(MacroModel macro)
at umbraco.macro.renderMacro(Hashtable pageElements, Int32 pageId)
(where line 8 of SecondLevelPageRedirection.cshtml is the Response.Redirect).
That problem and the ThreadAbortException itself are strongly suggesting to me that Response.Redirect is the problem here and I should be using some other means of performing this redirect. (And even if this weren't a problem I'd prefer to avoid the performance impact of a bunch of exceptions being thrown.)
How should we be performing this redirect to have the same effect (so anyone going to ~/section1/ will be redirected to ~/section1/page1-1/ and so on), without having to add an umbracoRedirect or umbracoInternalRedirectId to each node and without having these damn ThreadAbortExceptions thrown all the time?
As detailed in a handful of places (notably Why Response.Redirect causes System.Threading.ThreadAbortException? here on Stack Overflow and PRB: ThreadAbortException Occurs If You Use Response.End, Response.Redirect, or Server.Transfer on the MSKB), Response.Redirect(string) is only present in ASP.Net for backwards compatibility.
To quote from Joel Fillmore in his answer to the Stack Overflow question linked above:
The correct pattern is to call the Redirect overload with endResponse=false and make a call to tell the IIS pipeline that it should advance directly to the EndRequest stage once you return control:
Response.Redirect(url, false);
Context.ApplicationInstance.CompleteRequest();
This blog post from Thomas Marquardt provides additional details, including how to handle the special case of redirecting inside an Application_Error handler.
Note that code after the Context.ApplicationInstance.CompleteRequest call will execute, so may need handling separately.
Incidentally, as the problem stems from Response.End, which includes the code
InternalSecurityPermissions.ControlThread.Assert();
Thread.CurrentThread.Abort(new HttpApplication.CancelModuleException(false));
then Server.Transfer will have precisely the same problem. There is more information at Is Response.End() considered harmful?
When my buildbot fails, it is configured to send an email.
Current configuration is:
mailNotify = MailNotifier(fromaddr="****#****.com",
sendToInterestedUsers=True,
extraRecipients=['*****#*****.com', '****#****.com'],
relayhost="mail.****.com",
smtpPort=587,
addLogs = True,
addPatch = True,
useTls=True,
smtpUser="****#****.com",
smtpPassword="****"
mode="failing")
I have a buildmaster setup in my local network, at 192.168.1.11. Because of that, when an email comes, it contains the following information:
Full details are available at:
http://192.168.1.11:8020/builders/BuilderName/builds/136
Buildbot URL: http://192.168.1.11:8020/
Apart from that, I have a publicly accessible server, by which I can access buildbot, i.e. https://mydomain.com/buildbot/
What I want to get is
Full details are available at:
https://mydomain.com/buildbot/builders/BuilderName/builds/136
Buildbot URL: https://mydomain.com/buildbot/
I'd love NOT to rewrite a whole message formatter, but I couldn't find a way to do that. Is it even possible?
AFAIK the best way is to write your own messageFormatter(). It is not much of a pain. I have done it for my buildbot and it works like a charm.
If you look into the sources buildbot\status\mail.py there is function called defaultMesage(...). Just override this in your buildbot's configuration and pass it to the MailNotifier constructor ! Most likely you have to change just the line:108
def myMessageFormatter(mode, name, build, results, master_status)
# Copy everything from buildbot\status\mail.py:defaultMessage()
# Change this to point to https://mydomain.com/buildbot/
if master_status.getURLForThing(build):
text += "Full details are available at:\n %s\n" % master_status.getURLForThing(build)
text += "\n"
When using ZFDebug, is it possible to add custom messages to the 'Log' tab?
So you could use something like:
$this->log('Error: Couldn't find the user');
Has anyone managed to achieve this?
I have never used ZFDebug before and wasn't aware of it. Your post piqued my interest, so I installed it and have been trying to achieve what you want to do. I will probably add it to my dev toolbox as I use ZF a lot.
You can achieve what you want by using the mark() method of ZFDebug_Controller_Plugin_Debug_Plugin_Log which takes two arguments. The first is the message you want to send and the second is a boolean which, when set to true (default is false), will send your message to the 'log' tab.
The following code worked for me:-
$debug = Zend_Controller_Front::getInstance()
->getPlugin('ZFDebug_Controller_Plugin_Debug');
$logger = $debug->getPlugin('log');
$logger->mark('Logging a message now', true);
Or to use your example (with the syntax error fixed :) )
$logger->mark("Error: Couldn't find the user", true);
As you can see this produced the desired output:-
Not quite as simple as you wanted, I know, but it's close and you could always wrap it in a function.
Is there any way to do something like that.
I have next wiki text:
{{template_open_tag}}
{{template_some_data}}
{{template_close_tag}}
And there are templates:
{{template_open_tag}}
<my-tag>
{{template_some_data}}
bla-bla-bla...
{{template_close_tag}}
</my-tag>
But tag '<bold>' processed already when first template transluded and wiki render this page like:
bla-bla-bla...
</my-tag>
But I want to see:
**bla-bla-bla...**
In my extension:
$wgHooks['ParserFirstCallInit'][] = 'myTagInit';
function myTagInit( &$parser ) {
$parser->setHook( 'my-tag', 'myTagRender' );
}
function myTagRender( $input, $args, $parser, $frame) {
return "**".$input."**";
}
Thank you.
P.S.
And don't ask me why I need this strange markup and don't want to use something like this:
{{template_tag|{{template_some_data}}}}
And {{template_open_tag}} like:
<my-tag>{{{1}}}</my-tag>
To warn you -- this sort of structure will likely be phased out entirely in future versions of MediaWiki, due to its inconsistent behavior and the difficulties it causes with structures like tags and sections.
The correct and future-proof way to do it is indeed to contain both your start and end in one template and pass the middle in as a parameter, eg {{template_tag|{{template_some_data}}}}
Set $wgUseTidy to true to make MediaWiki remove unclosed tags only after all the templates have been evaluated. Alternatively, you can use wikimarkup - as Adrian said - which does not suffer from this limitation.
Update: AFAIK XML-style extension tags are evaluated before way template including happens, so piecing them together from multiple templates is not possible. (Event <ext>{{{1}}}</ext> does not work pre-1.16, though you can make it work in 1.16 with recursiveTagParse.)
instead of using <bold> use ''' in both your {{template_open_tag}} and {{template_close_tag}} and it should render as bla-bla-bla...
Also, you can't do:
{{template_open_tag}}
{{template_some_data}}
{{template_close_tag}}
You have to do
{{template_open_tag}}{{template_some_data}}{{template_close_tag}}