Logging events OCaml/Async - asynchronous

I've been using the global module Log.Global and the functions info and debug but my application is growing larger and I need more flexibility. Specifically, I'd like to be able to enable/disable events from different components of the system. I'm wondering what is considering best practice in general (I mention Async since it's the API I'm using but the question is more general).
It seems the API provides at least two ways to do it. There is a ?tags:(string * string) list optional parameters. When used, it appends tags after the log message.
2017-08-23 17:35:38.090225+07:00 Info starting my program -- [foobar: foobar]
I could use that and then filter my log based on the events I want to see. How are tags used in general, are they typically literals or are there other ways of using them?
I could also use more than one logger. For instance, the functor Make_global () : Global_intf creates singleton. I could create one logger for each component. Is there a good reason to choose this approach? besides having different output for each log and setting the log level independently.

Related

Elixir - Changing default behavior of actors

I am currently looking into the behavioral reflection possibilities of Elixir, a language to which I'm pretty new. Specifically, I am searching for a way to change the default behavior of actors within Elixir, or install hooks within this behavior. As a classic example, let's say I want to log messages when they are send from one actor, arrive in the other actor and are actually processed. Could I change/override/hook into the default behavior of these hypothetical 'send', 'arrive' and 'process' methods in orde to add this functionality as 'default behavior'? How would this be done?
The logging example above is just an example. I am looking to use the approach used to implement this example in a broader context (eg. change default mailbox behavior).

How do I save a dynamically generated Lisp system in external files?

Basically, I want to be able to generate class definitions, compile the system, and save it for reuse. Would that involve a code walker, or is there a simpler option?
(save-lisp-and-die "isn't going to work for me")
Expanding to explain. I'm generating systems based on OpenAPI definitions, so a system roughly corresponds to an API client.
There will be dozens, if not hundreds of these.
The idea is to NOT keep them all in the image, but load at run time as required.
I see two possible routes here, and to some extent, I suspect they mainly differ in "the last mile" (as it were).
The route you seem to have settled on, run-time definition of classes and functions.
A route whereby you generate your function/class forms, but don't go the full way to get them "Live" in the image and instead emit the form(s) to a file.
I suspect that it would be possible to have most of the generating code shared between the two and for the first route have a wrapping macro that effectively returns a PROGN, and in the second calls a function to pretty-print what the macro would have returned on a stream.
Saying that, building a tailored environment and saving it to a "core" file is a pretty good way of getting excellent startup times.

Injecting code to track events on Delphi

I have a big and old application written in Delphi version 2007 for over a decade now and in order to rewrite it I intend to understand which parts/features of it are mostly used by the majority of its users.
The idea that came up is to track objects clicks and window creations to populate a log or analytics tool like Google Analytics or Deskmetrics with quantitative and qualitative data in order to help on the decision making.
To achieve that, I'm trying to figure out what is the easiest path respecting the current version limitations. One of the possibilities I am exploring is understanding how to implement some generic code that could be somehow "injected/reflected" in a class level so all instantiated objects may among other things, call a function passing parameters that identify themselves and this function would then take action to log that info using the best tool.
The only real solution so far is copying and pasting this function call on several thousands of onClick/onCreate methods and I'd like to avoid it while I am open to all other possibilities that may come out on this thread.
Thanks!

global settings in sailsjs

What would be a proper way to handle global "settings" in my sailsjs application? The user will want to change those settings via the web front of my app.
I imagine I could use a new model "GlobalSettings" with only one item, but I don't really know if it's a good "MVC" practice.
Since it is based on user input, it has to be stored in a database and therefore storing it in model seems like a right choice to me.
Having just 1 row/collection is completely ok in my opinion, especially in the no-SQL field. But for more reusability and scalability, you might want to consider to actually store each setting in invididual row, that might give you space to expand the usability of it in the future.
In my own opinion, I always find as a web app develops, you will start to realize there are more and more fields that you want the user to setup as their preference, as a good practice to relax the application.
For me I usually setup a meta_data model with name, value, criteria, and some other fields.
For example, when viewing your web page, 'Alice' may want a background color of black, 'Bob' may want a background color of green. Then you can let them modify or insert row into this meta_data collection. Then in your database, you will have
name value criteria
background_color black user_name='Alice'
background_color green user_name='Bob'
and it can be all kinds of values.
of course if you just have one value that can be changed by all of your users, it is probably a good idea to know who updated them. For this you would want to create a trigger, (if you are using a sql database)see trigger in mysql, so that every update on the table will trigger a function that stores what was changed and who changed it in another table
So yes, to answer your question, it is totally ok to have a model to store a value, and don't worry about only have one row, you will have more as you develop your app.
The config/globals.js file seems to be a good place to place a global configuration setting.
For convenience, Sails exposes a handful of global variables. By
default, your app's models, services, and the global sails object are
all available on the global scope; meaning you can refer to them by
name anywhere in your backend code (as long as Sails has been loaded).
Nothing in Sails core relies on these global variables - each and
every global exposed in Sails may be disabled in sails.config.globals
(conventionally configured in config/globals.js.)
Sailsjs.org Documentation - Globals
Alternatively you can use the sails.config object.
Custom Configuration
Sails recognizes many different settings, namespaced under different top level keys (e.g. sails.config.sockets and
sails.config.blueprints). However you can also use sails.config for
your own custom configuration (e.g.
sails.config.someProprietaryAPI.secret).
From the docs
There is also services which is global by default.
Overview
Services can be thought of as libraries which contain functions that you might want to use in many places of your application. For example,
you might have an EmailService which wraps some default email message
boilerplate code that you would want to use in many parts of your
application. The main benefit of using services in Sails is that they
are globalized--you don't have to use require() to access them.
It really depends on what kind of global you are wanting.

How does one expose constants in a java google app engine Endpoints API?

Simple question -- how do you expose constants in a java google app engine Endpoints API?
e.g
public static final int CODE_FOO = 3845;
I'd like the client of the Endpoints to be able to match on CODE_FOO rather than on 3845. I'll end up doing enum wrappers (which probably is better anyway) but I'm just starting to be curious if this is even doable? Thx
Note that this isn't a full answer but here is a workaround: in Android Studio, create a very light-weight "common" java project and shove anything you want to keep in sync there such as constants as well as common types that you want exposed (e.g. an enum representing all possible return / error codes, etc).
This way you should get pretty decent compiler-time safety and keep these guys in sync.
Please feel free to comment if anyone has better suggestions.
This is unfortunately a Law of Information (ahem). If you have a message protocol you defined, both sides of the interaction need to be aware of the messages that could be passed. There's no other way for the client to be aware of what it needs to respond to. Ajax libraries hard-code the number "200" to be able to detect a successful request, as one example.
Yes, just use a switch statement on strings inside your client code. Or, you could use a dictionary of strings pointing to functions and just call the function after de-referencing the dictionary given the string you got.

Resources