Tüm Ürünler
Search
Belge Merkezi

Simple Log Service:Temel sözdizim

Son Güncelleme:Sep 30, 2026

Bu konu, Simple Log Service (SLS) etki alanına özel dilinin (DSL) temel sözdizimini açıklar.

Yorumlar

Sözdizimini açıklayan bir yorum eklemek için satırı diyez işareti (#) ile başlatın. Aşağıdaki kodda örnek gösterilmiştir:

# Set the default topic for logs. This is a comment at the beginning of a line.
e_set("__topic__", "access_log")   # Set the default topic for logs. This is a comment at the end of a line.

Satır sonları

Bir fonksiyon çağrısının parametre listesi çok uzunsa satır sonu ekleyebilirsiniz.

  • Fonksiyon yapısında virgül (,) varsa satır sonunu doğrudan virgülden sonra ekleyebilirsiniz.

  • Bir dize çok uzunsa ve satır sonu gerekiyorsa ters eğik çizgi (\) kullanabilirsiniz.

Örnek:

e_set("__topic__", "v1",
        "type", "v2",       # When parameters are separated by commas (,), you can add a line break directly.
        "length", 100)
e_set("__topic__", "this is a very long long long .........." \
                            "......long text")  # Use a backslash (\) to add a line break.

Fonksiyon çağırma yöntemleri

  • Temel çağırma

    e_set("abc", "xyz")
    Not

    Veri dönüştürme ifadesi yazarken giriş parametrelerinin veri türleri ve sayısı fonksiyon sözdizimiyle eşleşmelidir.

  • Temel değişken parametre çağırma

    str_replace(value, old [,new [,count] ]) 
    Not

    Bir fonksiyonun parametreleri köşeli parantezler ([]) içeriyorsa parantez içindeki parametreler, örneğin new ve count, isteğe bağlıdır. Bunları adlandırılmış parametre olarak çağıramazsınız; belirtilen sırayla çağırmalısınız.

    # Invalid examples
    str_replace("a-b-c", "-", new='%')
    str_replace("a-b-c", "-", new='%', count=1)
    # Valid examples
    str_replace("a-b-c", "-", '%')
    str_replace("a-b-c", "-", '%', 2)
  • Adlandırılmış parametre çağırma

    Varsayılan değeri olan parametre, adlandırılmış parametredir. Örneğin, e_set("abc", "xyz", mode="fill") ifadesindeki mode adlandırılmış bir parametredir.

    • Bazı fonksiyonlarda belirli koşullar altında adlandırılmış parametrelerin değerlerini geçirmeniz gerekir. Daha fazla bilgi için her fonksiyonun parametre açıklamasına bakın.

    • Adlandırılmış bir parametreye değer geçirmek için mode=... biçimini kullanın.

    • Birden fazla adlandırılmış parametre varsa bunları belirtme sırası önemli değildir. Örneğin, e_csv("data", ["f1", "f2", "f3"], sep='#', quote="|") ifadesi e_csv("data", ["f1", "f2", "f3"], quote="|", sep='#') ifadesiyle aynıdır.

    Not

    Bir fonksiyon çağrısında adlandırılmış parametreler her zaman adlandırılmamış parametrelerden sonra belirtilmelidir.

  • İç içe fonksiyon çağrıları

    Bir fonksiyonun dönüş değerini başka bir fonksiyonda parametre olarak kullanabilirsiniz. Veri türlerinin tutarlı olduğundan emin olun. Örnek:

    e_set("abc", v("xyz"))
    e_set("abc", str_lower(v("xyz")))
  • Değişken parametreler

    Bazı fonksiyonlar değişken parametreleri destekler. v("f1", ....) ifadesi v("f1", "f2", "f3") gibi daha fazla parametre geçirebileceğiniz anlamına gelir.

    Adlandırılmış parametreleri geçirdiğinizde bunları en sona yerleştirmelisiniz. Örnek: v("f1", "f2", "f3", "f4", mode="fill").

İşleçler

  • Karşılaştırma işleçleri

    SLS DSL'in standart modu >, <, >=, <=, !=, and == dahil olmak üzere karşılaştırma işleçlerini destekler. Aynı etkiyi elde etmek için SLS tarafından sağlanan karşılaştırma fonksiyonlarını da kullanabilirsiniz.

    • Karşılaştırma işleçlerini doğrudan kullanma

      # The following examples show how to use comparison operators. If the comparison result is True, the log is dropped.
      e_if(3 > 2, DROP)       # If 3 is greater than 2, the log is dropped.
      e_if(3 < 2, DROP)       # If 3 is less than 2, the log is dropped.
      e_if(3 >= 2, DROP)      # If 3 is greater than or equal to 2, the log is dropped.
      e_if(3 <= 2, DROP)      # If 3 is less than or equal to 2, the log is dropped.
      e_if(3 == 2, DROP)      # If 3 is equal to 2, the log is dropped.
      e_if(3 != 2, DROP)      # If 3 is not equal to 2, the log is dropped.
      e_if(1 < 2 < 3, DROP)   # If 2 is greater than 1 and less than 3, the log is dropped.
      e_if(0 < ct_int(v('x')) < 100, DROP) # If the value of the x field is greater than 0 and less than 100, the log is dropped.
    • SLS tarafından sağlanan karşılaştırma fonksiyonlarını kullanma


      İşlem


      Fonksiyon


      Örnek


      Eşittir ==


      op_eq


      op_eq(v("name"), "xiao ming")


      Eşit değildir !=


      op_ne


      op_ne(v("name"), "xiao ming")


      Büyüktür >


      op_gt


      op_gt(ct_int(v("age")))


      Büyük veya eşittir >=


      op_ge


      op_ge(ct_int(v("age")), 18)


      Küçüktür <


      op_lt


      op_lt(ct_int(v("age")), 18)


      Küçük veya eşittir <=


      op_le


      op_le(ct_int(v("age")), 18)

  • Mantıksal işleçler

    SLS DSL'in standart modu and, or ve not mantıksal işleçlerini destekler. Aynı etkiyi elde etmek için SLS tarafından sağlanan mantıksal fonksiyonları da kullanabilirsiniz.

    • Mantıksal işleçleri doğrudan kullanma

      # The following examples show how to use logical operators. If the result of the logical operation is True, the log is dropped.
      e_if(True and False, DROP)     # The result is False.
      e_if(True or False, DROP)      # The result is True.
      e_if(True and not False, DROP) # The result is True.
      e_if(3 > 2 and 1 < 3, DROP)    # The result is True.
      e_if(ct_int(v('x')) > 100 or ct_int(v('y')) < 100, DROP) # The value of the x field is greater than 100 or the value of the y field is less than 100.
    • SLS tarafından sağlanan mantıksal fonksiyonları kullanma


      İşlem


      Fonksiyon


      Örnek


      Mantıksal AND and


      op_and


      op_and(op_gt(v("age"), 18), op_lt(v("age"), 31))


      Mantıksal OR or


      op_or


      op_or(op_le(v("age"), 18), op_gt(v("age"), 65))


      Mantıksal NOT not


      op_not


      op_not(op_gt(v("age"), 18))

  • Diğer işleçler

    Aşağıdaki işleçler SLS DSL'in standart modunda doğrudan desteklenmez. SLS, aynı etkileri elde etmek için karşılık gelen fonksiyonlar sağlar.


    Senaryoya dayalı işlemler


    Fonksiyon


    Örnek


    Toplama +


    op_add


    op_add(v("age"), 2)


    Çıkarma -


    op_sub


    op_sub(v("age"), 2)


    Çarpma *


    op_mul


    op_mul(v("size"), 2)


    Üs alma **


    op_pow


    op_pow(v("size"), 2)


    Taban bölme //


    op_div_floor


    op_div_floor(v("bytes"), 1024)


    Modülüs işlemi %


    op_mod


    op_mod(v("age"), 10)


    Negatif yapma -


    op_neg


    op_neg(v("profit"))


    Varlık kontrolü in


    op_in


    op_in(["pass", "ok"], v("result"))


    Yokluk kontrolü not in


    op_not_in


    op_not_in(["pass", "ok"], v("result"))


    Dize dilimleme [ ...]


    op_slice


    op_slice(v("message"), 0, 20)

    Örneğin, a alanının değerini 3600*6 olarak ayarlamak için:

    # * 
    e_set("a", 3600 * 6)           # Invalid
    e_set("a", op_mul(3600, 6))    # Valid
    
    # /
    e_set("bytes_kb", v("bytes") / 1024)                 # Invalid
    e_set("bytes_kb", op_div_floor(v("bytes"), 1024))    # Valid

True ve false değerlendirme

Bazı fonksiyonlar bir koşulu kabul eder ve bu koşulun değerine göre sonraki mantığı belirler. Koşul statik bir alan veya bir ifadenin dönüş değeri olabilir.

SLS DSL, herhangi bir veri türünün değerlendirilmesini destekler. Aşağıdaki tabloda farklı veri türleri için true ve false değerlerinin koşulları açıklanmaktadır.


Veri türü


True olma koşulu


False olma koşulu


Boolean


True, true


False, false


None


None


Her zaman False


Sayısal


0 veya 0,0 değil


0 veya 0,0


Dize


Boş değil


Boş dize


Bayt


Boş değil


Boş bayt


Tuple


Boş değil


Boş tuple


Liste


Boş değil


Boş liste


Sözlük


Boş değil


Boş sözlük


Tablo


Var ise True


Null nesne (None)


Datetime


Var ise True


Null nesne (None)

Aşağıda bırakılan bir olay örneği gösterilmektedir:

e_if(True, DROP)                     # If the input is True, the event is dropped.
e_if(1, DROP)                        # If the input is 1, the event is dropped.
e_if(v("abc"), DROP)                 # If the abc field exists and is not empty, the event is dropped.
e_if(str_isdigit(v("abc")), DROP)    # If the abc field exists and its content consists only of digits, the event is dropped.